I want to open my phone dialer .But it shows error. I have declared permissions for CALL_PHONE on Android Manifest and also declared class in Android Manifest.
case R.id.action_call:
Log.d("Action_call","INside Action call");
Intent dialer = new Intent(Intent.ACTION_DIAL);
startActivity(dialer);
return true;
You don't need any permissions for ACTION_DIAL
Intent. So remove CALL_PHONE
permission from AndroidManifest.xml
.
You have not pass any number to fire dial Intent.
Use tel:
followed by the phone number as the value passed to Uri.parse():
Try this code.
String number = "1234567890";
Uri number = Uri.parse("tel:" + number);
Intent dial = new Intent(Intent.ACTION_DIAL);
dial.setData(number);
startActivity(dial);
EDIT:
You can first check whether telephony is supported on device
private boolean isTelephonyEnabled(){
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
return tm != null && tm.getSimState()==TelephonyManager.SIM_STATE_READY
}
I hope it helps!
Use Uri
to parse number..
Intent call = new Intent(Intent.ACTION_DIAL);
call.setData(Uri.parse("tel:"+phone)); //String phone
startActivity(call);
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