I want to send SMS from my application, for which I have written below code, which is pretty simple. But the issue I am facing is, No activity is started on sending message
Method to send a message:
private void sendSMS(Context context, String phone, String msg){
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setData(Uri.parse("smsto:"));
smsIntent.putExtra("address", phone);
smsIntent.putExtra("sms_body", msg);
smsIntent.setType("vnd.android-dir/mms-sms");
try {
startActivity(smsIntent);
finish();
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(context, "SMS faild, please try again later.", Toast.LENGTH_SHORT).show();
}
}
Permission added in manifest
<uses-permission android:name="android.permission.SEND_SMS" />
It always shows toast written in catch()