android.intent.action.BATTERY_OKAY无法在广播接收器中工作,在广播接收器中该怎么办?

时间:2015-06-15 23:18:40

标签: android android-intent action broadcast receiver

清单:

<receiver android:name=".BatteryFullReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.BATTERY_OKAY" />
            </intent-filter>
        </receiver>

广播接收器:

public class BatteryFullReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
//      String intentAction = intent.getAction();
//      if(Intent.ACTION_BATTERY_OKAY.equalsIgnoreCase(intentAction)){
            Toast.makeText (context, "Battery Full", Toast.LENGTH_LONG).show ();
            Speaker.tts.speak("Battery full ,you can disconnect the usb now", TextToSpeech.QUEUE_ADD, null);       
        }
//  }

}

我尝试使用电池电量低而且工作正常。但电池正常工作无效。有时我使用那些代码,这就是为什么我使用评论进行检查。但没有什么工作。请帮助!!!

1 个答案:

答案 0 :(得分:1)

你拼错了意图行动: android.intent.action.ACTION_BATTERY_OKAY

文档http://developer.android.com/training/monitoring-device-state/battery-monitoring.html#DetermineChargeState

中有完整的示例