No Activity found to handle Intent { act=android.intent.action.DIAL }

佐手、 提交于 2021-01-27 05:55:23

问题


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;

回答1:


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!




回答2:


Use Uri to parse number..

Intent call = new Intent(Intent.ACTION_DIAL);
call.setData(Uri.parse("tel:"+phone));  //String phone
startActivity(call);



回答3:


  • 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){
    }
    


来源:https://stackoverflow.com/questions/32263955/no-activity-found-to-handle-intent-act-android-intent-action-dial

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!