I am installing an app programmatically in Android Studio. I am downloading the apk file and then building and launching the Intent
:
val intent = Intent()
intent.setDataAndType(uri, "application/vnd.android.package-archive")
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
intent.action = Intent.ACTION_VIEW
context.startActivity(intent)
The main problem is that that app (the one that will be installed) needs an Extra
called GUID
. This is how I launch the app with that Extra
:
val intent = packageManager.getLaunchIntentForPackage(applicationData.packageName)
intent?.let { i: Intent ->
i.putExtra("GUID", loggedUserSingleton.guid)
context.startActivity(intent)
}
I need to launch the app with that Extra
but Android asks the user if they want to open it after the installation:
I tried to put this line i.putExtra("GUID", loggedUserSingleton.guid)
inside the installation Intent
but is useless.
Is there an option to not show that dialog? Or maybe make the 'Open' option allow you to pass the Extra
?
What the app installer UI does is up to Google and device manufacturers. It will vary by OS version and device model. You cannot control this.
That said, using
ACTION_VIEW
to install an app has been deprecated for some time. If you usePackageInstaller
, you may have somewhat more control. FWIW, I cover the use ofPackageInstaller
in this chapter of this free book of mine.That too is not an option. Usually, "Open" will do the same thing that the launcher would, and a launcher is not going to know anything about this extra.