美文网首页Android学习
android适配android10安装

android适配android10安装

作者: crush_d872 | 来源:发表于2019-12-08 11:55 被阅读0次
public static void installApk(Context context,String filePath) {
    try {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        File file = new File(filePath);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // 7.0+以上版本
            Uri apkUri = FileProvider.getUriForFile(context, "cn.wlantv.kznk.fileprovider", file); //与manifest中定义的provider中的authorities="cn.wlantv.kznk.fileprovider"保持一致
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
        } else {
            intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
        }
        context.startActivity(intent);
    }catch (IllegalArgumentException e){

    }

}

相关文章

网友评论

    本文标题:android适配android10安装

    本文链接:https://www.haomeiwen.com/subject/rdkmgctx.html