android 安装 apk 7.0,android 7.0及以上版本安装apk

这篇博客介绍了如何在Android中使用FileProvider进行权限管理和安装APK,特别是在Android N及以上版本的兼容性解决方案。通过在AndroidManifest.xml配置FileProvider,并创建res/xml/file_paths文件来指定文件路径,然后根据Android版本调用不同的安装方法,确保在不同系统上的正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一:在AndroidManifest.xml文件下

android:name="android.support.v4.content.FileProvider"

android:authorities="com.tvbox.yoostore.fileprovider"

android:grantUriPermissions="true"

android:exported="false">

android:name="android.support.FILE_PROVIDER_PATHS"

android:resource="@xml/file_paths"/>

第二: 在res目录下新建想xml文件夹及其xml文件夹下新建file_paths文件

file_paths文件内容如下:

最后兼容个版本的apk安装方法:

public static voidinstallApp(File file) {

Intent intent =newIntent(Intent.ACTION_VIEW);

//判断是否是AndroidN以及更高的版本

if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.N) {

intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

Uri contentUri = FileProvider.getUriForFile(App.app.getApplicationContext(),"com.tvbox.yoostore"+".fileprovider",file);

intent.setDataAndType(contentUri,"application/vnd.android.package-archive");

}else{

intent.setDataAndType(Uri.fromFile(file),"application/vnd.android.package-archive");

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

}

App.app.getApplicationContext().startActivity(intent);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值