Android 7.0 FileProvider 自动更新适配

来源:互联网 发布:电子线路板设计软件 编辑:程序博客网 时间:2024/06/06 01:51

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);
原创粉丝点击