fun executeInstall(cxt: Context, _file: File) {
try{
val DATA_AND_TYPE = "application/vnd.android.package-archive";
val intent = Intent(Intent.ACTION_VIEW)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
val file = _file
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {
val apkUri = FileProvider.getUriForFile(cxt, BuildConfig.APPLICATION_ID +
".fileProvider", file)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
intent.setDataAndType(apkUri, DATA_AND_TYPE)
cxt.startActivity(intent)
} else {
val pc:Process = Runtime.getRuntime().exec("chmod 755 $file");
pc.waitFor()
val apkUri = Uri.fromFile(file)
intent.setDataAndType(apkUri, DATA_AND_TYPE)
cxt.startActivity(intent)
}
}catch(e:java.lang.Exception){
e.printStackTrace()
}
}
网友评论