android - 找不到使用 action.DIAL 处理 Intent 的 Activity

标签 android android-intent

我似乎缺乏处理此类 Intent 的知识,但是暂时找不到答案。

我有一个 fragment 的 Activity 。该 fragment 执行此代码以调用联系人:

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

还包括权限

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

输出是No Activity found to handle Intent,应用崩溃。

这是包含 fragment 的 Activity 的 list 实现:

<activity android:name="activities.ContactActivity">            
    <intent-filter>
        <action android:name="android.intent.action.DIAL" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

我做错了什么?为此,我需要在 list 中声明一些特殊 Activity 吗?

最佳答案

您不需要在 list 中声明 dial intent-filter,也不需要任何 ACTION_DIAL 权限。寻找我的实现

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

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

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

关于android - 找不到使用 action.DIAL 处理 Intent 的 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16236504/

相关文章:

android - Google Play 开发者控制台 : Supported Android Devices: 0

android - 如何从java代码中读取自定义维度属性

android - React Native ScrollView 设备方向景观

java - 如何选择正确的方式来获取Java中的相关上下文?

android - Activity 从 MapActivity 切换到 Activity

android - 如何制作 map 中标记地点的 ListView ?

android - 方向变化不抓取正确的布局

Android 即时应用程序 : showInstallPrompt's postInstallIntent does nothing?

java - 无法获取从 BroadcastReceiver 发送的 Intent

android - 设置Action bar下拉菜单不可见