android代码调用安装apk(兼容7.0)
2018-02-26 14:37
405 查看
public void install(Context context,String filePath) { File apkFile = new File(filePath); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Uri contentUri = FileProvider.getUriForFile( context , "你的包名.fileprovider" , apkFile); intent.setDataAndType(contentUri, "application/vnd.android.package-archive"); } else { intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive"); } context.startActivity(intent); }
兼容7.0
1.在配置文件中添加
<provider android:name="android.support.v4.content.FileProvider" android:authorities="你的包名.fileprovider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> </provider>
2.在res中添加文件file_paths.xml文件
<?xml version="1.0" encoding="utf-8"?> <paths xmlns:android="http://schemas.android.com/apk/res/android"> <root-path name="root_path" path="." /> </paths>
相关文章推荐
- Android 动态加载APK--代码安装、获取资源及Intent调用已安装apk
- Android 动态加载APK--代码安装、获取资源及Intent调用已安装apk
- Android 动态加载APK--代码安装、获取安装包中的资源及Intent调用已安装apk
- android插件化,简单调用未安装apk的资源和代码
- android 使用FileProvider 兼容apk 在7.0版本无法安装
- 兼容Android系统7.0,升级安装apk
- Android代码实现APK文件的安装与卸载
- android 代码 安装APK 解决了
- Android 实现用代码安装和卸载APK
- Android代码实现APK文件的安装与卸载
- Android代码实现APK文件的安装与卸载
- Android代码如何监控apk安装_卸载_…
- ANDROID代码实现APK文件的安装与卸载
- Android 监听apk安装替换卸载广播的实现代码
- Android代码实现APK文件的安装与卸载
- android 在代码中安装apk的方法
- android代码安装和卸载apk
- Android代码实现APK文件的安装与卸载
- Android代码实现APK文件的安装与卸载
- Android代码实现APK文件的安装与卸载