【发布时间】:2012-05-02 03:04:31
【问题描述】:
我曾经遇到过这个问题,但我找到了解决方案,所以决定在这里发布它以防其他人需要它。
如何启动本机安装程序来安装 apk?
很多帖子的解决方法如下:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(path), "application/vnd.android.package-archive");
context.startActivity(intent);
这很好,除了一个微小但至关重要的细节:
“路径”字符串必须以 file:// 开头,否则会出现异常,例如
Unable to find an activity to handle the intent .....
所以请确保路径以 file://
开头干杯。
【问题讨论】:
-
@CommonsWare - 您的链接确实包含此信息,但并未强调“file://”方案的重要性。顺便说一句,谢谢你的链接,我希望我能早点找到它——这样可以节省我一堆白发:)
标签: android android-intent installation protocols