Android Question Returning text to Intent

epiCode

Active Member
Licensed User
I'm trying to Modify String received by EXTRA_PROCESS_TEXT intent

I found a post here in forum with an example of how to handle an intent in B4a (Thanks to the author)

But there is no mention of returning / updating text sent by Text Contextual Popup Menu

Can anyone share what needs to be done or where or whom can I connect with for this ?
 
Solution
The extra key should be: "android.intent.extra.PROCESS_TEXT"


It still did not work , however your last input helped me make it work after a few more hits and trials. Thank you so much for guiding me to a solution.
sharing the final code here just in case it helps anyone in same situation

this is code to go in Activity_Oncreate

Put in Activity Oncreate:
Sub Activity_Create(FirstTime As Boolean)
  
    Dim strFromIntent As String=""
    
    Try
        If Activity.GetStartingIntent.Action="android.intent.action.PROCESS_TEXT" Then
            strFromIntent=Activity.GetStartingIntent.GetExtra("android.intent.extra.PROCESS_TEXT")
            
            '\\\\  your modification code here

              '/// Code to return text back...

epiCode

Active Member
Licensed User
If your activity was started with StartActivityForResult then you should use Activity.SetActivityResult to return the result to the calling app.
Thanks for a prompt reply

1. StartActivityForResult (Im not sure how to determine that but I'm selecting text in another app where the text is editable and can be changed by other apps
2. Your example helped me correct the SetActivityResult but it is still not workig

Please guide where am I going wrong...

This is how my code is structured

Manifest:
'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: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true" 
    android:normalScreens="true" 
    android:smallScreens="true" 
    android:anyDensity="true"
    android:theme="@android:style/Theme.Translucent"
    />)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.


'FOR TRANSPARENT ACTIVITY
SetActivityAttribute(ACTION_PROCESS_TEXT, android:theme, "@android:style/Theme.Translucent.NoTitleBar")

'for removing from the recent app's list
SetActivityAttribute(ACTION_PROCESS_TEXT, "android:excludeFromRecents", "true")


'For Creating custom Text Selection actions with ACTION_PROCESS_TEXT
SetActivityAttribute(ACTION_PROCESS_TEXT, android:label, "Convert to Decimal")
AddActivityText(ACTION_PROCESS_TEXT,
<intent-filter>
    <action android:name="android.intent.action.PROCESS_TEXT" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="text/plain" />
</intent-filter>)

Activity ACTION_PROCESS TEXT:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Dim strActoin As String=""
    
    Try
        If Activity.GetStartingIntent.Action="android.intent.action.PROCESS_TEXT" Then
            strActoin=Activity.GetStartingIntent.GetExtra("android.intent.extra.PROCESS_TEXT")
            
            If strActoin<>"" Then
              
' /// Code for action 
' /// if strnew is null after code  then ....

                If strnew="" Then ExitApplication  'just exit no error to be given

                Dim DoAction As Intent
                
                DoAction.Initialize("android.intent.action.PROCESS_TEXT","")
                DoAction.Flags=1
                
                Activity.GetStartingIntent.PutExtra("android.Intent.EXTRA_PROCESS_TEXT", strnew)  'strnew is the text to be returned
                
                Activity.SetActivityResult(-1,DoAction)

            Else

                ToastMessageShow ("Nothing Selected",0) ' might never land here tho

            End If
        End If
    Catch
        Log(LastException)
    End Try
    
End Sub

Sub Activity_Resume
    
Activity.Finish ' close the activity

End Sub
 
Upvote 0

epiCode

Active Member
Licensed User
The extra key should be: "android.intent.extra.PROCESS_TEXT"


It still did not work , however your last input helped me make it work after a few more hits and trials. Thank you so much for guiding me to a solution.
sharing the final code here just in case it helps anyone in same situation

this is code to go in Activity_Oncreate

Put in Activity Oncreate:
Sub Activity_Create(FirstTime As Boolean)
  
    Dim strFromIntent As String=""
    
    Try
        If Activity.GetStartingIntent.Action="android.intent.action.PROCESS_TEXT" Then
            strFromIntent=Activity.GetStartingIntent.GetExtra("android.intent.extra.PROCESS_TEXT")
            
            '\\\\  your modification code here

              '/// Code to return text back via intent
                Dim returnText As Intent 
                
                returnText.Initialize("android.intent.action.PROCESS_TEXT","")
                returnText.Flags=1
                returnText.PutExtra("android.intent.extra.PROCESS_TEXT", strnew)  ' ///// replace strnew with modified string you wish to return 
                Activity.SetActivityResult(-1,returnText)
                Activity.Finish
            Else
                ToastMessageShow ("Nothing Selected",0)
            End If
        End If
    Catch
        Log(LastException)
    End Try
End Sub

Sub Activity_Resume

End Sub
 
Upvote 0
Solution
Top