Android Example Retrieve one or multiple image(s) shared to your app

Discussion in 'Tutorials & Examples' started by KMatle, Apr 7, 2018.

  1. KMatle

    KMatle Expert Licensed User

    With this code you can retrieve images shared to your app (e.g. if a user selects one or more images from the gallery and selects "Share..."). No permissions are required as the user selects the images :)

    Add this to the manifest (send = one image, multiple = multiple images)

    *code optimized*

    Code:
    AddActivityText(Main,
    <
    intent-filter>
        <action android:name=
    "android.intent.action.SEND" />
        <category android:name=
    "android.intent.category.DEFAULT" />
        <data android:mimeType=
    "image/*" />
    </
    intent-filter>
    <
    intent-filter>
        <action android:name=
    "android.intent.action.SEND_MULTIPLE" />
        <category android:name=
    "android.intent.category.DEFAULT" />
        <data android:mimeType=
    "image/*" />
    </
    intent-filter>)
    Code

    Code:
    Dim ImageList As List
    ImageList=GetUrisFromStartingIntent(
    Activity.GetStartingIntent)
    Code:
    Private Sub GetUrisFromStartingIntent(in As IntentAs List
        
    Log(in.Action)
        
    Log(in.GetData)
        
    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 StringIntent As StringAs 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

    With friendly regards to @DonManfred
     
    Last edited: Apr 8, 2018
    DavideV, fredo, Erel and 1 other person like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice