Android : For call and send SMS Intent need to add permission?

Viewed 3918

I'm working on Call and SMS Intent while user click on call and SMS button.

Question:

1) Need to add permission in AndroidManifest.xml file?

2) Need to code for runtime permission also?

I write code for call intent is below:

 Intent intent = new Intent(Intent.ACTION_DIAL);
                intent.setData(Uri.parse("tel:" + driverMobileNo));
                startActivity(intent);

SMS intent

Intent it = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:"+ driverMobileNo));
            it.putExtra("sms_body", "The SMS text");
            startActivity(it);

Above code working fine (tested in Oreo 8.0 version) without adding permission in AndroidManifest.xml and also runtime.

2 Answers

You can use this code without any permission:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + phoneNumber));     
intent.putExtra("sms_body", message); 
startActivity(intent);

For the call, you can use this without any permission:

Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:phoneNumber"))
startActivity(intent);

You don't need any permission as the user actually make the call, you just redirect him to the phone app. If you want to make the phone call directly through your app, you have to use ACTION_CALL instead of ACTION_DIAL and add the permission :

<uses-permission android:name="android.permission.CALL_PHONE" />

Hope it helps !

For sms you can write

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setData(Uri.parse("smsto:"+phoneNumber)); // This ensures only SMS apps respond
intent.putExtra("sms_body", message);
startActivity(intent);

and for call you can use this intent

Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:0123456789"));
startActivity(intent); 
Related