Example usage for android.content Intent ACTION_BATTERY_CHANGED

List of usage examples for android.content Intent ACTION_BATTERY_CHANGED

Introduction

In this page you can find the example usage for android.content Intent ACTION_BATTERY_CHANGED.

Prototype

String ACTION_BATTERY_CHANGED

To view the source code for android.content Intent ACTION_BATTERY_CHANGED.

Click Source Link

Document

Broadcast Action: This is a sticky broadcast containing the charging state, level, and other information about the battery.

Usage

From source file:com.nbplus.iotapp.bluetooth.BluetoothLeService.java

/**
 * Called by the system when the service is first created.  Do not call this method directly.
 *///from  w  w w.j a  v a2s.c om
@Override
public void onCreate() {
    super.onCreate();
    mIsBatteryPlugged = DeviceUtils.isPlugged(this);
    Log.d(TAG, "onCreate() battery plugged = " + mIsBatteryPlugged);

    IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    registerReceiver(mBroadcastReceiver, filter);
}

From source file:com.mobicage.rogerthat.MainService.java

public boolean isBatteryPowered() {
    boolean plugged = false;
    Intent intent = registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    if (intent != null) {
        Bundle extras = intent.getExtras();
        if ((extras != null) && (extras.containsKey("plugged"))) {
            int status = extras.getInt("plugged");
            plugged = status == BatteryManager.BATTERY_PLUGGED_AC
                    || status == BatteryManager.BATTERY_PLUGGED_USB;
        }/*from  ww w.  ja v a2s .co m*/
    }
    return !plugged;
}

From source file:org.restcomm.app.qoslib.Services.Intents.IntentHandler.java

