第一:在AndroidManifest.xml文件下

android:name="android.support.v4.content.FileProvider"

android:authorities="com.tvbox.yoostore.fileprovider"

android:grantUriPermissions="true"

android:exported="false">

android:name="android.support.FILE_PROVIDER_PATHS"

android:resource="@xml/file_paths"/>

第二: 在res目录下新建想xml文件夹及其xml文件夹下新建file_paths文件

file_paths文件内容如下:

最后兼容个版本的apk安装方法:

public static voidinstallApp(File file) {

Intent intent =newIntent(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(App.app.getApplicationContext(),"com.tvbox.yoostore"+".fileprovider",file);

intent.setDataAndType(contentUri,"application/vnd.android.package-archive");

}else{

intent.setDataAndType(Uri.fromFile(file),"application/vnd.android.package-archive");

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

}

App.app.getApplicationContext().startActivity(intent);

}

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