尝试使用意图安装 apk 失败且没有错误 [英] Trying to install apk with intent fails without error
本文介绍了尝试使用意图安装 apk 失败且没有错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在下载后尝试安装 apk.
下载工作正常,但当我尝试安装该软件包时,它完全没有任何作用.
没有日志消息,我不知道我的错误可能是什么.
I'm trying to install an apk after I downloaded it.
Download works fine but when I try to install the package it does absolutely nothing.
There are no log messages and I have no clue what the my error might be.
这是我用来启动意图的代码(它肯定会被执行):
Here is the code I use to launch the intent (it definitely gets executed):
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Uri contentUri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", apkFile);
Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE);
install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
install.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
install.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
install.addCategory(Intent.CATEGORY_DEFAULT);
install.setDataAndType(contentUri, "application/vnd.android.package-archive");
context.startActivity(install);
} else {
Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE);
install.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
install.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
context.startActivity(install);
}
我已经检查了变量:
- apkFile: "/storage/emulated/0/Download/name.apk"
- contentUri: "content://APP_ID.provider/external_storage_root/Download/name.apk"
非常感谢任何关于我可以尝试的提示.
Any tips on what I could try are greatly appreciated.
推荐答案
没关系,我在 AndroidManifest.xml 中打错了字.
Nevermind I made a typo in my AndroidManifest.xml.
情况如何:
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES " />
应该如何:
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
注意到末尾有一个空格吗?
我花了 3 天时间才找到它...
Notice that one space at the end?
Took me 3 days to find it...
这篇关于尝试使用意图安装 apk 失败且没有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文