Example usage for android.content Intent getIntExtra

List of usage examples for android.content Intent getIntExtra

Introduction

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

Prototype

public int getIntExtra(String name, int defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:Main.java

/**
 * Gets the app id.//from  w ww .j a va2s .  c  o  m
 * 
 * @param intent
 *            the intent
 * 
 * @return the app id
 */
public static int getAppId(Intent intent) {
    return intent.getIntExtra(GAME_APP_ID_KEY, 0);
}

From source file:Main.java

/**
 * Gets the session id./*w  w w  . j av a 2s . c o  m*/
 * 
 * @param intent
 *            the intent
 * 
 * @return the session id
 */
public static int getSessionId(Intent intent) {
    return intent.getIntExtra(SESSION_ID_KEY, -1);
}

From source file:Main.java

public static boolean isCharging(Context context) {
    Intent batteryStatus = getBatteryStatus(context);
    int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
    return status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL;
}

From source file:Main.java

public static int getBatteryLevel(Context context) {
    IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    Intent batteryStatus = context.registerReceiver(null, ifilter);
    return batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
}

From source file:Main.java

public static String getBatteryLevel(Context context) {
    IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    Intent status = context.registerReceiver(null, intentFilter);
    int level = status.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
    return String.valueOf(level);
}

From source file:Main.java

private static Boolean isCharging(Context context) {
    IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    Intent batteryStatus = context.registerReceiver(null, ifilter);
    int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);

    return status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL;
}

From source file:Main.java

/**
 * @return the id of the field in which the result to be filled. Or, {@code -1} for error.
 *//*from   w w  w.j a  v a  2  s.c  o  m*/
public static int getFieldId(Intent intent) {
    if (intent == null) {
        return -1;
    }
    return intent.getIntExtra(FIELD_ID, -1);
}

From source file:Main.java

/**
 * return between 0 and 1./*from ww w  .j a v a  2 s.co m*/
 */
public static float level(final Context context) {
    final IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    final Intent batteryStatus = context.registerReceiver(null, ifilter);
    final int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
    final int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
    return level / (float) scale;
}

From source file:Main.java

public static boolean isCharging(Context context) {
    IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    Intent batteryStatus = context.registerReceiver(null, ifilter);

    int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
    return status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL;
}

From source file:Main.java

public static boolean isCharging(Context context) {
    IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    Intent batteryStatus = context.registerReceiver(null, filter);
    int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
    boolean usbCharge = (chargePlug == BatteryManager.BATTERY_PLUGGED_USB);
    boolean acCharge = (chargePlug == BatteryManager.BATTERY_PLUGGED_AC);
    boolean wirelessCharge = false;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        wirelessCharge = (chargePlug == BatteryManager.BATTERY_PLUGGED_WIRELESS);
    }//from   w  w w  . j  ava2s  .c o  m
    return (usbCharge || acCharge || wirelessCharge);
}