public IntentFilter declareIntentFilters() {
    IntentFilter intentFilter = new IntentFilter(IntentHandler.UPDATE_ACTION);
    intentFilter.addAction(IntentHandler.START_TRACKING_ACTION);
    intentFilter.addAction(IntentHandler.TRACK_REMOTE);
    intentFilter.addAction(IntentHandler.STOP_TRACKING_ACTION);
    intentFilter.addAction(IntentHandler.SPEED_TEST);
    intentFilter.addAction(IntentHandler.RUN_WEBSOCKET);
    intentFilter.addAction(CommonIntentActionsOld.ACTION_START_UI);

    intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_UPDATE);
    intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_LOCATION_UPDATE);
    intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_CELL_UPDATE);
    intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_GPS_STATUS_UPDATE);
    intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_SIGNAL_STRENGTH_UPDATE);
    intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_EVENT_UPDATE);
    intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_NEIGHBOR_UPDATE);
    intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_NETWORK_UPDATE);
    //intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_RX_TX);

    intentFilter.addAction(IntentHandler.ACTION_SPEEDTEST_RESULT);
    intentFilter.addAction(IntentHandler.ACTION_SPEEDTEST_ERROR);
    intentFilter.addAction(IntentHandler.ACTION_SPEEDTEST_COMPLETE);
    intentFilter.addAction(IntentHandler.ACTION_SPEEDTEST_CANCELLED);

    intentFilter.addAction(IntentHandler.ACTION_WEBTEST_RESULT);
    intentFilter.addAction(IntentHandler.ACTION_WEBTEST_ERROR);
    intentFilter.addAction(IntentHandler.ACTION_WEBTEST_COMPLETE);
    intentFilter.addAction(IntentHandler.ACTION_WEBTEST_CANCELLED);

    //do not add filter if sms test permissions aren't all allowed
    if (PreferenceKeys.getSMSPermissionsAllowed(owner, true))
        intentFilter.addAction(IntentHandler.SMS_TEST);

    intentFilter.addAction(IntentHandler.SMS_DELIVERED);
    intentFilter.addAction(IntentHandler.LATENCY_TEST);
    intentFilter.addAction(IntentHandler.ACTION_STOP_SPEEDTEST);
    intentFilter.addAction(IntentHandler.RESTART_MMC_SERVICE);
    intentFilter.addAction(IntentHandler.COLDRESET_ACTION);
    intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
    intentFilter.addAction(Intent.ACTION_POWER_CONNECTED);
    intentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED);
    intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
    intentFilter.addAction(Intent.ACTION_SCREEN_ON);
    intentFilter.addAction(IntentHandler.COMMAND);
    intentFilter.addAction(IntentHandler.SURVEY);
    //intentFilter.addAction(Intent.ACTION_VIEW);
    //intentFilter.addAction("android.intent.PHONE_STATE");
    intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    intentFilter.addAction(IntentHandler.ACTION_ALARM_MINUTE);
    intentFilter.addAction(IntentHandler.ACTION_TRACKING_5MINUTE);
    intentFilter.addAction(IntentHandler.ACTION_TRACKING_1MINUTE);
    intentFilter.addAction(IntentHandler.ACTION_ALARM_3HOUR);
    intentFilter.addAction(IntentHandler.ACTION_ALARM_15MINUTE);
    intentFilter.addAction(IntentHandler.ACTION_ALARM_SCANAPPS);
    intentFilter.addAction(IntentHandler.EMAIL_CSV);
    intentFilter.addAction(IntentHandler.GPS_STATE_OFF);
    intentFilter.addAction(IntentHandler.GPS_STATE_ON);
    intentFilter.addAction(IntentHandler.PHONE_CALL_CONNECT);
    intentFilter.addAction(IntentHandler.PHONE_CALL_DISCONNECT);
    intentFilter.addAction(IntentHandler.HANDOFF);
    //intentFilter.addAction(IntentHandler.SMS_SENT);
    intentFilter.addAction(IntentHandler.SMS_RECEIVED);
    intentFilter.addAction(Intent.ACTION_SEND);
    intentFilter.addAction(IntentHandler.MANUAL_PLOTTING_START);
    intentFilter.addAction(IntentHandler.MANUAL_PLOTTING_END);
    intentFilter.addAction(IntentHandler.MANUAL_PLOTTING_CANCEL);
    intentFilter.addAction(IntentHandler.MANUAL_TRANSIT_START);
    intentFilter.addAction(IntentHandler.MANUAL_TRANSIT_END);
    intentFilter.addAction(IntentHandler.MANUAL_TRANSIT_CANCEL);
    intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
    intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED);
    intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);

    intentFilter.addAction(Intent.ACTION_HEADSET_PLUG);
    intentFilter.addAction(IntentHandler.ROAMING_ON);
    intentFilter.addAction(IntentHandler.ROAMING_OFF);

    intentFilter.addAction(IntentHandler.VIEWING_SIGNAL);
    intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    intentFilter.addAction("android.intent.action.PRECISE_CALL_STATE");
    intentFilter.addAction("android.intent.action.PRECISE_DATA_CONNECTION_STATE_CHANGED");
    intentFilter.addAction("android.intent.action.PHONE_STATE");
    intentFilter.addAction("android.intent.action.NEW_OUTGOING_CALL");

    intentFilter.addAction("android.intent.action.DATA_CONNECTION_CONNECTED_TO_PROVISIONING_APN");
    intentFilter.addAction("android.intent.action.ANY_DATA_STATE");
    intentFilter.addAction("android.intent.action.ACTION_DATA_CONNECTION_FAILED");

    intentFilter.addAction(CommonIntentActionsOld.ACTION_BLUETOOTH_ENDDOWNLOAD);
    intentFilter.addAction(CommonIntentActionsOld.ACTION_START_VOICETEST);
    intentFilter.addAction(CommonIntentActionsOld.ACTION_STOP_VOICETEST);
    intentFilter.addAction(CommonIntentActionsOld.ACTION_TEST_VQ_DEVICE);

    intentFilter.addAction(IntentHandler.ACTIVE_TEST);
    intentFilter.addAction(IntentHandler.ACTION_STOP_VIDEOTEST);
    intentFilter.addAction(IntentHandler.GCM_MESSAGE);

    intentFilter.addAction("org.restcomm.android.CONNECT_FAILED");
    intentFilter.addAction("org.restcomm.android.CALL_STATE");
    intentFilter.addAction("org.restcomm.android.DISCONNECT_ERROR");

    intentFilter.addAction(IntentHandler.ACTION_RADIOLOG_DISCONNECT);
    intentFilter.addAction(IntentHandler.ACTION_RADIOLOG_CONNECT);
    intentFilter.addAction(IntentHandler.ACTION_RADIOLOG_NEIGHBORS);
    intentFilter.addAction(IntentHandler.ACTION_RADIOLOG_SERVICEMODE);
    intentFilter.addAction(IntentHandler.ACTION_RADIOLOG_SERVICEMENU);
    intentFilter.addAction(IntentHandler.ACTION_MMCSYS_VERSION);

    //intentFilter.addAction(Intent.ACTION_APP_ERROR);
    int raisePriority = owner.getPackageManager().checkPermission("android.permission.RAISED_THREAD_PRIORITY",
            owner.getPackageName());//  ww  w  .  j  a va2  s .c o m
    // With permission to raise priority for SMS messages
    if (raisePriority == 0)
        intentFilter.setPriority(9999999);

    return intentFilter;
}

