Skip to content

Instantly share code, notes, and snippets.

@ala98412
Created May 21, 2018 10:12
Show Gist options
  • Save ala98412/d738505ad443e73d154e2e6762249838 to your computer and use it in GitHub Desktop.
Save ala98412/d738505ad443e73d154e2e6762249838 to your computer and use it in GitHub Desktop.
protected void installApk(File file) {
Intent intent = new Intent();
//執行動作
intent.setAction(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//執行類型
if (Build.VERSION.SDK_INT >= 24) {
Uri apkuri = FileProvider.getUriForFile(Option.this, getApplicationContext().getPackageName() + ".provider", file);
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");
Option.this.startActivity(intent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment