Android Question [solved] Get Filename from Incoming Image Intent

trepdas

Active Member
Licensed User
Longtime User
Hello good b4x people,

I am receiving the image successfully (intent from image gallery to the app.)

How can I get the file name of the sent image?

B4X:
Dim uri As String = in.RunMethod("getParcelableExtra", Array("android.intent.extra.STREAM"))


uri value in log : content://0@media/external/images/media/11281

TIA
 
Last edited:

KMatle

Expert
Licensed User
Longtime User
I use these subs. Remove the limit of 1 image if you want. In "Resume" I prevent the user to start the app as he/she must select some images and share it to my app. Remove this, too if needed.

B4X:
Sub Activity_Resume
    Log(Activity.GetStartingIntent.ExtrasToString)
    If Activity.GetStartingIntent.Action="android.intent.action.MAIN" Then
       MsgboxAsync("Please use the 'share' option of the other app... ","Info")
       Return
    End If

    ImageList=GetUrisFromStartingIntent(Activity.GetStartingIntent)
    If ImageList.Size>0 Then
        If ImageList.size>1 Then 'remove the limit if needed
            MsgboxAsync("Please select ONE image","Too many images")
            Return
        End If
        For i=0 To ImageList.Size-1
            Dim uri As String = ImageList.Get(i)
            
            ...

Private Sub GetUrisFromStartingIntent(in As Intent) As List
    Log(in.Action)
    Log(in.ExtrasToString)
    
    Dim ImageList As List
    ImageList.Initialize
    If in.IsInitialized And in <> OldIntent Then
        If in.Action = "android.intent.action.SEND" Or in.Action= "android.intent.action.SEND_MULTIPLE" Then
           ImageList= GetImageUrisFromExtras(in.ExtrasToString, in.action)     
        End If
        OldIntent = in
    End If
    Return ImageList
End Sub

Sub GetImageUrisFromExtras (Extras As String, Intent As String) As List
    Log(Extras)
    Dim ImageList As List
    ImageList.Initialize
    
    Dim JO As JavaObject = Activity.GetStartingIntent
    Select Intent
        Case "android.intent.action.SEND"
            Dim uri As String = JO.RunMethod("getParcelableExtra", Array("android.intent.extra.STREAM"))
            ImageList.Add(uri)
        Case "android.intent.action.SEND_MULTIPLE"
            Dim uris As List = JO.RunMethod("getParcelableArrayListExtra", Array("android.intent.extra.STREAM"))
            If uris.Size > 0 Then
                For i = 0 To uris.Size-1
                    ImageList.Add(uris.Get(i))
                Next
            End If
    End Select
    
    Return ImageList
End Sub
 
Upvote 0

trepdas

Active Member
Licensed User
Longtime User
Thank you for your example.
I tried it , ImageList returns as uri above
content://0@media/external/images/media/11279
:\
I need the actual file name (title)
(i.e. img003.jpg)

I may not adapted your example properly. such a shame I need to leave now for my boring day job , away from b4x.
but I'll keep running this in the gray windmills of my mind and will be back!

?
 
Last edited:
Upvote 0

trepdas

Active Member
Licensed User
Longtime User
Android goes a long way to hide the file system. Don't try to get the original file. Don't assume that there is a file. It can come from many types of sources.

Thank you Erel. I will always consider that in the future. "There is no spoon."...

as for the example you sent -

Cool !!
It really works !

:D



Thank you for this
 

Attachments

  • scf.jpg
    scf.jpg
    116.1 KB · Views: 183
Last edited:
Upvote 0
Top