通过 APK 下载更新应用程序(使用 url),不显示 Open/Done 屏幕

Update App via APK download (with url), not showing Open/Done Screen

我正在尝试通过下载 apkupdate 应用程序添加选项,它已成功安装。但问题是,应用程序在安装后关闭,没有提示 Open/Done 屏幕 Nougat 以上 设备。

我尝试过同时使用 ACTION_VIEWACTION_INSTALL_PACKAGE,但没有成功。还尝试使用 startActivityForResult 而不是 startActivity,仍然没有成功。

public void installAPK() {
        Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
        File file = new File(path + "update.apk");

        if (Build.VERSION.SDK_INT < 24) {
            intent.setDataAndType(Uri.fromFile(new File(path + "update.apk")), "application/vnd.android.package-archive");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // without this flag android returned a intent error!
        } else {

            Uri apkURI = FileProvider.getUriForFile(
                    activity,
                    activity.getApplicationContext()
                            .getPackageName() + ".provider", file);
            intent.setDataAndType(apkURI, "application/vnd.android.package-archive");
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }
        intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
        activity.startActivityForResult(intent, RC_INSTALL_APK);
    }

我有什么想做的吗?

下面是我的应用打开新版本方法的示例代码

 void OpenNewVersion(String location) {
    Intent downloadIntent;
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        String PATH = Environment.getExternalStorageDirectory() + "/Download/";

        File fileLocation = new File(PATH, "app-stock.apk");
        Uri apkUri = FileProvider.getUriForFile(this,  "Adapters.GenericFileProvider", fileLocation);

        downloadIntent = new Intent(Intent.ACTION_VIEW);
        downloadIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        downloadIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        downloadIntent.setDataAndType(apkUri, "application/vnd.android.package-archive");

        List<ResolveInfo> resInfoList = this.getPackageManager().queryIntentActivities(downloadIntent, PackageManager.MATCH_DEFAULT_ONLY);
        for (ResolveInfo resolveInfo : resInfoList) {
            String packageName = resolveInfo.activityInfo.packageName;
            this.grantUriPermission(packageName, apkUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }

    } else {
        File fileLocation = new File(this.getFilesDir(), "app-stock.apk");
        downloadIntent = new Intent(Intent.ACTION_VIEW);
        downloadIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        downloadIntent.setDataAndType(Uri.fromFile(fileLocation), "application/vnd.android.package-archive");
    }
    this.startActivity(downloadIntent);

}