From source file:ua.mkh.weather.MainActivity.java

protected void onResume() {
    super.onResume();

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

    IntentFilter filtertime = new IntentFilter();
    filtertime.addAction("android.intent.action.TIME_TICK");
    registerReceiver(mTimeInfoReceiver, filtertime);

    String weather = mSettings.getString(APP_PREFERENCES_WEATHER, "Clear");
    if (weather.contains("light_rain")) {
        img1.setImageDrawable(getResources().getDrawable(R.drawable.light_rain_d));
    } else if (weather.contains("moderate rain")) {
        img1.setImageDrawable(getResources().getDrawable(R.drawable.moderate_rain_d));
    } else if (weather.contains("heavy_intensity_rain")) {
        img1.setImageDrawable(getResources().getDrawable(R.drawable.heavy_intensity_rain_d));
    } else if (weather.contains("few_clouds")) {
        img1.setImageDrawable(getResources().getDrawable(R.drawable.few_clouds_d));
    } else if (weather.contains("scattered_clouds")) {
        img1.setImageDrawable(getResources().getDrawable(R.drawable.scattered_clouds_d));
    } else if (weather.contains("broken_clouds")) {
        img1.setImageDrawable(getResources().getDrawable(R.drawable.broken_clouds_d));
    } else if (weather.contains("Clear")) {
        img1.setImageDrawable(getResources().getDrawable(R.drawable.clear_sky_d));
    } else if (weather.contains("Snow")) {
        img1.setImageDrawable(getResources().getDrawable(R.drawable.snow_d));
    } else if (weather.contains("Thunderstorm")) {
        img1.setImageDrawable(getResources().getDrawable(R.drawable.thunderstorm));
    } else if (weather.contains("Drizzle")) {
        img1.setImageDrawable(getResources().getDrawable(R.drawable.light_rain_d));
    } else if (weather.contains("Atmosphere")) {
        img1.setImageDrawable(getResources().getDrawable(R.drawable.few_clouds_d));
    } else if (weather.contains("Extreme")) {
        img1.setImageDrawable(getResources().getDrawable(R.drawable.thunderstorm));
    } else if (weather.contains("Additional")) {
        img1.setImageDrawable(getResources().getDrawable(R.drawable.clear_sky_d));
    }/*ww w  .  jav  a2s  .  c o  m*/

    String city = mSettings.getString(APP_PREFERENCES_CITY, "2172797");
    //city = city.replace(" ","_");
    //Log.i("", city);

    //String adress = mSettings.getString(APP_PREFERENCES_ADRESS, "q");
    //Log.d("", adress);

    String locale = Locale.getDefault().getLanguage();

    String temp = mSettings.getString(APP_PREFERENCES_TEMP, "c");

    if (temp.contains("c")) {
        temp_n = "&units=metric";
    } else {
        temp_n = "&units=imperial";
    }

    if (locale.contains("ru")) {
        url_forecast = "http://api.openweathermap.org/data/2.5/forecast/daily?mode=json&id=" + city + temp_n
                + "&lang=ru&APPID=0e9e2449bc7a756fad899235dfae7206";
        url_base = "http://api.openweathermap.org/data/2.5/weather?id=" + city + temp_n
                + "&lang=ru&APPID=0e9e2449bc7a756fad899235dfae7206";
        url_daily = "http://api.openweathermap.org/data/2.5/forecast?id=" + city + temp_n
                + "&lang=ru&APPID=0e9e2449bc7a756fad899235dfae7206";

    } else if (locale.contains("uk")) {
        url_forecast = "http://api.openweathermap.org/data/2.5/forecast/daily?mode=json&id=" + city + temp_n
                + "&lang=ua&APPID=0e9e2449bc7a756fad899235dfae7206";
        url_base = "http://api.openweathermap.org/data/2.5/weather?id=" + city + temp_n
                + "&lang=ua&APPID=0e9e2449bc7a756fad899235dfae7206";
        url_daily = "http://api.openweathermap.org/data/2.5/forecast?id=" + city + temp_n
                + "&lang=ua&APPID=0e9e2449bc7a756fad899235dfae7206";

    } else {
        url_forecast = "http://api.openweathermap.org/data/2.5/forecast/daily?mode=json&id=" + city + temp_n
                + "&APPID=0e9e2449bc7a756fad899235dfae7206";
        url_base = "http://api.openweathermap.org/data/2.5/weather?id=" + city + temp_n
                + "&APPID=0e9e2449bc7a756fad899235dfae7206";
        url_daily = "http://api.openweathermap.org/data/2.5/forecast?id=" + city + temp_n
                + "&APPID=0e9e2449bc7a756fad899235dfae7206";

    }

    check_int();

    top_bar();

}

