Guest User

Untitled

a guest
May 25th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. protected void installApk(File file) {
  2. Intent intent = new Intent();
  3. //執行動作
  4. intent.setAction(Intent.ACTION_VIEW);
  5. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  6. //執行類型
  7. if (Build.VERSION.SDK_INT >= 24) {
  8. Uri apkuri = FileProvider.getUriForFile(Option.this, getApplicationContext().getPackageName() + ".provider", file);
  9. intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  10. intent.setDataAndType(apkuri, "application/vnd.android.package-archive");
  11. }
  12. else
  13. intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
  14.  
  15. Option.this.startActivity(intent);
  16. }
Add Comment
Please, Sign In to add comment