Android开始意图查看apk [英] Android start intent to view apk

查看:25
本文介绍了Android开始意图查看apk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我正在下载一个 apk 并将其保存到 SD 卡,然后我想开始安装该 apk.我正在使用以下代码尝试此操作:

In my application I am downloading and saving an apk to the SDcard 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);

但是当我这样做时,它告诉我没有启动意图的活动.我试图做的是为当前正在运行的应用程序安装一个新的更新.如何启动 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(new File(filePath)) 而不是 Uri.parse(file)?

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

这篇关于Android开始意图查看apk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