Android Battery in Sdk

Android Battery in SDK

You can register an Intent receiver to receive the broadcast for ACTION_BATTERY_CHANGED: http://developer.android.com/reference/android/content/Intent.html#ACTION_BATTERY_CHANGED. The docs say that the broadcast is sticky, so you'll be able to grab it even after the moment the battery state change occurs.

Android: Battery usage of each application

Other than the battery usage screen in Settings, there is no API or command-line way to get this information.

Capture SDK request battery level not working

Ok, after talking to support at Socket Mobile a software engineer informed me how the battery level information was packed into the property response. Here it is...now it's just a matter of formatting it for display!

Code:    int value = property.getInt();    int current = value >>> 8 & 0xFF;    int min = value >>> 16 & 0xFF;    int max = value >>> 24 & 0xFF;    Double batteryPercent = current * 100.0 / (max - min);

Get battery level only once using Android SDK

The Intent.ACTION_BATTERY_CHANGED broadcast is what's known as a "sticky broadcast." Because this is sticky, you can register for the broadcast with a null receiver which will only get the battery level one time when you call registerReceiver.

A function to get the battery level without receiving updates would look something like this:

public float getBatteryLevel() {
Intent batteryIntent = registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);

// Error checking that probably isn't needed but I added just in case.
if(level == -1 || scale == -1) {
return 50.0f;
}

return ((float)level / (float)scale) * 100.0f;
}

More data can be pulled from this sticky broadcast. Using the returned batteryIntent you can access other extras as outlined in the BatteryManager class.

How to check battery saver is on in android API 21

Hmm.This is check high acurary mode in GPS. This is check:

   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
try {
if (getLocationMode(getApplicationContext()) != 3) {
tvmessage.setText("Please turn on GPS high Acurary");
btcancel_Dialog.setText("OK");
btcancel_Dialog.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
dlg.dismiss();
}
});
dlg.show();
} else {

Intent intentvitri = new Intent(customer_textReport.this, CustomerGetLocation.class);
startActivityForResult(intentvitri, 111);
}
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}
}

and method getLocationMode return mode of GPS:

 private int getLocationMode(Context context) throws Settings.SettingNotFoundException {
return Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);

}


Related Topics



Leave a reply



Submit