Android Question Receiving shared text from other apps

FrankDev

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

Code: Copy
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
 
How are you starting the 2nd app? Post the code which creates the Intent

- On the starting-side you can Add Extras to the Intent.
- On the receiving side you can get the Extras back from the Intent.
 
Upvote 0
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
 
Upvote 0
from 'Receiving shared images'

Code: Copy
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
 
Upvote 0
As FrankDev said, you have to put the code in the Manifest Editor to make it work:

Code: Copy
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:

Code: Copy
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.
 
Upvote 0

Similar Threads

Back
Top