Android Question Need a Little Help - Content Chooser File Error

Shadow&Max

Active Member
Licensed User
Longtime User
OK, I'm right a the end of something, and this is the last annoying thing I have to solve. This is a strange one... This almost always works, but one of my tester gets this error on his tablet, I don't. This works EVERY time on my phone. This FAILS EVERY TIME on the Genymotion emulator to match my phone (Moto-X). This is definitely a timing issue because it DOESN"T happen in either of the two debug modes (rapid/legacy) but does happen in release or release(obfuscated).

In the chooser's success module I have the following code (this is a snippet). I have all of the MsgBox calls to see how far it's getting:

B4X:
Sub cc_Result (Success As Boolean, Dir As String, FileName As String)
        If Success Then
            ChangesMade = True
            If CurrentTempPicFile.Trim = "" AND ImageFileName.Trim = "" Then
                Try
                    ImageFileDir = File.DirInternal
                    iv.Visible = False

                    Msgbox("1","Got Here!")
                  
                    CreateNewFileName
                  
                    Msgbox("2","Got Here!")
                  
                    ImageFileName = NewFileName
                  
                    Msgbox("3" & CRLF & Dir & CRLF & FileName,"Got Here!")
                  
                    b.Initialize(Dir, FileName)
                  
                    Msgbox("4","Got Here!")

This fails on the b.Initialize call. Well, not really... never seems to get to it. In Debug mode, it gets to the last MsgBox but in release mode, it goes from there to Activity_Resume and never hits MsgBox 4. I have the following sub, called from Activity_Resume:

B4X:
Sub RestorePic
    iv.Visible = False
    'WAS HERE

    Msgbox("Restore Pic 1","Here")
    b.Initialize(ImageFileDir, ImageFileName)
  
    Msgbox("Restore Pic 2","Here")
    ResizePhoto(File.DirInternal, ImageFileName)

    iv.Bitmap = b
    iv.Visible = True
    EditPic.Visible = True
    DelPic.Visible = True
    ivPreview.Visible = False
    btnRotateRight.Visible = False  
    btnRotateLeft.Visible = False

End Sub

The program fails on the b.Initialize call above. Gets to the first MsgBox, not the second (error is in screenshot below). I have tried everything I can think of to get the file to be saved before getting to that red call above, but it seems to always get to Activity_Resume before I can save the file. I've even done a File.Copy(Dir, FileName, ImageFileDir, ImageFileName) before the call to initialize b in the cc_Result sub.

It's not regular, and can't be duplicated on all devices. I have a Moto-X... works fine, even with a new, empty data file... I have a crappy tablet... Works fine on that. Genymotion fails ever time. Tester's tablet fails every time...

The error:

fem2.png


Any suggestions on how to get past this? FYI, the RestorePic code is there to bring back a picture if orientation has changed.
 

Shadow&Max

Active Member
Licensed User
Longtime User
(FYI, I just attached a complete log for a session from install, to triggering the error, continuing and closing the app...)

I don't GET the message in debug mode... it always works in debug mode... FYI, The rest of the code for cc_result is:

B4X:
Sub cc_Result (Success As Boolean, Dir As String, FileName As String)
        If Success Then
            ChangesMade = True
            If CurrentTempPicFile.Trim = "" AND ImageFileName.Trim = "" Then
                Try
                    ImageFileDir = File.DirInternal
                    iv.Visible = False
                    Msgbox("1","Got Here!")
                    CreateNewFileName
                    Msgbox("2","Got Here!")
                    ImageFileName = NewFileName
                    Msgbox("3" & CRLF & Dir & CRLF & FileName,"Got Here!")
                    b.Initialize(Dir, FileName)
                    Msgbox("4","Got Here!")
          
                    SavePhoto(ImageFileDir, ImageFileName)
                    ResizePhoto(ImageFileDir, ImageFileName)
      
                    iv.Bitmap = b
                    iv.Visible = True

                    PictureChanged = True
                    RecordChanged = True
                    Msgbox("Got Here!!!","Stop")

The call to SavePhoto would save the bitmap b to the new file named in the variable ImageFileName but it never gets that far. It gets to MsgBox 3 in the code above, and then goes to Activity_Resume. Had it finished the code above, that file would have been there. As it is, it never executes the save before Activity_Resume takes over... Technically, it's a correct message because the file can't be saved before... g1.jpg would be the correct file name. I've tried DoEvents all over the place but they don't affect anything. In debug mode, everything in cc_Result gets executed.

