Android Question Intent does not open SMS & Take pictures applications

ciginfo

Well-Known Member
Licensed User
Longtime User
Bonjour,
Intent opens the SMS app on certain Smartphones, not on all smartphones. Idem to take pictures
B4X:
Sub Btn_Click   
    Dim number, message As String
    number = "0123456789"
    message = "Hello"
    Dim In As Intent
    In.Initialize(In.ACTION_VIEW, "sms:" & number)
    In.PutExtra("sms_body",  Message)
    StartActivity(In)
End sub
This code works on some smartphones and not others
Thank you
 

JohnC

Expert
Licensed User
Longtime User
Try this code (if it works, please mark it as the "solution"):
B4X:
Dim iIntent As Intent  

iIntent.Initialize("android.intent.action.SEND", "")  

iIntent.SetType("text/plain")  

iIntent.PutExtra("address", TelNum)        'TelNum = number to send to (just numbers)
   
iIntent.PutExtra("sms_body", SMSText)        'SMSText is text to be included in message
iIntent.PutExtra("android.intent.extra.TEXT", SMSText)
   
iIntent.Flags = 268435456    'FLAG_ACTIVITY_NEW_TASK

Dim JO As JavaObject      
JO.InitializeContext
JO.RunMethod("startActivity", Array(iIntent))
 
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
No, This code refers to Whatsapp and not to SMS.

And what means
B4X:
iIntent.Flags = 268435456    'FLAG_ACTIVITY_NEW_TASK
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
No, This code refers to Whatsapp and not to SMS.

And what means
B4X:
iIntent.Flags = 268435456    'FLAG_ACTIVITY_NEW_TASK
Try doing a "Clear Defaults" for the Whatsapp and when you run your app again, select your SMS app and select "Always".

I believe I added that flag so that if you try to run your app again, it won't instantly jump to the SMS app by mistake because the last intent was still active.
 
Last edited:
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
Like this it works, but the person who downloads the app will not know that this is necessary. My previous code went directly to SMS
 
Upvote 0
Top