【问题标题】:android - cannot receive CALL intent in BroadcastReceiverandroid - 无法在 BroadcastReceiver 中接收 CALL 意图
【发布时间】:2017-06-29 04:38:46
【问题描述】:

我创建了一个 BroadcastReceiver 来检测 CALL 操作。

android.intent.action.CALLintent 在 Activity 中声明时收到。

<activity
    android:name="com.xxx.yyy.CallCatcherActivity"
    android:launchMode="singleTop"
    android:theme="@android:style/Theme.Translucent.NoTitleBar"
    android:screenOrientation="landscape">

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <action android:name="android.intent.action.CALL" />
        <action android:name="android.intent.action.CALL_BUTTON" />
        <action android:name="android.intent.action.CALL_PRIVILEGED" />
        <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
        <action android:name="android.intent.action.DIAL" />

        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="tel" />
    </intent-filter>
</activity>

但是,它不适用于 BroadcastReceiverService

AndroidManifest.xml

<receiver android:name="PhoneCallListener">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <action android:name="android.intent.action.CALL" />
        <action android:name="android.intent.action.CALL_BUTTON" />
        <action android:name="android.intent.action.CALL_PRIVILEGED" />
        <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
        <action android:name="android.intent.action.DIAL" />

        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="tel" />
    </intent-filter>
</receiver>

PhoneCallListener.java

public class PhoneCallListener extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("-", intent.getAction() + " received");

        try {
            if (intent.getAction().equals("android.intent.action.CALL")) {
                Log.d("-", "+ CALL action received!!");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

【问题讨论】:

  • 请列出您的应用权限

标签: android android-intent broadcastreceiver action phone-call


【解决方案1】:

动作 CALL 和动作 DIAL 用于启动Activity,这些动作不用于广播Intents。 Intents分别用于启动ActivityServiceBroadcastReceivers,它们之间没有任何关系。

有关如何捕获Intent.ACTION_NEW_OUTGOING_CALL 以及如何使用PhoneStateListener 检测呼叫状态变化的更多详细信息,请参阅How do you receive outgoing call in broadcastreceiver

另请参阅https://www.codeproject.com/Articles/548416/Detecting-incoming-and-outgoing-phone-calls-on-And,了解有关检测来电和去电的教程。

【讨论】:

    猜你喜欢
    • 2013-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多