Reputation: 5338
I'm using this code to send intent default sms app in my application
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address", number);
smsIntent.putExtra("sms_body",message);
if (smsIntent.resolveActivity(context.getPackageManager()) != null) {
context.startActivity(smsIntent);
}
This code open an sms app in android 5 (and probably in kitkat!) but it may or may not be the default sms app! So sometimes when it does not open default sms app i get an error because only default app can send sms!
my question is how to insure only default app handles my intents ?
Upvotes: 0
Views: 245
Reputation: 5951
try adding this-
smsIntent.addCategory(Intent.CATEGORY_DEFAULT);
this should ensure the recipient app is the default one.
Or alternatively for KK, you could try this-
SmsManager.getDefault().sendTextMessage("Phone Number", null, "Message", null, null);
N.B: Using this method requires that your app has the SEND_SMS permission.
For further information, please see sendTextMessage() documentation
Upvotes: 1