android - 为什么 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_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
onCreateMainActivity
方法,该方法的工作原理与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
.
所以我想答案是:如果发生这样的事件,它会起作用。
推荐阅读
- javascript - Laravel 7 jQuery UI datepicker: Uncaught TypeError: $(...).datepicker is not a function
- javascript - JavaScript 从另一个对象创建对象
- java - Selenium WebDriver 无耻地返回不正确的 WebElement 高度
- python - Django Listview FormMixin
- ansible - ansible playbook 执行并且没有显示错误,但没有在主机上执行预期的操作
- php - 我如何在不重复自己的情况下更好地编写此语句,它需要使用简单的 html dom 的值
- android - Android Studio - 加载小部件时出现问题(切换/切换)
- javascript - 如何将数据从 javascript 发送到 python 烧瓶后端?
- java - java - 如何通过java中的selenium在弹出框中发送用户名和密码?
- apache-kafka - FlinkRunner 上的 ApacheBeam 不从 Kafka 读取