我想在我的 Android 应用程序中收听 APN 更改。
因此,我在android.intent.action.BOOT_COMPLETED
. 此服务启动一个 ContentObserver,它侦听
content://telephony/carriers/preferapn
.
我在几个不同的设备上测试了这个设置(例如 LG Spirit with Android 5.0、Samsung A3 with 6.0、Emulator Nexus5 with 7.0 和 Huawei P9 Lite with 7.0)
在onCreate
我的服务的华为手机上没有调用。
我的另一种方法与Manifest 中注册的android.intent.action.ANY_DATA_STATE
a 相结合,BroadcastReceiver
在这款手机上也不起作用。
我的清单的相关部分:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
...
<receiver android:name=".ConnectivityChangeReceiver">
<intent-filter>
<action android:name="android.intent.action.ANY_DATA_STATE" />
</intent-filter>
</receiver>
<receiver android:name=".APNChangedServiceStarter" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>
</receiver>
<service android:name=".APNChangedService"></service>
Run Code Online (Sandbox Code Playgroud) android android-intent android-service bootcompleted huawei-mobile-services