首页 > 移动平台 > 详细

使用BroadcastReceiver实现系统对手机电量进行提示

时间:2016-06-25 15:05:16      阅读:328      评论:0      收藏:0      [点我收藏+]

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!