首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么ACTION_CARRIER_CONFIG_CHANGED没有触发我的接收器?

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

Stack Overflow用户
提问于 2019-04-10 17:08:58
回答 1查看 352关注 0票数 0

我正在写一个Android应用程序,它应该记录对蜂窝网络连接的更改。我已经成功地实现了一个记录MCC/MNC更改的BroadcastReceiver (使用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:

代码语言:javascript
复制
    <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:

代码语言:javascript
复制
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");
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-10 22:46:07

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55608769

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档