我想在通知栏中显示电池电量(如:50%)。按下复选框时我想要它,因为我想决定是否显示它。无论如何,我将此代码用于电池级别:
@Override
public void onCreate() {
BroadcastReceiver batteryReceiver = new BroadcastReceiver() {
int level = -1;
@Override
public void onReceive(Context context, Intent intent) {
level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
Log.e("BatteryManager", "level is "+level+");
}
};
IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
registerReceiver(batteryReceiver, filter);
}
要发布通知我发现了这个:
NotificationManager notifi = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher,"Testing",System.currentTimeMillis());
notification.flags = Notification.FLAG_ONGOING_EVENT;
Intent i = new Intent(this,KillerActivity.class);
PendingIntent penInt = PendingIntent.getActivity(getApplicationContext(), 0 , i , 0);
notification.setLatestEventInfo(getApplicationContext(), "Varaha ", "Testing", penInt);
notifi.notify(215,notification);
但是我如何将它与我的barrey级代码合并?