Skip to content

Instantly share code, notes, and snippets.

@lvyitian
Forked from LloydBlv/Extensions.kt
Created July 2, 2024 23:51
Show Gist options
  • Select an option

  • Save lvyitian/3ca0a3ea3bb7ad713444e860c8c5376a to your computer and use it in GitHub Desktop.

Select an option

Save lvyitian/3ca0a3ea3bb7ad713444e860c8c5376a to your computer and use it in GitHub Desktop.
Install APK programmatically
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