为什么 ACTION_CARRIER_CONFIG_CHANGED 没有触发我的接收器?

Why is ACTION_CARRIER_CONFIG_CHANGED not triggering my receiver?

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

我知道 ACTION_CARRIER_CONFIG_CHANGED 是白名单广播,应该仍然有效。我在意图过滤器中尝试了不同的拼写组合(android.telephony.CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGEDCarrierConfigManager.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>

(注意:我将 ServiceStateChangedReceiver 的接收器注册移到了 MainActivity onCreate 方法,它的工作方式与之前在 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");
    }
}

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

的确切定义。

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