安卓7.0手机上遇到的app升级问题终极解决方案
来源:互联网 发布:淘宝内裤店铺起名 编辑:程序博客网 时间:2024/05/18 03:45
兼容Android 7.0 App升级
一、在AndroidManifest.xml清单文件中注册Provider
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.cuileikun.androidbase.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/cui_file_paths"
tools:replace="android:resource"/>
</provider>
authorities: 常用命名为包名+fileprovider
exported要求必须为false,为true会报安全异常
grantUriPermissions表示URI临时访问权限,true为需要临时访问权限
resource指当前组件引用res文件夹中qk_file_paths文件,这个文件名可以随便写,只要在res文件夹中有这个文件即可。
在res文件夹中新建xml文件夹,再新建cui_file_paths.xml文件,内容如下
<?xml version="1.0" encoding="utf-8"?>
<resources>
<paths>
<external-path
name="files_root"
path="Android/data/com.cuileikun.androidbase/" />
<external-path
name="external_storage_root"
path="." />
<!-- yan notice: do not edit -->
<root-path path="" name="camera_photos" />
</paths>
</resources>
path填上Android/data/包名
二、安装Apk时注意兼容高低版本
Intent intent = new Intent(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(context, BuildConfig.APPLICATION_ID + ".fileprovider", apkFile);
intent.setDataAndType(contentUri, "application/vnd.android.package-archive");
} else {
intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
context.startActivity(intent);
主要是注意getUriForFile方法中的参数,第二个参数为BuildConfig.APPLICATION_ID + “.fileprovider”
一、在AndroidManifest.xml清单文件中注册Provider
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.cuileikun.androidbase.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/cui_file_paths"
tools:replace="android:resource"/>
</provider>
authorities: 常用命名为包名+fileprovider
exported要求必须为false,为true会报安全异常
grantUriPermissions表示URI临时访问权限,true为需要临时访问权限
resource指当前组件引用res文件夹中qk_file_paths文件,这个文件名可以随便写,只要在res文件夹中有这个文件即可。
在res文件夹中新建xml文件夹,再新建cui_file_paths.xml文件,内容如下
<?xml version="1.0" encoding="utf-8"?>
<resources>
<paths>
<external-path
name="files_root"
path="Android/data/com.cuileikun.androidbase/" />
<external-path
name="external_storage_root"
path="." />
<!-- yan notice: do not edit -->
<root-path path="" name="camera_photos" />
</paths>
</resources>
path填上Android/data/包名
二、安装Apk时注意兼容高低版本
Intent intent = new Intent(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(context, BuildConfig.APPLICATION_ID + ".fileprovider", apkFile);
intent.setDataAndType(contentUri, "application/vnd.android.package-archive");
} else {
intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
context.startActivity(intent);
主要是注意getUriForFile方法中的参数,第二个参数为BuildConfig.APPLICATION_ID + “.fileprovider”
即包名+.fileprovider,这个和AndroidManifest中的Provider中的属性authorities一致
参考链接:
http://www.2cto.com/kf/201704/622561.html
阅读全文
1 0
- 安卓7.0手机上遇到的app升级问题终极解决方案
- 安卓项目升级sdk和第三方库遇到的问题及解决方案
- 安卓 app 本地升级下载后自动安装(小米手机安装包解析失败问题)
- 安卓在Eclipse上开发遇到项目运行不了的终极解决办法
- 安卓app import android.os.servicemanager遇到的问题
- 安卓app开发遇到的问题以及解决方法
- 安卓CRC16校验中遇到的问题和解决方案
- 手机掉水里的终极解决方案!
- 手机app开发遇到的问题总结
- 安卓开发 RecycleView 中notifyItemRemoved遇到的那些坑, IndexOutOfIndexException、删除错乱,数组越界等终极解决方案,多人亲测可行
- 安卓手机自动关机的app
- cmake升级之后遇到的cmake问题的解决方案
- 为什么安卓手机上的多数APP,消息推送不了?
- 升级xcode7 和 iOS9 后遇到的问题以及解决方案
- 升级xcode7 和 iOS9 后遇到的问题以及解决方案
- 【总结】升级Xcode8遇到的问题及解决方案!!!
- 【总结】升级Xcode8遇到的问题及解决方案!!!
- 安卓开发debug-app卸载不干净,导致安装、升级不成功问题的解决办法
- java语言中关于抽象类和接口的区别
- 冒泡排序和选择排序
- Third Maximum Number
- iOS 动画研究一:丰富多彩的动画
- android QMI机制---底层消息发送
- 安卓7.0手机上遇到的app升级问题终极解决方案
- POJ 2613 Choose and divide 笔记
- hdu 3729
- Unity3D开发之同时播放多个视频
- listview 的滑动
- 字符串反转(C/C++)
- 调研网络端口号的分类
- [编程题] 最后一个字符
- 二维数组中的查找