找不到与action.DIAL一起处理Intent的Activity

Jac*_*ień 10 android android-intent

我似乎缺乏处理这种意图的知识,但是暂时找不到答案.

我有一个片段的活动.片段执行此代码是为了调用联系人:

private void onCall() {
    Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(contact.getBusinessPhone()));
    startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)

还包括许可

<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission> 
Run Code Online (Sandbox Code Playgroud)

输出是No Activity found to handle Intent和应用程序崩溃.

这是包含片段的活动的清单实现:

<activity android:name="activities.ContactActivity">            
    <intent-filter>
        <action android:name="android.intent.action.DIAL" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?我需要在清单中声明一些特殊活动吗?

Via*_*lav 66

您不需要在清单中声明拨号intent-filter,也不需要ACTION_DIAL的任何权限.寻找我的实施

private void startDialActivity(String phone){
    Intent intent = new Intent(Intent.ACTION_DIAL);
    intent.setData(Uri.parse("tel:"+phone));
    startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)

也很好检查设备上支持的电话

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

  • 请记住,TelephonyManager.SIM_STATE_READY将失败支持电话的CDMA手机(例如一些Verizon手机).因此,如果`tm.getPhoneType()!= TelephonyManager.PHONE_TYPE_GSM`你要检查`context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)`以确保它是否真的是没有电话的平板电脑,或者只是一个手机没有SIM卡,但有电话. (7认同)

dt0*_*dt0 8

Intent.ACTION_VIEW 为我做得更好,因为在没有拨号器的平板电脑上,它会自动切换到"添加到联系人".