Example usage for android.content Intent getBooleanExtra

List of usage examples for android.content Intent getBooleanExtra

Introduction

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

Prototype

public boolean getBooleanExtra(String name, boolean defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.laevatein.internal.misc.ui.FragmentUtils.java

public static boolean getIntentBooleanExtra(Fragment fragment, String key, boolean fallback) {
    Activity activity = fragment.getActivity();
    Intent intent = activity.getIntent();
    return intent.getBooleanExtra(key, fallback);
}

From source file:com.amlcurran.messages.telephony.SmsManagerOutputPort.java

private static boolean isFromWear(Intent intent) {
    return intent.getBooleanExtra(FROM_WEAR, false);
}

From source file:Main.java

public static boolean getBooleanExtra(Intent intent, String name, boolean defaultValue) {
    if (!hasIntent(intent) || !hasExtra(intent, name))
        return defaultValue;
    return intent.getBooleanExtra(name, defaultValue);
}

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:com.onesignal.NotificationOpenedProcessor.java

public static void processFromActivity(Context inContext, Intent inIntent) {
    // Pressed an action button, need to clear the notification and close the notification area manually.
    if (inIntent.getBooleanExtra("action_button", false)) {
        NotificationManagerCompat.from(inContext).cancel(inIntent.getIntExtra("notificationId", 0));
        inContext.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
    }/*from   www  . ja  va2s . c om*/

    processIntent(inContext, inIntent);
}

From source file:at.ac.uniklu.mobile.sportal.util.Utils.java

/**
 * Returns the value of the EXTRA_REFETCH_DATA flag of an intent, and removes it
 * if it is set. This flag tells an Activity if it should load the data freshly from the
 * server by invalidating the cache.//from  ww  w  . j  a v  a2 s .c o m
 */
public static boolean shouldRefetchData(Intent i) {
    boolean refetch = i.getBooleanExtra(Studentportal.EXTRA_REFETCH_DATA, false);
    if (refetch) {
        i.removeExtra(Studentportal.EXTRA_REFETCH_DATA);
    }
    return refetch;
}

From source file:com.google.ipc.invalidation.ticl.android.c2dm.C2DMObserver.java

/**
 * Creates a new observer from the extra values contained in the provided intent.
 *///from w  ww  .java  2  s  . co  m
static C2DMObserver createFromIntent(Intent intent) {
    String canonicalClassString = intent.getStringExtra(C2DMessaging.EXTRA_CANONICAL_CLASS);
    try {
        // Extract observer state from the intent built by the C2DM manager.
        Class<? extends Service> clazz = Class.forName(canonicalClassString).asSubclass(Service.class);
        String filterKey = intent.getStringExtra(C2DMessaging.EXTRA_FILTER_KEY);
        String filterValue = intent.getStringExtra(C2DMessaging.EXTRA_FILTER_VALUE);
        boolean handleWakeLock = intent.getBooleanExtra(C2DMessaging.EXTRA_HANDLE_WAKELOCK, false);
        return new C2DMObserver(clazz, filterKey, filterValue, handleWakeLock);
    } catch (ClassNotFoundException e) {
        Log.e(TAG, "Unable to register observer class " + canonicalClassString);
        return null;
    }
}

From source file:cat.ereza.customactivityoncrash.CustomActivityOnCrash.java

/**
 * Given an Intent, returns if the error details button should be displayed.
 *
 * @param intent The Intent. Must not be null.
 * @return true if the button must be shown, false otherwise.
 *//*from  www.  j  a v a2  s.c  o  m*/
public static boolean isShowErrorDetailsFromIntent(Intent intent) {
    return intent.getBooleanExtra(CustomActivityOnCrash.EXTRA_SHOW_ERROR_DETAILS, true);
}

From source file:com.fenlisproject.elf.core.framework.ElfBinder.java

public static void bindIntentExtra(Object receiver) {
    Field[] fields = receiver.getClass().getDeclaredFields();
    for (Field field : fields) {
        field.setAccessible(true);/*  w ww .  ja v  a2 s. c  o m*/
        IntentExtra intentExtra = field.getAnnotation(IntentExtra.class);
        if (intentExtra != null) {
            try {
                Intent intent = null;
                if (receiver instanceof Activity) {
                    intent = ((Activity) receiver).getIntent();
                } else if (receiver instanceof Fragment) {
                    intent = ((Fragment) receiver).getActivity().getIntent();
                }
                if (intent != null) {
                    Class<?> type = field.getType();
                    if (type == Boolean.class || type == boolean.class) {
                        field.set(receiver, intent.getBooleanExtra(intentExtra.value(), false));
                    } else if (type == Byte.class || type == byte.class) {
                        field.set(receiver, intent.getByteExtra(intentExtra.value(), (byte) 0));
                    } else if (type == Character.class || type == char.class) {
                        field.set(receiver, intent.getCharExtra(intentExtra.value(), '\u0000'));
                    } else if (type == Double.class || type == double.class) {
                        field.set(receiver, intent.getDoubleExtra(intentExtra.value(), 0.0d));
                    } else if (type == Float.class || type == float.class) {
                        field.set(receiver, intent.getFloatExtra(intentExtra.value(), 0.0f));
                    } else if (type == Integer.class || type == int.class) {
                        field.set(receiver, intent.getIntExtra(intentExtra.value(), 0));
                    } else if (type == Long.class || type == long.class) {
                        field.set(receiver, intent.getLongExtra(intentExtra.value(), 0L));
                    } else if (type == Short.class || type == short.class) {
                        field.set(receiver, intent.getShortExtra(intentExtra.value(), (short) 0));
                    } else if (type == String.class) {
                        field.set(receiver, intent.getStringExtra(intentExtra.value()));
                    } else if (type == Boolean[].class || type == boolean[].class) {
                        field.set(receiver, intent.getBooleanArrayExtra(intentExtra.value()));
                    } else if (type == Byte[].class || type == byte[].class) {
                        field.set(receiver, intent.getByteArrayExtra(intentExtra.value()));
                    } else if (type == Character[].class || type == char[].class) {
                        field.set(receiver, intent.getCharArrayExtra(intentExtra.value()));
                    } else if (type == Double[].class || type == double[].class) {
                        field.set(receiver, intent.getDoubleArrayExtra(intentExtra.value()));
                    } else if (type == Float[].class || type == float[].class) {
                        field.set(receiver, intent.getFloatArrayExtra(intentExtra.value()));
                    } else if (type == Integer[].class || type == int[].class) {
                        field.set(receiver, intent.getIntArrayExtra(intentExtra.value()));
                    } else if (type == Long[].class || type == long[].class) {
                        field.set(receiver, intent.getLongArrayExtra(intentExtra.value()));
                    } else if (type == Short[].class || type == short[].class) {
                        field.set(receiver, intent.getShortArrayExtra(intentExtra.value()));
                    } else if (type == String[].class) {
                        field.set(receiver, intent.getStringArrayExtra(intentExtra.value()));
                    } else if (Serializable.class.isAssignableFrom(type)) {
                        field.set(receiver, intent.getSerializableExtra(intentExtra.value()));
                    } else if (type == Bundle.class) {
                        field.set(receiver, intent.getBundleExtra(intentExtra.value()));
                    }
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:net.peterkuterna.android.apps.devoxxsched.service.SyncService.java

/**
 * Should we perform a remote sync?//from   w  w  w.  j a  va 2 s.  co m
 */
private static boolean performRemoteSync(ContentResolver resolver, HttpClient httpClient, Intent intent,
        Context context) {
    final SharedPreferences settingsPrefs = context.getSharedPreferences(SettingsActivity.SETTINGS_NAME,
            MODE_PRIVATE);
    final SharedPreferences syncServicePrefs = context.getSharedPreferences(SyncPrefs.DEVOXXSCHED_SYNC,
            Context.MODE_PRIVATE);
    final boolean onlySyncWifi = settingsPrefs.getBoolean(context.getString(R.string.sync_only_wifi_key),
            false);
    final int localVersion = syncServicePrefs.getInt(SyncPrefs.LOCAL_VERSION, VERSION_NONE);
    if (!onlySyncWifi || isWifiConnected(context)) {
        final boolean remoteParse = localVersion < VERSION_REMOTE;
        final boolean forceRemoteRefresh = intent.getBooleanExtra(EXTRA_FORCE_REFRESH, false);
        final boolean hasContentChanged = hasContentChanged(resolver, httpClient);
        return remoteParse || forceRemoteRefresh || hasContentChanged;
    }
    return false;
}