Android detects amperage from the charger

I am trying to detect (if possible) the power emanating from a / usb charger. gets the intention extra - EXTRA_VOLTAGE will help me achieve this? sometimes USB produces a different current - 1000 mA, and sometimes less. How can I find out the current strength?

Thank!

+3
source share
2 answers

Yes, ACTION_BATTERY_CHANGED is a sticky broadcast

this.registerReceiver(this.batReceiver,     
    new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

private BroadcastReceiver batReceiver = new BroadcastReceiver(){

    @Override

    public void onReceive(Context arg0, Intent intent) {
    int voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, 0);

    int source = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);     

    }    
  };

It seems you want the charger source to use EXTRA_PLUGGED 0 for battery, 1 for AC and 2 for USB

+3
source

u should use the receiver and initialize it in the Android manifest file.

 <receiver android:name=".reboot" android:enabled="true"
        android:exported="false" android:label="StartServiceAtBootReceiver">
        <intent-filter>
            <action android:name="android.intent.action.EXTRA_VOLTAGE" />
        </intent-filter>
    </receiver>

in the reciver file

@Override
public void onReceive(Context context, Intent intent) {
    if("android.intent.action.EXTRA_VOLTAGE".equals(intent.getAction()))
    {
}
}
0
source

All Articles