问题
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