版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012966861/article/details/79379657
frameworks/base/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
添加一个全局变量
在class Receiver的onReceive中添加
frameworks/base/packages/SystemUI/AndroidManifest.xml
给BatteryWarningActivity类进行注册
写一个新的类来进行预警提示
添加一个全局变量
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();
}
}