In my Android Aplication I just need to open SMS intent with pre populated message_body and the PhoneNumber.
Following is the code I am trying
Uri uri = Uri.parse(String.format("smsto:%s", strPhoneNumber));
Intent smsIntent = new Intent(Intent.ACTION_SENDTO, uri);
smsIntent.putExtra("sms_body", "Sample Body");
startActivityForResult(smsIntent, OPEN_SMS_APP);
All works great in default scenario but if Facebook Messenger is installed and setup it as the default SMS Application (settings -> Apps & Notifications -> Default Apps -> SMS app) then the functionality breaks.
Problem is, it opens FB messenger without the message_body (empty) even though it correctly picks the phone number (in FB Messenger APP).
Further, I tried following tests but didn't pick SMS_BODY or opened default Android APP
smsIntent.addCategory(Intent.CATEGORY_APP_MESSAGING); // STILL DIDN'T FIX
smsIntent.putExtra(Intent.EXTRA_TEXT, "Sample Body"); // STILL DIDN'T FIX
Questions
If you really want to restrict to Google Android SMS App then can specify the package name of the Google App. But there are so many other Applications that will read 'sms_body' Intent Key.
Uri uri = Uri.parse(String.format("smsto:%s", strPhoneNumber));
Intent smsIntent = new Intent(Intent.ACTION_SENDTO, uri);
smsIntent.putExtra("sms_body", "Sample Body");
// To Force Google Android SMS APP To Open
smsIntent.setPackage("com.google.android.apps.messaging");
if (smsIntent.resolveActivity(getPackageManager()) != null)
{
startActivityForResult(smsIntent, OPEN_SMS_APP);
}
else
{
// Display error message to say Google Android SMS APP required.
}
But I would use the Application Chooser rather than just restricting to Google SMS App. Obviously user have to go through an additional step (click), but it lists all SMS Apps (every time) and user have the option to select a correctly working SMS Application.
startActivityForResult(Intent.createChooser(smsIntent, "Sample Title"), OPEN_SMS_APP);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With