Android Question App in 'Share Via' menu 4 single image but not 4 multiple image selections

Gregg Homan

Member
Licensed User
Longtime User
Hello,

I successfully added following intent-filter to my app's manifest file to cause my B4A application shows up in the Share Via drop-down menu when only one image is selected but NOT when multiple images are selected.

I noticed that about half of the apps that appear for single image selections disappear like my app when multiple images are selected; so, they have a problem similar to mine. I am guessing that an additional intent-filter needs to be added, but I have been unable to find any other thread that specifically addresses this issue. Can someone suggest what any additional intent-filter or modification to intent-filter below is required to cause my app to be listed in Share Via menus for multiple image selections?

Thanks,
Gregg

A note to newbies, like myself, though I must eventually write B4A app code to handle when my app is invoked from a Share Via menu; it is interesting to realize that only the intent-filter (see below) needed to be added to the manifest file to cause my app to be listed in the Share Via drop-down menu. This subtle fact is never really definitely stated in other threads that address Share Via issues. BTW, I added helpful debugging code that I hope will, in part, help me develop the necessary app code when app is invoked from a Share Via menu.

The intent-filter I added to manifest file to get my B4A app listed in the Share Via menu when selecting a single (but NOT multiple) image follows:
B4X:
AddActivityText(Main,
<intent-filter>
 <action android:name="android.intent.action.SEND" />
 <category android:name="android.intent.category.DEFAULT" />
 <data android:mimeType="image/*" />
</intent-filter>)

Manifest File containing additional intent-filter to cause Share Via to list my B4A app follows:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="4" />
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
'GGH 01-04-14, Intent to get included in Share Via menus
AddActivityText(Main,
<intent-filter>
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="image/*" />
</intent-filter>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.

Helpful debugging code to help develop code for when app is invoke from a Share Via menu:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim Intent1 As Intent
    Intent1 = Activity.GetStartingIntent
    If Intent1.Action = "android.intent.action.SEND" Then
        Log("Invoked by Share Via")
    Else If Intent1.Action = "android.intent.action.MAIN" Then
        Log("Invoked by Clicking on App")
    Else        
        Log("Should not happen")
    End If    
    Log("Action    :"&Intent1.Action)
    Log("GetExtra :"&Intent1.GetExtra("android.intent.extra.TEXT"))
    Log("Extras    :"&Intent1.ExtrasToString)
    Log("GetData :"&Intent1.GetData)
    Log("GetExtra:"&Intent1.GetExtra("android.intent.extra.TEXT"))
    Log(Intent1.HasExtra("EXTRA_TEXT"))
End Sub
 

Gregg Homan

Member
Licensed User
Longtime User
Thanks Erel!!! I greatly appreciate your timely assistance, this active forum, the B4A community, and B4A itself!!! Gregg

Here's the Manifest file that incorporates two Intents needed to be included in Share Via menus for both single image and multiple image selections:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="4" />
<supports-screens android:largeScreens="true" 
    android:normalScreens="true" 
    android:smallScreens="true" 
    android:anyDensity="true"/>)
'GGH 01-04-14, Intents to get included in Share Via menus
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>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.

Here's a B4A code example that handles the two Intents needed to be included in Share Via menus for both single image and multiple image selections:
B4X:
Sub Process_Globals
End Sub

Sub Globals
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim Intent1 As Intent
    Intent1 = Activity.GetStartingIntent
    If Intent1.Action = "android.intent.action.SEND" Then
        Log("Invoked by Share Via - single image")
    Else If Intent1.Action = "android.intent.action.SEND_MULTIPLE" Then
        Log("Invoked by Share Via - multiple images")
    Else If Intent1.Action = "android.intent.action.MAIN" Then
        Log("Invoked by Click on App")
    Else
        Log("Invoked by unknown method")
    End If
    Log("Action  :"&Intent1.Action)
    Log("GetData :"&Intent1.GetData)
    Log("GetExtra:"&Intent1.GetExtra("android.intent.extra.TEXT"))
    Log("ExtraStr:"&Intent1.ExtrasToString)
   
    If  Intent1.HasExtra("android.intent.extra.STREAM") Then
        Dim i, j As Int
        Dim str, fn As String
       
        str = Intent1.ExtrasToString.ToLowerCase
        If str.EndsWith("]}]") Then
            str=str.Replace("]}]",",")
        Else If str.EndsWith("}]") Then
            str=str.Replace("}]",",")
        End If
       
        'Parse Intents
        i = str.IndexOf("content:") 
        j = str.IndexOf(",")
        Do While i>0 AND j>0
            fn = GetPathFromContentResult(str.SubString2(i,j))
            Log("Filename: "&fn)
            str = str.SubString(j+1)
            i = str.IndexOf("content:") 
            j = str.IndexOf(",")
        Loop
    End If
End Sub

'GGH 01-05-13, SQL and Reflection lib
Sub GetPathFromContentResult(UriString As String) As String
   If UriString.StartsWith("/") Then Return UriString 'If the user used a file manager to choose the image
   Dim Proj() As String
   Proj = Array As String("_data")
   Dim Cursor As Cursor
   Dim r As Reflector
   Dim Uri As Object
   Uri = r.RunStaticMethod("android.net.Uri", "parse", _
      Array As Object(UriString), _
      Array As String("java.lang.String"))
   r.Target = r.GetContext
   r.Target = r.RunMethod("getContentResolver")
   Cursor = r.RunMethod4("query", _
   Array As Object(Uri, Proj, Null, Null, Null), _
   Array As String("android.net.Uri", _
      "[Ljava.lang.String;", "java.lang.String", _
      "[Ljava.lang.String;", "java.lang.String"))
   
   Cursor.Position = 0
   Dim res As String
   res = Cursor.GetString("_data")
   Cursor.Close
   Return res
End Sub
 
Upvote 0
Top