BroadcastReceiver的获得ServiceState信息 [英] Broadcastreceiver to obtain ServiceState information

查看:159
本文介绍了BroadcastReceiver的获得ServiceState信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道的方式来获得手机服务状态(IN_SERVICE,OUT_OF_SERVICE,EMERGENCY_ONLY,POWER_OFF)的机器人。

Does anyone know of a way to obtain the phone service state (IN_SERVICE, OUT_OF_SERVICE, EMERGENCY_ONLY, POWER_OFF) in android.

我希望会有一个broadcastreciever,以找出发生的变化,但我无法找到任何东西。我知道有一个监听器,但我不知道我怎么会用,从我的应用程序,因为它是用WakefulIntentService(由thecommonsguy)的服务运行。

I was hoping there would be a broadcastreciever to identify the changes, but I can't find anything. I know there's a listener but I'm not sure how I would use that from my app as it runs as a service using a WakefulIntentService (by thecommonsguy).

使用类似的电量(即BATTERY_LOW,BATTERY_OKAY)这是很容易的,但我就是不能制定出一个类似的东西的电话服务的变化。

With something like battery level (ie BATTERY_LOW, BATTERY_OKAY) it's quite easy, but I just can't work out a similar things for phone service changes.

推荐答案

注册一个接收器

public static final String ACTION_SERVICE_STATE_CHANGED = "android.intent.action.SERVICE_STATE";

当你打算在你的接收器只需使用下面的小黑客从Android源

When you get intent on your receiver just use below little hack from android source

public void onReceive(Context context, Intent intent) {
    int state = intent.getExtras().getInt("state");
    if(state == ServiceState.STATE_IN_SERVICE)
    {
        //Do whatever you want
    }
    }

检查服务状态类的源 <一href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/1.5_r4/android/telephony/ServiceState.java#ServiceState.setFromNotifierBundle%28android.os.Bundle%29" rel="nofollow">http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/1.5_r4/android/telephony/ServiceState.java#ServiceState.setFromNotifierBundle%28android.os.Bundle%29

check source of service state class http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/1.5_r4/android/telephony/ServiceState.java#ServiceState.setFromNotifierBundle%28android.os.Bundle%29

这篇关于BroadcastReceiver的获得ServiceState信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