Reputation: 5792
I am trying to detect (if it is possible) the amperage coming from the charger/usb. is getting the intent extra - EXTRA_VOLTAGE will help me achieve that? sometimes the USB produces different amperage - 1000mA and sometimes less. How can I know the amperage?
Thanks!
Upvotes: 3
Views: 976
Reputation: 33792
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 use EXTRA_PLUGGED 0 for battery, 1 for AC and 2 for USB
Upvotes: 3
Reputation: 2250
u have to use receiver and initilize like this in android manifestfile
<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 reciver file
@Override
public void onReceive(Context context, Intent intent) {
if("android.intent.action.EXTRA_VOLTAGE".equals(intent.getAction()))
{
}
}
Upvotes: -1