高温高压系统预警机制

frameworks/base/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
添加一个全局变量
private int mHealthType;

在class Receiver的onReceive中添加
mHealthType=intent.getIntExtra("health",BatteryManager.BATTERY_HEALTH_UNKNOWN);
if(mHealthType==BatteryManager.BATTERY_HEALTH_OVERHEAT || mHealthType==BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE){
	Intent activityIntent = new Intent();
	activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
				| Intent.FLAG_ACTIVITY_CLEAR_TOP
				| Intent.FLAG_ACTIVITY_CLEAR_EXCLUDE_FROM_RECENTS);
	activityIntent.setClass(mContext,BatteryWarningActivity.class);
	activityIntent.putExtra(BatteryWarningActivity.KEY_TYPE,mHealthType);
	mContext.startActivity(activityIntent);
}

frameworks/base/packages/SystemUI/AndroidManifest.xml
给BatteryWarningActivity类进行注册
<activity android:name=".power.BatteryWarningActivity"></activity>

写一个新的类来进行预警提示
package com.android.systemui.power;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.BatteryManager;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;

/**
 * Created by songyan on 2018/2/26.
 */

public class BatteryWarningActivity extends Activity{
    private static final String TAG="BatteryWaringAcitivity";
    protected static final String KEY_TYPE="type";
    private int mType;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        Intent intent=getIntent();
        mType=intent.getIntExtra(KEY_TYPE,-1);
        Log.d("songdebug","onCreate,mType is "+mType);
        if(mType== BatteryManager.BATTERY_HEALTH_OVERHEAT){
            showDialogMessage("Temperature Warning","temperature is too high!");
        }else if (mType==BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE){
            showDialogMessage("Voltage Warning","voltage is too hight!");
        }else {
            finish();
        }
    }

    private void showDialogMessage(String tem,String message){
        AlertDialog.Builder builder=new AlertDialog.Builder(BatteryWarningActivity,this);
        builder.setTitle(tem);
        builder.setMessage(message);
        builder.setPositiveButton("ok",new DialogInterface.OnClickListener(){
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        builder.setNegativeButton("cancle", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        builder.setCancelable(false);//点击空白区域提示框不消失
        builder.show();
    }

    protected void onDestroy(){
        super.onDestroy();
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值