現時点では、ユーザーがアプリにアクセスしたときに、バッテリーの状態を何らかの形で示したいだけです。たとえば、デバイスが接続されている場合、デバイスは充電中とそのレベルを表示する必要があります。デバイスが取り外されている場合、何も表示されません。デバイスが充電されておらず、電池残量が少ない場合は、電池残量低下の表示が表示されます。
ほとんどのコードをセットアップしましたが、問題は、たとえば、アプリを実行し、デバイスが接続されている場合、画面に充電インジケータが表示されることです。デバイスのプラグを抜くと充電は見えなくなりますが、デバイスを再接続しても充電は見えなくなります。バッテリ アラートは、デバイスが接続されているか、接続されていないか、バッテリが高いか低いかを常に表示する必要があります。情報の変更は常に表示する必要があります。
だからここに私の放送受信機があります:
  private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver()  {
        @Override
        public void onReceive(Context arg0, Intent intent) {
            //Battery level
            int level = intent.getIntExtra("level", 0);
            //Plugged in Status
            int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
            //Battery Status
            int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
            //If the device is charging or contains a full status, it's charging
            boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
                    status == BatteryManager.BATTERY_STATUS_FULL;
            //If the device isCharging and plugged in, then show that the battery is charging
            TextView batteryTextView = ((TextView) findViewById(R.id.charging));
            TextView batteryLowTextView = ((TextView) findViewById(R.id.low_battery));
            ImageView batteryLowImageView= ((ImageView) findViewById(R.id.low_battery_icon));
            ImageView batteryImageView =((ImageView) findViewById(R.id.charging_battery_icon));
            if (isCharging && plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB) {
                //Gets the 'last synced' string and sets to datetime of the last sync
                Resources resources = context.getResources();
                String chargingString = String.format(resources.getString(R.string.charging), level);
                //Dynamically sets the value of the battery level
                batteryLowTextView.setVisibility(TextView.INVISIBLE);
                batteryLowImageView.setVisibility(ImageView.INVISIBLE);
                batteryTextView.setText(chargingString + "%");
            } else if (level < LOW_BATTERY_LEVEL && !isCharging) {
                Resources resources = context.getResources();
                String lowBatteryString = String.format(resources.getString(R.string.low_battery));
                batteryTextView.setVisibility(TextView.INVISIBLE);
                batteryImageView.setVisibility(ImageView.INVISIBLE);
                batteryLowTextView.setText(lowBatteryString);
            } else if (!isCharging && level > LOW_BATTERY_LEVEL) {
                //do nothing
                batteryTextView.setVisibility(TextView.GONE);
                batteryImageView.setVisibility(ImageView.GONE);
            }
        }
    };
私の OnCreate メソッドで、私は呼び出します
 //calls registerReceiver to receive the broadcast for the state of battery
            this.registerReceiver(this.mBatInfoReceiver,new
                    IntentFilter(Intent.ACTION_BATTERY_CHANGED));
だから、私は何が間違っているのだろうか?それはブールですか?