仅在通知选项卡上安装应用程序

Install application only on notification tab

我会在下载应用程序后向用户显示通知。

我还有一个安装下载的应用程序的 installApk 方法,但在代码段 (completeNotification) 中,应用程序会自动 安装。我只需要在用户点击通知后安装它。

我是不是忽略了什么?

感谢您的帮助。

完整的通知方法:

public void completeNotification() {
        Intent install = installApk(urlPath, context, mNotificationManager,
                NOTIFYCATIONID);
        PendingIntent pending = PendingIntent.getActivity(context, 0, install, 0);

        mBuilder = new NotificationCompat.Builder(context)
                .setContentTitle(appName)
                .setContentText("ready to install.");
        mBuilder.setContentIntent(pending);
        mBuilder.setSmallIcon(R.drawable.placeholder);
        mBuilder.setDefaults(Notification.DEFAULT_SOUND);
        mBuilder.setAutoCancel(true);
        mNotificationManager =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(1, mBuilder.build());
    }

安装Apk方法:

public static Intent installApk(String urlPath, Context context,
                                    NotificationManager mNotificationManager, int NOTIFYCATIONID) {
        Intent apkIntent = new Intent();
        apkIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        apkIntent.setAction(android.content.Intent.ACTION_VIEW);
        File apkFile = new File(urlPath);
        Uri uri = Uri.fromFile(apkFile);
        apkIntent
                .setDataAndType(uri, "application/vnd.android.package-archive");
        context.startActivity(apkIntent);
        mNotificationManager.cancel(NOTIFYCATIONID);
        return apkIntent;
    };

删除此行:

context.startActivity(apkIntent);