1

我想在通知栏中显示电池电量(例如: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);

但是我怎样才能将它与我的巴雷级别代码合并?

4

0 回答 0