没有找到处理 Intent { act=android.intent.action.DIAL } 的活动

Lor*_*ren 5 android android-intent

我想打开我的电话拨号器。但它显示错误。我已经在 Android Manifest 上声明了 CALL_PHONE 的权限,也在 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;
Run Code Online (Sandbox Code Playgroud)

Raj*_*esh 5

您不需要任何ACTION_DIALIntent权限。所以CALL_PHONEAndroidManifest.xml.

您还没有通过任何号码来触发拨号意图。

使用tel:后跟电话号码作为传递给 Uri.parse() 的值:

试试这个代码。

 String number = "1234567890";
 Uri number = Uri.parse("tel:" + number);
 Intent dial = new Intent(Intent.ACTION_DIAL);
 dial.setData(number);
 startActivity(dial);
Run Code Online (Sandbox Code Playgroud)

编辑:

您可以先检查设备是否支持电话

private boolean isTelephonyEnabled(){
    TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
    return tm != null && tm.getSimState()==TelephonyManager.SIM_STATE_READY
}
Run Code Online (Sandbox Code Playgroud)

我希望它有帮助!