Android Question Get multiple images using StartActivityForResult

Jean Weets

Member
Licensed User
Longtime User
With this code item and uris is empty.
Does anyone know a solution? I have a Samsung A50 with the latest Android version. Thnx

B4X:
Sub Activity_Click
    Dim i As Intent
    i.Initialize("android.intent.action.GET_CONTENT", "")
    i.PutExtra("android.intent.extra.ALLOW_MULTIPLE", True)
    i.SetType("image/*")
    StartActivityForResult(i)
End Sub
Sub ion_Event (MethodName As String, Args() As Object) As Object
    If Args(0) = -1 Then 'resultCode = RESULT_OK
        Dim i As Intent = Args(1)
        Dim jo As JavaObject = i
        'Android 4.1+ (API 16)
        Dim uris As List
        uris.Initialize
        Dim clipdata As JavaObject = jo.RunMethod("getClipData", Null)
        If clipdata.IsInitialized Then
            Dim count As Int = clipdata.RunMethod("getItemCount", Null)
            For i2 = 0 To count -1
                Dim item As JavaObject = clipdata.RunMethod("getItemAt", Array(i2))
                uris.Add(item.RunMethod("getUri", Null))
            Next
        Else
            uris.Add(i.GetData)
        End If
        Log(uris)
    End If
    Return Null
End Sub
Sub StartActivityForResult(i As Intent)
    Dim jo As JavaObject = GetBA
    ion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null)
    jo.RunMethod("startActivityForResult", Array As Object(ion, i))
End Sub
Sub GetBA As Object
    Dim jo As JavaObject
    Dim cls As String = Me
    cls = cls.SubString("class ".Length)
    jo.InitializeStatic(cls)
    Return jo.GetField("processBA")
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Your code works fine here.

The logs output is:
(ArrayList) [content://com.google.android.apps.photos.contentprovider/0/1/mediakey%3A%2Flocal%253A7da3bbdd-a6ed-49d2-86a5-864774bafb1d/ORIGINAL/NONE/787558906, content://com.google.android.apps.photos.contentprovider/0/1/mediakey%3A%2Flocal%253A8cbf25ac-27a0-4430-be2d-f1e0d0456106/ORIGINAL/NONE/577244119]

It is possible that the app that was started from this intent doesn't properly support multiselection.
 
Upvote 0

Jean Weets

Member
Licensed User
Longtime User

Thank you, but i can't find a solution for the Samsung A50
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…