Android 7.0 FileProvider 自动更新适配

Android7.0自动更新发生异常的适配,provider,私有文件。
具体看项目,注意某些手机同为Android7.0未发生此问题,仅于华为手机中出现;
简单配置如下:
——manifest文件配置

<provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="com.tiandu.cdwzhc.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"/>
 </provider>

——新建xml路径文件provider_paths

 <?xml version="1.0" encoding="utf-8"?>
 <paths>
     <external-path name="external_files" path="."/>
 </paths>

——实现代码

 Intent intent = new Intent();
                         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                         intent.setAction(Intent.ACTION_VIEW);
                         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {// android.os.FileUriExposedException
                             intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                             Uri installURI = FileProvider.getUriForFile(AdMainActivity.this, AdMainActivity.this.getApplicationContext().getPackageName() + ".provider", file);
                             intent.setDataAndType(installURI,
                                     "application/vnd.android.package-archive");
                         } else {
                             intent.setDataAndType(Uri.fromFile(file),
                                     "application/vnd.android.package-archive");
                         }
                         startActivity(intent);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值