Here's the error log stuff:

java.io.FileNotFoundException: /data/data/com.twodogapps.diva/files/g1.jpg: open failed: ENOENT (No such file or directory)

at libcore.io.IoBridge.open(IoBridge.java:409)
at java.io.FileInputStream.<init>(FileInputStream.java:78)
at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:209)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize(CanvasWrapper.java:498)
at com.twodogapps.diva.addedit._restorepic(addedit.java:4395)
at com.twodogapps.diva.addedit._activity_resume(addedit.java:664)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
at com.twodogapps.diva.addedit$ResumeMessage.run(addedit.java:273)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
at libcore.io.IoBridge.open(IoBridge.java:393)
... 19 more
java.io.FileNotFoundException: /data/data/com.twodogapps.diva/files/g1.jpg: open failed: ENOENT (No such file or directory)
 

Attachments

  • log.txt
    52.3 KB · Views: 448
Last edited:
Upvote 0

Shadow&Max

Active Member
Licensed User
Longtime User
yes, b's a global bitmap.

I'll remove the DoEvents and MsgBox-s, but this was happening before I added them... they're only there to stop execution so I know how far it got... I wasn't able to get the log messages working in release mode for some reason...
 
Upvote 0

Shadow&Max

Active Member
Licensed User
Longtime User
Here's the log with the DoEvents and MsgBox statements removed... Same Error...
 

Attachments

  • log2.txt
    27.4 KB · Views: 334
Upvote 0

Shadow&Max

Active Member
Licensed User
Longtime User
I check for the file name. I suppose I could do a check to see if the file exists, but if it doesn't, then what? The reason that RestorePic sub is called from Activity_Resume is because the picture has to be restored if the orientation changes. However, if I comment that call to it out, I just get a blank pic and the file never gets copied...

BTW, I did try to save the Dir and FileName from the cc_Result to public variables and save the file in Activity_Resume, but I get a permissions failure when I try to access the file from Content...
 
Last edited:
Upvote 0

Shadow&Max

Active Member
Licensed User
Longtime User
I'm trying to wrap my head around this Erel... I'll try this. However, I'm confused. What is the URI? I get a Dir and a FileName from the cc_Result. Do I combine those two or is there some other variable I need to trap in the cc_Result?

OK, I looked at 1.zip and see...I'll try this and report back...

Thanks Erel...
 
Last edited:
Upvote 0

Shadow&Max

Active Member
Licensed User
Longtime User
Hi Erel:

OK, I ran 1.zip on my emulator and it errored out on permissions. I unzipped the project, ran 1, and this is what I get:

fem3.png



** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
Success = true, Dir = ContentDir, FileName = content://media/external/images/media/14

java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/14 from pid=1239, uid=10060 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
at android.os.Parcel.readException(Parcel.java:1465)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:413)
at android.content.ContentResolver.query(ContentResolver.java:461)
at android.content.ContentResolver.query(ContentResolver.java:404)
at anywheresoftware.b4a.objects.ContentResolverWrapper.Query(ContentResolverWrapper.java:43)
at b4a.example.main._getpathfromcontentresult(main.java:378)
at b4a.example.main._cc_result(main.java:334)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
at anywheresoftware.b4a.phone.Phone$ContentChooser$1.ResultArrived(Phone.java:843)
at anywheresoftware.b4a.BA$5.run(BA.java:505)
at anywheresoftware.b4a.BA.setActivityPaused(BA.java:390)
at b4a.example.main$ResumeMessage.run(main.java:271)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/14 from pid=1239, uid=10060 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
 
Upvote 0

Shadow&Max

Active Member
Licensed User
Longtime User
I added the permission to the manifest and the 1.b4a file worked... I'll try that on my project and see what happens with the code you sent... I'll post back in an hour or two with results. Thanks!
 
Upvote 0

Shadow&Max

Active Member
Licensed User
Longtime User
So far, so good. It's working on the Genymotion... I'll try it on several emulated devices to be sure, as well as on my tablet and phone, and let you know sometime later tonight for me, or your early morning. Thanks Erel...
 
Upvote 0

Shadow&Max

Active Member
Licensed User
Longtime User
Thanks Erel... I got it working. But it definitely needs the permission added to the manifest to work. This was a biggie for me. Thanks again...
 
Upvote 0
Top