Android Question Detecting intent cancellation?

Sub7

Active Member
Licensed User
Longtime User
Morning, i am working on this code that create an image on file.dirRootExternal after opening the gallery pic an image, crop it and put the result on an imageview.

This is partially working, after executing the sub GetFRomGallery(arguments) if the user press the cancel button in gallery the file is not generated and error occurs (file not found)

I kindly ask an advice on how to detect and manage this exception since i ran out of ideas for now, thank you.

B4X:
Sub imgGallery3_Click

Dim q As Int
q= Msgbox2(mgsbox_uploadText,"Confirm","Upload","","Cancel",Null)
If q = DialogResponse.POSITIVE Then
RandFileName = Rnd(0001,9999) &"-"& Rnd(1450,6721) &"-"& Rnd(1223,3321) &".jpg"
clickedView = 4
GetFromGallery(File.DirRootExternal&"/app_temp/", RandFileName, 140)   
    Else If q = DialogResponse.NEGATIVE Then
        ToastMessageShow("Operation cancelled", True)
End If
End Sub


Sub GetFromGallery(Directory As String, PictureName As String, size As Int)

    Dim i As Intent
    i.Initialize(i.ACTION_PICK, "")
    i.SetType("image/*")
    i.PutExtra("output", ParseUri("file://" & File.Combine(Directory, PictureName))) 'output folder you set OpenCam(File.DirRootExternal, "1.jpg")
    i.PutExtra("crop", "true") 'crop ON
    i.PutExtra("aspectX", 1) 'crop aspects
    i.PutExtra("aspectY", 1) 'crop aspects
    i.PutExtra("outputX", size) 'crop size //Set this to define the max size of the output bitmap
    i.PutExtra("outputY", size) 'crop size //Set this to define the max size of the output bitmap
    i.putExtra("scale", True)
    i.putExtra("scaleUpIfNeeded", True)
    StartActivity(i)
End Sub

Sub ParseUri(FileName As String) As Object
Dim r As Reflector
Return r.RunStaticMethod("android.net.Uri", "parse", Array As Object(FileName), Array As String("java.lang.String"))
End Sub

Error on cancel
B4X:
java.io.FileNotFoundException: /storage/emulated/0/app_temp/6972-4048-1410.jpg: open failed: ENOENT (No such file or directory)
 
Last edited:
Top