Android Question Problem with stored file on Dir.DefaultExternal

Matteo Giorgini

Member
Licensed User
Hi to all!
I develop a new app that use some routine extract from another project developped with B4A v. 6.8, and other version ok SDK.
In particolar, all routines that save data (SQLite database, for example) in Dir.DefaultExternal.

I'm developing this new app with B4A v. 9.50 and android.jar v. 28, jdk1.8.0_201.
I did read some post, where was explain whats to put on manifest editor, and I added this:

AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission(android.permission.READ_EXTERNAL_STORAGE)
AddPermission(android.permission.WRITE_MEDIA_STORAGE)
AddPermission(android.permission.READ_MEDIA_STORAGE)

On starting, I had log this:

File.ExternalWritable = true
File.DirDefaultExternal= /storage/emulated/0/Android/data/{PackageName}/files
File.DirRootExternal= /storage/emulated/0
File.DirInternal= /data/user/0/{PackageName}/files


During initializing of SQLite database, with this code:
DBLocalTemporary.Initialize(dbLocalPath, dbLocalName, FlagCreateLocalDB)
I obtain:
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database

If I change Dir.DefaultExternal in File.DirInternal it's all ok.


With this setting, update APK don't works.
I download new APK's file with FTP library and process ended normally.
I check existence of new APK's file on File.DirInternal directory, but when try to install with intent with this code:
Dim ii As Intent
ii.Initialize(ii.ACTION_VIEW, "file://" & apkNew)
ii.SetType("application/vnd.android.package-archive")
StartActivity(ii)

App crash and on log I found this:
android.os.FileUriExposedException: file:///data/user/0/etp.pushexample/files/VerifierAlarmsSafeCash.apk exposed beyond app through Intent.getData()


My questions are:
1) why in other version with same devices Dir.DefaultExternal was ok?
2) why I can't found File.DirDefaultExternal= /storage/emulated/0/Android/data/{PackageName}/files on my device?
3) why I can't install new version with intent?
Can you help me?

Thanks in advance for all tips...
Matteo
 

Matteo Giorgini

Member
Licensed User
Ok! I think that save file and create db are solved.
But.. why after a download on "safe dir" I receive an exception when I try, via Intent, to update my apk?
<Code>
'apkNew values => '/storage/emulated/0/Android/data/b4a.example/files/VerifierAlarmsSafeCash.apk'
Dim ii As Intent
ii.Initialize(ii.ACTION_VIEW, "file:/" & apkNew)
ii.SetType("application/vnd.android.package-archive")
StartActivity(ii)
</Code>
Exception:
android.os.FileUriExposedException: file://storage/emulated/0/Android/data/b4a.example/files/{ApkName}.apk exposed beyond app through Intent.getData()

Thanks for to link your tutorial.

Can you help me for this last issue?

Matteo
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Can you help me for this last issue?
Use the forumsearch and search for FileUriExposedException.
You´ll get into valid results and the solution.

I suggest to first search, then ask if you don´t find anything.
In this case i´m sure you find good answers.

Fileprovider
 
Upvote 0
Top