From source file:org.mozilla.gecko.GeckoApp.java

private void initialize() {
    mInitialized = true;// w  w  w . j  a va2 s  . c  o  m

    Intent intent = getIntent();
    String args = intent.getStringExtra("args");
    if (args != null && args.contains("-profile")) {
        Pattern p = Pattern.compile("(?:-profile\\s*)(\\w*)(\\s*)");
        Matcher m = p.matcher(args);
        if (m.find()) {
            mProfile = GeckoProfile.get(this, m.group(1));
            mLastTitle = null;
            mLastViewport = null;
            mLastScreen = null;
        }
    }

    if (ACTION_UPDATE.equals(intent.getAction()) || args != null && args.contains("-alert update-app")) {
        Log.i(LOGTAG, "onCreate: Update request");
        checkAndLaunchUpdate();
    }

    mBrowserToolbar.init();
    mBrowserToolbar.setTitle(mLastTitle);

    String passedUri = null;
    String uri = getURIFromIntent(intent);
    if (uri != null && uri.length() > 0)
        passedUri = mLastTitle = uri;

    if (passedUri == null || passedUri.equals("about:home")) {
        // show about:home if we aren't restoring previous session
        if (!getProfile().hasSession()) {
            mBrowserToolbar.updateTabCount(1);
            showAboutHome();
        }
    } else {
        mBrowserToolbar.updateTabCount(1);
    }

    if (sGREDir == null)
        sGREDir = new File(this.getApplicationInfo().dataDir);

    Uri data = intent.getData();
    if (data != null && "http".equals(data.getScheme()) && isHostOnPrefetchWhitelist(data.getHost())) {
        Intent copy = new Intent(intent);
        copy.setAction(ACTION_LOAD);
        GeckoAppShell.getHandler().post(new RedirectorRunnable(copy));
        // We're going to handle this uri with the redirector, so setting
        // the action to MAIN and clearing the uri data prevents us from
        // loading it twice
        intent.setAction(Intent.ACTION_MAIN);
        intent.setData(null);
        passedUri = null;
    }

    sGeckoThread = new GeckoThread(intent, passedUri, mRestoreSession);
    if (!ACTION_DEBUG.equals(intent.getAction())
            && checkAndSetLaunchState(LaunchState.Launching, LaunchState.Launched))
        sGeckoThread.start();

    mFavicons = new Favicons(this);

    Tabs.getInstance().setContentResolver(getContentResolver());

    if (cameraView == null) {
        cameraView = new SurfaceView(this);
        cameraView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    if (mLayerController == null) {
        /*
         * Create a layer client so that Gecko will have a buffer to draw into, but don't hook
         * it up to the layer controller yet.
         */
        mSoftwareLayerClient = new GeckoSoftwareLayerClient(this);

        /*
         * Hook a placeholder layer client up to the layer controller so that the user can pan
         * and zoom a cached screenshot of the previous page. This call will return null if
         * there is no cached screenshot; in that case, we have no choice but to display a
         * checkerboard.
         *
         * TODO: Fall back to a built-in screenshot of the Fennec Start page for a nice first-
         * run experience, perhaps?
         */
        mLayerController = new LayerController(this);
        mPlaceholderLayerClient = PlaceholderLayerClient.createInstance(this);
        mLayerController.setLayerClient(mPlaceholderLayerClient);

        mGeckoLayout.addView(mLayerController.getView(), 0);
    }

    mPluginContainer = (AbsoluteLayout) findViewById(R.id.plugin_container);

    mDoorHangerPopup = new DoorHangerPopup(this);
    mAutoCompletePopup = (AutoCompletePopup) findViewById(R.id.autocomplete_popup);

    Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - UI almost up");

    if (!sTryCatchAttached) {
        sTryCatchAttached = true;
        mMainHandler.post(new Runnable() {
            public void run() {
                try {
                    Looper.loop();
                } catch (Exception e) {
                    GeckoAppShell.reportJavaCrash(e);
                }
                // resetting this is kinda pointless, but oh well
                sTryCatchAttached = false;
            }
        });
    }

    //register for events
    GeckoAppShell.registerGeckoEventListener("DOMContentLoaded", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("DOMTitleChanged", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("DOMLinkAdded", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("DOMWindowClose", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("log", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Content:LocationChange", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Content:SecurityChange", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Content:StateChange", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Content:LoadError", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("onCameraCapture", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Doorhanger:Add", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Doorhanger:Remove", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Menu:Add", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Menu:Remove", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Gecko:Ready", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Toast:Show", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("DOMFullScreen:Start", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("DOMFullScreen:Stop", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("ToggleChrome:Hide", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("ToggleChrome:Show", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("FormAssist:AutoComplete", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Permissions:Data", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Downloads:Done", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("CharEncoding:Data", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("CharEncoding:State", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Update:Restart", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Tab:HasTouchListener", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Session:StatePurged", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Bookmark:Insert", GeckoApp.mAppContext);

    IntentFilter batteryFilter = new IntentFilter();
    batteryFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
    mBatteryReceiver = new GeckoBatteryManager();
    registerReceiver(mBatteryReceiver, batteryFilter);

    if (SmsManager.getInstance() != null) {
        SmsManager.getInstance().start();
    }

    GeckoNetworkManager.getInstance().init();

    final GeckoApp self = this;

    GeckoAppShell.getHandler().postDelayed(new Runnable() {
        public void run() {
            Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - pre checkLaunchState");

            /*
              XXXX see bug 635342
               We want to disable this code if possible.  It is about 145ms in runtime
            SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE);
            String localeCode = settings.getString(getPackageName() + ".locale", "");
            if (localeCode != null && localeCode.length() > 0)
            GeckoAppShell.setSelectedLocale(localeCode);
            */

            if (!checkLaunchState(LaunchState.Launched)) {
                return;
            }

            checkMigrateProfile();
        }
    }, 50);
}

From source file:saphion.services.ForegroundService.java

public int readbattery() {
    Intent batteryIntent = getApplicationContext().registerReceiver(null,
            new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

    int rawlevel = batteryIntent.getIntExtra("level", -1);
    double scale = batteryIntent.getIntExtra("scale", -1);
    int plugged = batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
    isconnected = (plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB
            || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS);
    level = -1;/*from  w  w w . j ava  2s .  c  o  m*/
    if (rawlevel >= 0 && scale > 0) {
        level = (int) ((rawlevel * 100) / scale);
        Log.d("rawLevel: " + rawlevel);
        Log.d("scale: " + scale);
    }

    temperature = Functions.updateTemperature(
            (float) ((float) (batteryIntent.getIntExtra("temperature", 0)) / 10),
            mPref.getBoolean(PreferenceHelper.MAIN_TEMP, true), true);

    int inthealth = batteryIntent.getIntExtra(BatteryManager.EXTRA_HEALTH, 0);
    health = "";
    switch (inthealth) {
    case BatteryManager.BATTERY_HEALTH_COLD:
        health = "Cold";
        break;
    case BatteryManager.BATTERY_HEALTH_DEAD:
        health = "Dead";
        break;
    case BatteryManager.BATTERY_HEALTH_GOOD:
        health = "Good";
        break;
    case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
        health = "Over Voltage";
        break;
    case BatteryManager.BATTERY_HEALTH_OVERHEAT:
        health = "Overheat";
        break;
    case BatteryManager.BATTERY_HEALTH_UNKNOWN:
        health = "Unknown";
        break;
    case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
        health = "Unspecified failure";
        break;
    }

    if (mPref.getBoolean(PreferenceHelper.KEY_ONE_PERCENT_HACK, false)) {
        try {
            java.io.FileReader fReader = new java.io.FileReader(
                    "/sys/class/power_supply/battery/charge_counter");
            java.io.BufferedReader bReader = new java.io.BufferedReader(fReader);
            int charge_counter = Integer.valueOf(bReader.readLine());
            bReader.close();

            if (charge_counter > PreferenceHelper.CHARGE_COUNTER_LEGIT_MAX) {
                disableOnePercentHack("charge_counter is too big to be actual charge");
            } else {
                if (charge_counter > 100)
                    charge_counter = 100;

                level = charge_counter;
            }
        } catch (java.io.FileNotFoundException e) {
            /*
             * These error messages are only really useful to me and might
             * as well be left hardwired here in English.
             */
            disableOnePercentHack("charge_counter file doesn't exist");
        } catch (java.io.IOException e) {
            disableOnePercentHack("Error reading charge_counter file");
        }
    }

    return level;
}

From source file:org.mariotaku.twidere.util.Utils.java

public static boolean isBatteryOkay(final Context context) {
    if (context == null)
        return false;
    final Context app = context.getApplicationContext();
    final IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    final Intent intent = app.registerReceiver(null, filter);
    if (intent == null)
        return false;
    final boolean plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) > 0;
    final float level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
    final float scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100);
    return plugged || level / scale > 0.15f;
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static boolean isBatteryOkay(final Context context) {
    if (context == null)
        return false;
    final Context app = context.getApplicationContext();
    final IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    final Intent intent = app.registerReceiver(null, filter);
    if (intent == null)
        return false;
    final boolean plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0;
    final float level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
    final float scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100);
    return plugged || level / scale > 0.15f;
}