Hi Guys!
For update my APP, I decided to use an FTP.
Now... before old Android version I launched an intent and all worked.
Today I update my code and I added "FileProvider" taken from [https://www.b4x.com/android/forum/threads/version-safe-apk-installation.87667/#content]
Naturally, I have updated my project:
- Javac.exe: 11.0.1
- android.jar: 28
- Android's version on device: 10
I modified Manifest (like sample InstallAPK) and now is:
I created Starter service, for create FileProvider.
First time that launch update, Android ask me to set unknown source for update: I setted it.
When update starts, I receive a starnge message: "Error while parsing the package."
APK not was installed.
If I open manually "shared" folder and tap on APK, setup starts and end without problems.
"My" SendInstallaIntent procedure is:
Intent was initialized with this uri:
If I exec InstallAPK sample on same device works all.
Do you have any idea? Can you help me?
Thanks in advance,
Matteo
For update my APP, I decided to use an FTP.
Now... before old Android version I launched an intent and all worked.
Today I update my code and I added "FileProvider" taken from [https://www.b4x.com/android/forum/threads/version-safe-apk-installation.87667/#content]
Naturally, I have updated my project:
- Javac.exe: 11.0.1
- android.jar: 28
- Android's version on device: 10
I modified Manifest (like sample InstallAPK) and now is:
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission(android.permission.READ_EXTERNAL_STORAGE)
AddPermission(android.permission.WRITE_MEDIA_STORAGE)
AddPermission(android.permission.READ_MEDIA_STORAGE)
'End of default text.
AddManifestText(<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
)
AddApplicationText(
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="$PACKAGE$.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
)
'CreateResource(xml, provider_paths,
' <external-files-path name="name" path="shared" />
')
'AddPermission(android.permission.REQUEST_INSTALL_PACKAGES)
CreateResource(xml, provider_paths,
<files-path name="name" path="shared" />
)
AddPermission(android.permission.REQUEST_INSTALL_PACKAGES)
I created Starter service, for create FileProvider.
First time that launch update, Android ask me to set unknown source for update: I setted it.
When update starts, I receive a starnge message: "Error while parsing the package."
APK not was installed.
If I open manually "shared" folder and tap on APK, setup starts and end without problems.
"My" SendInstallaIntent procedure is:
B4X:
Private Sub SendInstallIntent
Dim ApkName As String = "StoreMobile.apk"
'File APK was copied in this path from download's flow => File.copy(File.DirAssets, ApkName, Starter.Provider.SharedFolder, ApkName)
Dim i As Intent
Dim uri As String = ""
If phone.SdkVersion >= 24 Then
uri = Starter.Provider.GetFileUri(ApkName)
Log(uri)
i.Initialize("android.intent.action.INSTALL_PACKAGE", uri )
i.Flags = Bit.Or(i.Flags, 1) 'FLAG_GRANT_READ_URI_PERMISSION
Else
i.Initialize(i.ACTION_VIEW, "file://" & File.Combine(Starter.Provider.SharedFolder, ApkName))
i.SetType("application/vnd.android.package-archive")
End If
StartActivity(i)
End Sub
Intent was initialized with this uri:
B4X:
content://net.commercod.storemobile.provider/name/StoreMobile.apk
If I exec InstallAPK sample on same device works all.
Do you have any idea? Can you help me?
Thanks in advance,
Matteo