android apk安装引导,Android-调用系统安装apk

对于7.0及其以上的设备我们需要做如下操作:

1.在manifest中注册FileProvider

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

android:authorities="${applicationId}.provider"

android:exported="false"

android:grantUriPermissions="true">

android:name="android.support.FILE_PROVIDER_PATHS"

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

2、指定可用的文件路径

在项目的res目录下,创建xml文件夹,并新建一个file_paths.xml文件。通过这个文件来指定文件路径:<?xml version="1.0" encoding="utf-8"?>

3、调用代码:File apkFile = new File(apkPath);

Intent intent = new Intent(Intent.ACTION_VIEW);

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

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

intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

Uri contentUri = FileProvider.getUriForFile(this, BuildConfig.FileProvider,apkFile);

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

} else {

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

}

startActivity(intent);

一般网上的教程就到此为止,但是现在部分手机出于安全考虑,禁止了APK自由调用安装程序,因此,还需要在AndroidManifest中添加一条权限:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值