gpt4 book ai didi

apk - 在 Android 7/api24 中以编程方式安装 apk

转载 作者:行者123 更新时间:2023-12-03 23:24:20 24 4
gpt4 key购买 nike

我正在尝试让我的应用程序自动安装 apk。这适用于 api<24。但是对于 24,它失败了。 Android 实现了额外的安全性:

For apps targeting Android 7.0, the Android framework enforces the StrictMode API policy that prohibits exposing file:// URIs outside your app. If an intent containing a file URI leaves your app, the app fails with a FileUriExposedException exception.



所以我试过这个:
    Uri myuri;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N){
myuri = Uri.parse("file://"+outapk);
} else {
File o = new File(outapk);
myuri = FileProvider.getUriForFile(con, con.getApplicationContext().getPackageName() + ".provider", o);
}
Intent promptInstall = new Intent(Intent.ACTION_VIEW).setDataAndType(myuri,"application/vnd.android.package-archive");
con.startActivity(promptInstall);

但得到一个致命的异常:
com.android.packageinstaller "Caused by: java.lang.SecurityException: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{b42ee8a 6826:com.android.packageinstaller/u0a15} (pid=6826, uid=10015) that is not exported from uid 10066". 

我的 list 中有 export=true 。

问题似乎是 packageinstaller 不能使用 content://uri。

有什么方法可以让应用程序以编程方式安装带有 api24 的 apk?

最佳答案

Are there any ways to allow an app to progammatically install an apk with api24?



添加 addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)给您的 promptInstall设置,授予对内容的读取访问权限。

I have export=true in my manifest.



不在您的 FileProvider ,因为这会导致您的应用程序崩溃。

The problem seems to be that packageinstaller cannot use a content:// uri.



不,问题是您没有授予软件包安装程序读取该 Uri 的权限。 .如果软件包安装程序无法使用 content计划,你会得到一个 ActivityNotFoundException .

但请注意,只有在 Android 7.0 中,软件包安装程序才开始支持 content .早期版本的Android必须使用 file .

关于apk - 在 Android 7/api24 中以编程方式安装 apk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41474683/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com