Install apks outside the store has to have Developer permission released on the Android operating system (at least in the most current versions of the system I believe it is like this)
If you choose to place in the play store you can open "an Activity" with the playstore, as described in the documentation
https://developer.android.com/distribute/marketing-tools/linking-to-google-play
For example:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(
"https://play.google.com/store/apps/details?id=com.example.android"));
intent.setPackage("com.android.vending");
startActivity(intent);
And to avoid opening this Activity if the app is already installed you can use the getApplicationInfo
(that you can check if it is enabled as well) or simply use the getInstalledApplications
and check on the list
That is, you induce the user to install via playstore the app if not installed yet, thus facilitating and without root or Developer permissions.
I’m a little rusty on Android, but I think with https://developer.android.com/reference/android/content/pm/PackageInstaller you can do this because since API 29 ACTION_INSTALL_PACKAGE
[and considered obsolete
Probably using installExistingPackage
that will require permission Manifest.permission.INSTALL_PACKAGES
(should not use with third party packages)
You can also try Google play Instant:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri.Builder uriBuilder = Uri.parse("https://play.google.com/store/apps/details")
.buildUpon()
.appendQueryParameter("id", "com.example.android")
.appendQueryParameter("launch", "true");
uriBuilder.appendQueryParameter("referrer", "exampleCampaignId");
intent.setData(uriBuilder.build());
intent.setPackage("com.android.vending");
startActivity(intent);
That way he won’t even install (https://developer.android.com/topic/google-play-instant), however the app that will use this service needs to follow a number of situations to be made available as Instant: https://developer.android.com/topic/google-play-instant/guides/reduce-module-size
If I’m not mistaken, the latest versions of Android do not allow the installation of an APK without confirmation, even if you release the application to perform installations.
– Rafael Tavares
@Rafaeltavares thank you so much for the return.
– Rodrigo Dantas