提示用户安装APK

问题描述 投票:0回答:1

我正在为自己的Android应用构建自己的更新机制(我没有使用Play商店)。我可以使用DownloadManager成功下载新的APK。下载完成后,我想提示用户安装apk。我尝试了以下方法:

    File file = context.getApplicationContext().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS + "/app-debug.apk");
    String test = file.getAbsolutePath();
    Intent promptInstall = new Intent(Intent.ACTION_VIEW)
            .setDataAndType(Uri.parse("content://" + file.getAbsolutePath()),
                    "application/vnd.android.package-archive");
    context.startActivity(promptInstall);

不幸的是,这根本不起作用。该文件在那里,但是没有安装提示。怎么了?我还必须将第二个参数调整为setDataAndType吗?它应该可以在SDK 23到29上使用。

android android-intent apk android-10.0 viewaction
1个回答
0
投票

Install Application programmatically on Android的可能副本

我认为该线程的答案应该有效:

https://stackoverflow.com/a/54424223/9490453

<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
© www.soinside.com 2019 - 2024. All rights reserved.