Android Question Get multiple images using StartActivityForResult

red30

Well-Known Member
Licensed User
Longtime User
How to get some images with StartActivityForResult? I do not understand how to use StartActivityForResult. Can you explain it in detail?
Eler wrote that with StartActivityForResult and:
ACTION_GET_CONTENT = "android.intent.action.GET_CONTENT"
EXTRA_ALLOW_MULTIPLE = "android.intent.extra.ALLOW_MULTIPLE"
But I do not understand how to do it...
B4X:
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)
        Log(i)
    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

Sub TakePicture
    Dim i As Intent
    i.Initialize("android.intent.extra.ALLOW_MULTIPLE", "")
    StartActivityForResult(i)
End Sub

Sub Button1_Click
    TakePicture
End Sub
 

red30

Well-Known Member
Licensed User
Longtime User
I used this example:
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
But I still get only one photo...
 
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
It works but not everywhere. On Samsung (Android 4.4.2) through the standard gallery does not work.
 
Upvote 0
Top