Example usage for android.content IntentFilter IntentFilter

List of usage examples for android.content IntentFilter IntentFilter

Introduction

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

Prototype

public IntentFilter(Parcel source) 

Source Link

Usage

From source file:Main.java

public static void registerBackReceiver() {
    IntentFilter filter = new IntentFilter(Intent.ACTION_TIME_TICK);
    //      MyBroadcastReceiver receiver = new MyBroadcastReceiver(); 
    //      registerReceiver(receiver, filter); 
}

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

@SuppressLint("InlinedApi")
public static IntentFilter getTagFilter() {
    IntentFilter tag = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    return tag;/* www. j a  v a2s  .  c  o  m*/
}

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 Intent getBatteryStatus(Context context) {
    IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    return context.registerReceiver(null, filter);
}

From source file:Main.java

public static float getCurrentBattery(Context context) {
    Intent batteryInfoIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    int status = batteryInfoIntent.getIntExtra("status", 0);
    int health = batteryInfoIntent.getIntExtra("health", 1);
    boolean present = batteryInfoIntent.getBooleanExtra("present", false);
    int level = batteryInfoIntent.getIntExtra("level", 0);
    int scale = batteryInfoIntent.getIntExtra("scale", 0);
    int plugged = batteryInfoIntent.getIntExtra("plugged", 0);
    int voltage = batteryInfoIntent.getIntExtra("voltage", 0);
    int temperature = batteryInfoIntent.getIntExtra("temperature", 0);
    String technology = batteryInfoIntent.getStringExtra("technology");
    return level / (float) scale;
}

From source file:Main.java

public static float getCurrentBattery(Context context) {
    Intent batteryInfoIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    //      int status = batteryInfoIntent.getIntExtra( "status" , 0 ); 
    //      int health = batteryInfoIntent.getIntExtra( "health" , 1 );  
    //      boolean present = batteryInfoIntent.getBooleanExtra( "present" , false );  
    int level = batteryInfoIntent.getIntExtra("level", 0);
    int scale = batteryInfoIntent.getIntExtra("scale", 0);
    //      int plugged = batteryInfoIntent.getIntExtra( "plugged" , 0 );  
    //      int voltage = batteryInfoIntent.getIntExtra( "voltage" , 0 );  
    //      int temperature = batteryInfoIntent.getIntExtra( "temperature" , 0 );
    //      String technology = batteryInfoIntent.getStringExtra( "technology" );  
    //      Log.i("Battery: ", "status:  " + status);
    //      Log.i("Battery: ", "health: " + health);
    //      Log.i("Battery: ", "present: " + present);
    //      Log.i("Battery: ", "level: " + level);
    //      Log.i("Battery: ", "scale: " + scale);
    //      Log.i("Battery: ", "plugged: " + plugged);
    //      Log.i("Battery: ", "voltage: " + voltage);
    //      Log.i("Battery: ", "temperature: " + temperature);
    //      Log.i("Battery: ", "technology: " + technology);
    return level / (float) scale;
}

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

public static float getBatteryLevel(Context context) {
    Intent batteryIntent = context.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;
    }//w w w.  j  a  v  a2s .c o  m

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

From source file:Main.java

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