“Mendeteksi Android Pengisian Baterai” Kode Jawaban

Mendeteksi Android Pengisian Baterai

<receiver android:name=".PowerConnectionReceiver">
  <intent-filter>
    <action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
    <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
  </intent-filter>
</receiver>
Faithful Fox

Mendeteksi Android Pengisian Baterai

public class PowerConnectionReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) { 
        int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
        boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
                            status == BatteryManager.BATTERY_STATUS_FULL;


        int chargePlug = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
        boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
        boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;
      //remove some variables if you don't need it.
    }
}
Faithful Fox

Jawaban yang mirip dengan “Mendeteksi Android Pengisian Baterai”

Pertanyaan yang mirip dengan “Mendeteksi Android Pengisian Baterai”

Lebih banyak jawaban terkait untuk “Mendeteksi Android Pengisian Baterai” di Java

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya