标签:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
public class BatteryReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
//获取当前电量
int current = bundle.getInt("level");
//获取总电量
int total = bundle.getInt("scale");
//如果当前电量小于总电量的15%
if(current*1.0/total<0.15){
Toast.makeText(context, "电量过低,请尽快充电!", 5000).show();
}
}
}
使用BroadcastReceiver实现系统对手机电量进行提示
标签:
原文地址:http://www.cnblogs.com/jiww/p/5616285.html