Android7.0以上自动更新安装apk
来源:互联网 发布:windows常见界面开发 编辑:程序博客网 时间:2024/05/18 02:23
Android7.0以上加了很多特性,也对系统做了很多的优化和升级,而在对Uri的访问上也做了改变,以下用安装apk的例子来说明
对于程序,我们要实现程序能够自动检查更新安装,我们需要给程序赋予权限
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
以上这是第一步,接着,我们需要在Manifest.xml文件当中做如下配置:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.test">...<application ...> <provider android:name="android.support.v4.content.FileProvider" android:authorities="com.test.fileprovider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> </provider> ... </application></manifest>主要添加的 就是provider标签部分,对于属性android:authorities一定要注意,当中的前面部分,com.test是程序的appId,就是applicationId,在build.gradle文件当中可以看到。
上面配置当中是否有看到android:resource="@xml/file_paths"呢,这里再来说一下xml下的file_paths
在项目中的res下新建xml目录,并在xml目录当中新建file_paths.xml文件,该文件当中的内容如下:
<?xml version="1.0" encoding="utf-8"?><paths xmlns:android="http://schemas.android.com/apk/res/android"> <external-path name="external_files" path="" /></paths>其实,我的path为空则表示为Environment.getExternalStorageDirectory()的主目录;好了,到此为止将配置做好了,以下是调用程序的安装功能,代码如下:
Intent intent = new Intent(); //执行动作 intent.setAction(Intent.ACTION_VIEW); //判读版本是否在7.0以上 if (Build.VERSION.SDK_INT >= 24) { Uri apkUri = FileProvider.getUriForFile(mContext, "com.test.fileprovider", file); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setDataAndType(apkUri, "application/vnd.android.package-archive"); } else { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); } mContext.startActivity(intent);关于file_paths的其实配置有其他文章参考,原文地址为:http://www.czhzero.com/2016/12/21/how-to-install-apk-on-Android7-0/
阅读全文
2 0
- Android7.0以上自动更新安装apk
- android7.0以上 安装卸载apk, monkey 测试
- Android7.0 apk安装
- Android7.0 PackageManagerService APK安装
- Android7.0 PackageManagerService (3) APK安装
- 下载安装APK(兼容Android7.0)
- Android7.0下载Apk自动安装
- Android7.0下载Apk自动安装
- 下载安装APK(兼容Android7.0)
- 下载安装APK(兼容Android7.0)
- 下载安装APK(兼容Android7.0)
- Android7.0使用FileProvider安装apk
- Android7.0下载Apk自动安装
- Android7.0升级安装APK,FileUriExposedException问题
- 下载安装APK(兼容Android7.0)
- Android7.0之安装apk文件
- Android7.0下载Apk自动安装
- 解决Android7.0以上版本升级apk时报android.os.FileUriExposedException的问题
- typescript 之 基础类型
- 对集合的一个字段排序(字符串、整型、日期)
- freemarker三目运算符
- PDF添加背景图片以及PDF文件添加页码技巧
- 看Uber产品总监的职场达人修炼之路(下)
- Android7.0以上自动更新安装apk
- c#简单教程2
- C++ fstream流的eof()函数多读一行的问题
- Myeclipse中关于js源码文件等报错问题
- 泛型类中静态成员
- [数论] 同余方程组 (hdu 3579&hdu 1573)
- DOM扩展
- Unicode 与 Unicode Transformation Format(UTF-8 / UTF-16 / UTF-32)
- QT Creator 快速入门教程 读书笔记