未找到处理意图的活动 { act=android.intent.action.CALL dat=+123456789 p



当我单击活动中的按钮时,以下代码工作正常,但在单击片段中的按钮时收到"找不到处理意图的活动"错误。

            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("+123456789"));
            startActivity(callIntent);
我认为

您应该说您添加的数据是这样的电话号码: callIntent.setData(Uri.parse("tel:+123456789"));

这是一个完整的解决方案:

首先,将以下权限添加到您的manifest.xml

<uses-permission android:name="android.permission.CALL_PHONE" />

然后使用以下代码进行调用:

String phone = "+34666777888";
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", phone, null));
startActivity(intent);

更新:

您不需要CALL_PHONE权限即可ACTION_DIAL.

将以下代码添加到 API 高于 22 的主文件中

<uses-feature
    android:name="android.hardware.telephony"
    android:required="false" />
<uses-permission android:name="android.permission.CALL_PHONE"/>

然后使用此代码

Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:+123456789"));
        startActivity(callIntent);
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:+123456789"));
        IntentChooser chooser= Intent.createChooser(callIntent,"title")
        startActivity(chooser);

希望对您有所帮助。确保已在清单文件中添加了适当的权限。

添加此代码将正常工作

//string phone="034028477736"
Intent intent=new Intent(Intent.Action-dial,Uri.fromparts("tell",phone,null));
startactivity(intent);//

最新更新