Android Question Receiving shared text from other apps

FrankDev

Active Member
Licensed User
Hi
I use the following source to get text from another application.

B4X:
Sub Activity_Resume
    
    If IsRelevantIntent(Activity.GetStartingIntent) Then
        Dim in As Intent = Activity.GetStartingIntent
        Dim lin As String  = in
        ToastMessageShow(lin,true)    

    End If

End Sub

Private Sub IsRelevantIntent(in As Intent) As Boolean
    If in.IsInitialized And in <> OldIntent And in.Action = in.ACTION_SEND Then
        OldIntent = in
        Return True
    End If
    Return False
End Sub


It works...
but
I think it's more of a coincidence.

regards Frank
 

FrankDev

Active Member
Licensed User
Hi

i come from the YouTube app and press the button to share the video.
then I choose my app.

So I accept the video link.
Like I said, it works.
My app accepts the link

but that I'm turning the intent into a string.
doesn't seem really' good' to me.

Dim in As Intent = Activity. GetStartingIntent
Dim lin As String = in


AddActivityText(Main,
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>)

regards Frank
 

FrankDev

Active Member
Licensed User
from 'Receiving shared images'

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

'my version to get the String

Dim in As JavaObject = Activity.GetStartingIntent
Dim uri As String  = in
 

GeoT

Active Member
Licensed User
As FrankDev said, you have to put the code in the Manifest Editor to make it work:

B4X:
AddActivityText(Main,
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>)
But you also have to put:

B4X:
SetActivityAttribute(Main, android:launchMode, "singleTask")
Well, it is necessary to configure launchMode in singleTask, instead of the singleTop predetermined by B4A internally or by Android, because if not, if your application was previously open, it creates another task of the same app, so there are two tasks of the same application at the same time on your device.

This automatically closes the first task so that the user is not confused by choosing it in the recent Android applications view.

This problem appears as of Android 6.

Regards.
 
Top