Android Question ( solved ) Close SMS Intent?

anOparator

Active Member
Licensed User
Longtime User
In 2016 it was not allowed to automatically CLOSE the "android.settings.WIFI_SETTINGS" activity.
In my app I select a poem, start an SMS intent, edit the poem and Send, ending up in Messenger.
Is there a way to Return to my app OR programmatically close the SMS activity?
B4X:
 Sub txnd_Click
    Dim itxt As Intent
    itxt.Initialize(itxt.ACTION_VIEW, "sms:")
    itxt.PutExtra("sms_body", story.Text)
    StartActivity(itxt)

    Activity.Finish    
    Log("after Finish")            ' Messenger stays in foreground
    Activity.RemoveAllViews
    Log("after RemoveAllViews")    ' Messenger stays in foreground
'    Activity.GetStartingIntent
'    Return
End Sub
 

anOparator

Active Member
Licensed User
Longtime User
Ok so I've just learned that Activity.Finish and ExitApplication written within the Intent that called it won't close the SMS Intent. I also gave up testing 'Close Intent' via Resumable Subs.
I've always wanted to send a SMS from an app and be returned to the app after "message sent" occurs and I still welcome code snippets, ideas, or even a definitive 'can't be done'. ThanksInAdvance
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
the activity that you start via an intent can return something to you (StartActivityForResult). it's easy enough if the activity you start is yours. with 3rd party apps, it only works if that app has been written to return something. many - if not most - are not.

in the case of sending an sms, there is an additional issue: if you are not publishing on play, it would not be difficult to add the necessary code to your sms sender. if your idea is to publish the app, then you will have a problem because google will not usually allow you to override the system sms app.

another possibility: the app started by your intent could restart your app with an intent of its own. your original activity (the caller) can check to see if it's being started
by the system or by another activity and act accordingly. in some ways this could be an interesting option.

but, in the end, the real issue boils down to which app sends the sms. if it's yours, no problem. if it's the pre-installed app, then you need to know if it exposes setResult() or if it can use an intent to start another activity (ie, yours). or you'll have to convince google to allow you to override the default app.
 
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
Great overview thanks.
Ok so a good animation on the page where user selects send SMS or TextMssg asking user to "press Back button to return to my app" solves everything.

also I just found this from 2018 :
Google has changed their policy regarding the following permissions:
B4X:
 READ_SMS, SEND_SMS, WRITE_SMS, RECEIVE_SMS
READ_CALL_LOG, WRITE_CALL_LOG, PROCESS_OUTGOING_CALLS
Only the default phone or messaging apps can use these permissions:
 
Upvote 0
Top