首页 > 解决方案 > 为什么 ACTION_CARRIER_CONFIG_CHANGED 没有触发我的接收器?

问题描述

我正在编写一个 Android 应用程序,它应该记录对蜂窝网络连接的更改。我已经成功实现了一个BroadcastReceiver来记录 MCC/MNC 更改(使用android.intent.action.SERVICE_STATE),但我无法CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED触发我的接收器。我错过了什么?

我知道这ACTION_CARRIER_CONFIG_CHANGED是一个列入白名单的广播,应该仍然有效。android.telephony.CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED我在意图过滤器( 、、、CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGEDACTION_CARRIER_CONFIG_CHANGED)中尝试了不同的拼写组合。

来自 AndroidManifest.xml:

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <receiver android:name="CarrierConfigChangedReceiver" android:exported="true"> <!-- CARRIER_CONFIG_CHANGED -->
          <intent-filter>
            <action android:name="android.telephony.CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED" />
          </intent-filter>
        </receiver>

    </application>

(注意:我将我的接收器注册移至ServiceStateChangedReceiveronCreateMainActivity方法,该方法的工作原理与AndroidManifest.xml以前一样) - 但CarrierConfigChangedReceiver不起作用。

来自 CarrierConfigChangedReceiver.java:

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class CarrierConfigChangedReceiver extends BroadcastReceiver {

    String msg = "BNA";

    @Override
    public void onReceive(Context context, Intent intent) {

        Log.d(msg, "Carrier Config change detected");
    }
}

标签: androidbroadcastreceiver

解决方案


在尝试了许多其他意图事件之后,即android.intent.action.ACTION_SUBINFO_CONTENT_CHANGE(对我有用),我最终得出结论,我的设置中实际上没有任何ACTION_CARRIER_CONFIG_CHANGED事件。不幸的是,我无法找到确切触发ACTION_CARRIER_CONFIG_CHANGED.

所以我想答案是:如果发生这样的事件,它会起作用。


推荐阅读