Android的意图开始查看APK意图、Android、APK

2023-09-04 23:54:00 作者:下①站,幸福

在我的应用程序,我下载并保存一个APK的SDK卡,然后我要开始的APK安装。我用下面的code尝试这样的:

In my application I am downloading and saving an apk to the sdk card and then I want to start the installation of the apk. I'm using the following code to attempt this:

Intent intent =new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(file), "application/vnd.android.package-archive");
activity.startActivity(intent);

但是,当我做到这一点告诉我,有没有活动启动的意图。我所试图做的就是安装新的更新为当前运行的应用程序。我该如何开始的意图来运行apk文件?

But when I do this it tells me there is no activity to start the intent. What I am attempting to do is install a new update for the currently running application. How do I start an Intent to run an apk file?

推荐答案

你有没有尝试使用 Uri.fromFile(新File(文件路径))而不是 Uri.parse(文件)

Did you try using Uri.fromFile(new File(filePath)) instead of Uri.parse(file)?