Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

detecting battery charging android

<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>
Comment

detecting battery charging android

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.
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: how to extract value from payload in java 
Java :: space between lines textview android 
Java :: java thread syncronized locker 
Java :: linux mint switch language 
Java :: stack overflow recyclerview 
Java :: java operator 
Java :: editable column 
Java :: Duplicate class android.support.v4.os.ResultReceiver$MyRunnable 
Java :: Double And Char In Java 
Java :: java no name array eg 
Java :: convert zipfile to bytebuffer 
Java :: print character in string java 
Java :: get variable from another class java 
Java :: This version of the Android Support plugin for IntelliJ IDEA (or Android Studio) cannot open this project, please retry with version 2020.3.1 or newer. 
Java :: Eclipse find/replace pluggin 
Java :: Java 17 not showing in linux 
Java :: JAVA Display numbers from 1 to 5 
Java :: this java 
Java :: java 8 list of objects get only first occurance 
Java :: are classes in java public by default 
Java :: comparable interface 
Java :: No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode -[IDENT] IdentNode: 
Java :: ezra margolin 
Java :: java-word-count 
Java :: java decrypt CryptoJS 
Java :: run jar with logback config file 
Java :: change replication factor hadoop cluster command 
Java :: check whether an entry in hashmap is deleted in java 
Java :: how to take input an array in java 
Java :: find the length of jtextfeild in java 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =