5

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;
2
  • 2
    I think you are using a tab with no call support. Commented Aug 28, 2015 at 6:32
  • which os version deos your phone have? Commented Dec 17, 2016 at 9:53

3 Answers 3

6

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!

5
  • Still the same problem persists
    – Loren
    Commented Aug 28, 2015 at 6:18
  • E/AndroidRuntime(12246): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.DIAL dat=tel:xxxxxxxxxx }
    – Loren
    Commented Aug 28, 2015 at 6:24
  • in which device you are running app? Commented Aug 28, 2015 at 6:25
  • Try ACTION_CALL instead of ACTION_DIAL in above code and also add CALL_PHONE permission in manifest then try Commented Aug 28, 2015 at 7:16
  • accessing SimState requires networkState permission, is there any other way to check if Telephone is allowed or not. because making a call doesnt require network state and just adding extra permission for accessing Sim state to check if telephony is allowed looks kind of overkill.
    – soan saini
    Commented Jan 29, 2018 at 23:55
3

Use Uri to parse number..

Intent call = new Intent(Intent.ACTION_DIAL);
call.setData(Uri.parse("tel:"+phone));  //String phone
startActivity(call);
0
  • Use try/catch.
  • Use Uri to parse number.
  • Don't need any permissions for ACTION_DIAL intent.

    try{
        Intent call_intent = new Intent(Intent.ACTION_DIAL);
        call_intent.setData(Uri.parse("tel:"+phone_number));
        startActivity(call_intent);
    }catch(Exception e){
    }
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.