Created
May 21, 2018 10:12
-
-
Save ala98412/d738505ad443e73d154e2e6762249838 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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