Android Question [b4xpages]Share Selected text to app

trepdas

Active Member
Licensed User
Hello Erel, B4x community and rest (api) of you good people.

I need to make a fairly simple task.

- user copied text to clipboard

1. display our app in the app list to choose from
2. process the text in the app.

I have already implemented sharing images to our app with this example


so I assume that it shouldn't be too difficult to add this but ...


[I'm using b4xpages in our project so I planted the activity_resume sub in the main module]

Main:
Sub Activity_Resume
    B4XPages.Delegate.Activity_Resume
    If IsRelevantIntent(Activity.GetStartingIntent) Then
        Dim in As JavaObject = Activity.GetStartingIntent
        Dim uri As String = in.RunMethod("getParcelableExtra", Array("android.intent.extra.STREAM"))
        Dim flag As Boolean
        Try
            Log("Loading bitmap from: " & uri)
            Dim bmp As Bitmap = LoadBitmapResize("ContentDir", uri, 100%x, 100%y,flag)
            Activity.SetBackgroundImage(bmp)
        Catch
            Log(LastException)
        End Try
    End If
End Sub




TIA
 
Last edited:

trepdas

Active Member
Licensed User
Great ! I added this in the manifest. the app is in the list to share and I can send a copied clipboard to the app.

B4X:
   <data android:mimeType="text/*" />

Now, what would be the activity_resume (handling the intent) to distinguish clipboard text / image?

šŸ™
 
Last edited:
Upvote 0

trepdas

Active Member
Licensed User
solved.




Activity_Resume:
Sub Activity_Resume
    B4XPages.Delegate.Activity_Resume
    If IsRelevantIntent(Activity.GetStartingIntent) Then
        Dim in As JavaObject = Activity.GetStartingIntent
        
        Dim t As String = in.RunMethod("getType", Null)
            If t.Contains("text") Then B4XPages.MainPage.HandleText
    
        Dim uri As String = in.RunMethod("getParcelableExtra", Array("android.intent.extra.STREAM"))
        Dim flag As Boolean
        Try
            Log("Loading bitmap from: " & uri)
            Dim bmp As Bitmap = LoadBitmapResize("ContentDir", uri, 100%x, 100%y,flag)
            Activity.SetBackgroundImage(bmp)
        Catch
            Log(LastException)
        End Try
    End If
End Sub
 
Last edited:
Upvote 0

trepdas

Active Member
Licensed User
can anyone tell ?
How do I get the shared clipboard content into a public string ???

I added the clipboard lib and tried to set it with no success
B4X:
Public Sub HandleText
    Dim tlc As String
   
    If Cl.hasText Then
        tlc=Cl.getText
        Else
            Return
    End If
   
End Sub

Clipboard is empty :/
I tried to make this check inside the activity_resume sub also with no success
 
Last edited:
Upvote 0
Top