-
-
Save lvyitian/3ca0a3ea3bb7ad713444e860c8c5376a to your computer and use it in GitHub Desktop.
Install APK programmatically
This file contains hidden or 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
| return Intent().apply { | |
| if (isN()) { | |
| action = Intent.ACTION_INSTALL_PACKAGE | |
| flags = Intent.FLAG_GRANT_READ_URI_PERMISSION | |
| data = FileProvider.getUriForFile(context, | |
| "${context.applicationContext.packageName}.provider", apkFile) | |
| } else { | |
| action = Intent.ACTION_VIEW | |
| data = Uri.fromFile(apkFile) | |
| type = "application/vnd.android.package-archive" | |
| flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment