Advertisement
P1NG2WIN

Untitled

May 29th, 2020
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.81 KB | None | 0 0
  1.     private fun startInstalling(outputFile: String) {
  2.         Log.d(TAG, "startInstalling")
  3.         val path: Uri = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
  4.             Uri.parse("file://$outputFile")
  5.         } else {
  6.             FileProvider.getUriForFile(
  7.                 this,
  8.                 applicationContext.packageName.toString() + ".provider",
  9.                 File(outputFile)
  10.             )
  11.         }
  12.  
  13.         val intent = Intent(Intent.ACTION_VIEW, path)
  14.             .apply {
  15.                 putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true)
  16.                 setDataAndType(path, "application/vnd.android.package-archive")
  17.                 addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
  18.                 addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
  19.             }
  20.         startActivity(intent)
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement