我正在写一个Android应用程序,它应该记录对蜂窝网络连接的更改。我已经成功地实现了一个记录MCC/MNC更改的BroadcastReceiver (使用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_CHANGED、ACTION_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");
}
}发布于 2019-04-10 22:46:07
在尝试了许多其他意图事件后,例如android.intent.action.ACTION_SUBINFO_CONTENT_CHANGE (对我有效),我最终得出结论,在我的设置中实际上没有ACTION_CARRIER_CONFIG_CHANGED事件。不幸的是,我无法找到触发ACTION_CARRIER_CONFIG_CHANGED的确切原因的确切定义。
所以我猜答案是:如果这样的事件发生了,它就会起作用。
https://stackoverflow.com/questions/55608769
复制相似问题