概述
IntentFilter mIntentFilter = new IntentFilter();
mIntentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
registerReceiver(mReceiverBatteryInfo, mIntentFilter);
private BroadcastReceiver mReceiverBatteryInfo = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.i(TAG, "mReceiverBatteryInfo action = " + action);
if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
boolean present = intent.getBooleanExtra("present",false);
int health = intent.getIntExtra("health", 0);
int level = intent.getIntExtra("level", 0);
int scale = intent.getIntExtra("voltage", 0);
int plugType = intent.getIntExtra("plugged", 0);
int status = intent.getIntExtra("status", BatteryManager.BATTERY_STATUS_UNKNOWN);
int temperature = intent.getIntExtra("temperature", BatteryManager.BATTERY_HEALTH_UNKNOWN);
setSummary(present,health,level,scale, plugType, status, temperature);
}
}
};
最后
以上就是负责猎豹为你收集整理的安卓 开发 监听电量的全部内容,希望文章能够帮你解决安卓 开发 监听电量所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复