Android Question How to delete file cleanly, GetSafeDirDefaultExternal usage

boten

Active Member
Licensed User
Longtime User
My app takes camera pictures and stores them "internally"
the directory they are stored is:

B4X:
Dim rp As RuntimePermissions
SafeDir=rp.GetSafeDirDefaultExternal("") & "/MYDIR"



/storage/emulated/0/Android/data/boten.mypkg/files/MYDIR

using a file browser I can see files in this dir, like:
/storage/emulated/0/Android/data/boten.mypkg/files/MYDIR/1.JPG
/storage/emulated/0/Android/data/boten.mypkg/files/MYDIR/2.JPG
etc...

the app also has a button that displays all the pictures taken in a grid.
when clicking a picture in the grid, it is shown full screen.
long-clicking on the full screen picture brings a dialog with the options:
1. share
2. delete

share works,
BUT when I choose "delete" the program stops with: unfortunately the app stopped
the log shows the error:
B4X:
galler_ivone_longclick (java line: 676)
java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from pid=5926, uid=10331
    at android.os.Parcel.readException(Parcel.java:1465)
    at android.os.Parcel.readException(Parcel.java:1419)
    at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:2586)
    at android.app.ContextImpl.sendBroadcast(ContextImpl.java:1472)
    at android.content.ContextWrapper.sendBroadcast(ContextWrapper.java:377)
    at anywheresoftware.b4a.phone.Phone.SendBroadcastIntent(Phone.java:177)
    at boten.corbuster.galler._ivone_longclick(galler.java:676)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at anywheresoftware.b4a.objects.ViewWrapper$2.onLongClick(ViewWrapper.java:90)
    at android.view.View.performLongClick(View.java:4669)
    at android.view.View$CheckForLongPress.run(View.java:19302)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:157)
    at android.app.ActivityThread.main(ActivityThread.java:5356)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
    at dalvik.system.NativeStart.main(Native Method)

The picture file is actually deleted! (not found in file browser)

Any ideas of how to avoid the crash?
 

boten

Active Member
Licensed User
Longtime User
MY BAD!
The error occured when I tried to broadcast intent to force GALLERY to update its albums to the internal dir - which of course CAN NOT BE DONE since no other app (gallery included) can access this internal dir. (can it be done?)
 
Upvote 0
Top