有谁知道在android中获取电话服务状态(IN_SERVICE、OUT_OF_SERVICE、EMERGENCY_ONLY、POWER_OFF)的方法。
我希望有一个广播接收器来识别更改,但我找不到任何东西。我知道有一个监听器,但我不确定如何在我的应用程序中使用它,因为它使用 WakefulIntentService(由 thecommonsguy 提供)作为服务运行。
有了电池电量(即 BATTERY_LOW、BATTERY_OKAY)之类的东西,这很容易,但我无法为电话服务更改制定类似的东西。
最佳答案
为
注册一个接收器public static final String ACTION_SERVICE_STATE_CHANGED = "android.intent.action.SERVICE_STATE";
当你对你的接收器有兴趣时,只需使用下面来自 android 源的小技巧
public void onReceive(Context context, Intent intent) {
int state = intent.getExtras().getInt("state");
if(state == ServiceState.STATE_IN_SERVICE)
{
//Do whatever you want
}
}
关于android - Broadcastreceiver获取ServiceState信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4846271/