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.
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 !