As explained in this tutorial all store apps will soon be forced to target the latest SDK.
This means that we can no longer rely on the OS backwards compatibility features and need to handle the behavior changes ourselves.
Starting from Android 8 (API 26) each app needs to explicitly request a special permission to install other apps. The global "install applications from unknown sources" option was removed.
First we check whether we already have permission:
If not we open the relevant settings page:
We will then wait for Activity_Resume and check the value of CanRequestPackageInstalls again.
The last step is to start the installation intent.
The following non-dangerous permission is required:
A full example is attached. It also checks that the "installation from unknown source" option is enabled and that the external storage is writable.
Example updated and is now based on FileProvider class.
This means that we can no longer rely on the OS backwards compatibility features and need to handle the behavior changes ourselves.
Starting from Android 8 (API 26) each app needs to explicitly request a special permission to install other apps. The global "install applications from unknown sources" option was removed.
First we check whether we already have permission:
B4X:
Private Sub CanRequestPackageInstalls As Boolean
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim PackageManager As JavaObject = ctxt.RunMethod("getPackageManager", Null)
Return PackageManager.RunMethod("canRequestPackageInstalls", Null)
End Sub
If not we open the relevant settings page:
B4X:
MsgboxAsync("Please allow me to install applications.", "")
Wait For Msgbox_Result(Result As Int)
Dim in As Intent
in.Initialize("android.settings.MANAGE_UNKNOWN_APP_SOURCES", "package:" & Application.PackageName)
StartActivity(in)
We will then wait for Activity_Resume and check the value of CanRequestPackageInstalls again.
The last step is to start the installation intent.
The following non-dangerous permission is required:
B4X:
AddPermission(android.permission.REQUEST_INSTALL_PACKAGES)
A full example is attached. It also checks that the "installation from unknown source" option is enabled and that the external storage is writable.
Example updated and is now based on FileProvider class.
Attachments
Last edited: