Android Question Backing up to SD or somewhere

IDDGroup

Member
Licensed User
Longtime User
I am kindof at witts end on this.

I have an app that uses a SQLITE database, and i just want allow the user to back it up somewhere.

I would love to put it on the root of the SD card, however, whatever i try doesnt work. it only allows me to copy to the sandboxed area (IE: sdcard/android/your app id/files etc)

The problem with this, is if the customer deletes and re-installs the app, deleting the app removes that directory and backups are lost.

I am SO open to any idea on how to handle this. Im sure there are others out there that have to backup.


frustrating because the app is all finished except for this.
 

DonManfred

Expert
Licensed User
Longtime User
Use runtimepermissions.
Request write permission for external storage (the Internal one).
Write to file.DirRootExternal or any other (sub-)Folder

To write on the REAL SDCard you need to use the External Storage Class as it is the only way to write there.
 
Upvote 0

IDDGroup

Member
Licensed User
Longtime User
thanks!

i think i am on my way with the external storage class, just a few more things to figure out.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
maybe this is of help

 
Upvote 0

IDDGroup

Member
Licensed User
Longtime User
where im stuck is trying to blindly create a directory.

what im trying to do is on the startup, create a directory on the root of the SD (Appname, then Appname/Backups)

but it keeps crashing on the "CreateNewDirectory" function with a null pointer.

I can get it if i show the filedialog, but like i said, i want it hidden.



Error occurred on line: 70 (ExternalStorage)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object anywheresoftware.b4j.object.JavaObject.RunMethod(java.lang.String, java.lang.Object[])' on a null object reference
at com.PrintChecksPro.PCP.externalstorage._createnewdir(externalstorage.java:190)
at com.PrintChecksPro.PCP.main2._showfirst(main2.java:1334)
at com.PrintChecksPro.PCP.main2._activity_create(main2.java:660)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at com.PrintChecksPro.PCP.main2.afterFirstLayout(main2.java:104)
at com.PrintChecksPro.PCP.main2.access$000(main2.java:17)
at com.PrintChecksPro.PCP.main2$WaitForLayout.run(main2.java:82)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6188)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:911)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:801)
** Activity (main2) Resume **
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I can get it if i show the filedialog, but like i said, i want it hidden.
It is MANDATORY to let the user choose the root path ONCE (you can save the path once the user selected the rootpath for further use).
It can not be prevented...

Also note that the user may select any subfolder of the SD Card instead of the ROOT Folder.
In this case you´ll only get access to the Selected path (and everything in it (sub-folder-structure)).
 
Last edited:
Upvote 0

IDDGroup

Member
Licensed User
Longtime User
have it working somewhat.

I keep getting this error:

java.lang.ClassCastException: java.lang.String cannot be cast to com.PrintChecksPro.PCP.externalstorage$_externalfile

the line is the first line in the itemclick function.
dim f as externalfile=value

the weird thing is, if i trace it in the debugger, it doesnt happen. it works fine.

is there something i am missing?
 
Upvote 0

IDDGroup

Member
Licensed User
Longtime User
I got it.

I dont know why it was happening, but i just removed the = value, and assigned it after "finding" the file.

Thanks for your help Don.
 
Upvote 0

IDDGroup

Member
Licensed User
Longtime User
quick question,

does this not work in the emulator?

I have everything working fine on real devices, but it crashes miserably on the emulator.
 
Upvote 0
Top