Example usage for android.content SharedPreferences contains

List of usage examples for android.content SharedPreferences contains

Introduction

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

Prototype

boolean contains(String key);

Source Link

Document

Checks whether the preferences contains a preference.

Usage

From source file:Main.java

public static boolean isExist(Context mContext, String name, String key) {
    SharedPreferences sharedPreferences = mContext.getSharedPreferences(name, Context.MODE_PRIVATE);
    return sharedPreferences.contains(key);
}

From source file:Main.java

public static boolean needsMigration(Context context) {
    try {/*from   w  w  w .j ava  2s  .c om*/
        int currentVersion = context.getPackageManager().getPackageInfo(context.getPackageName(),
                0).versionCode;
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);

        return !preferences.contains("migration_" + currentVersion);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return false;
}

From source file:org.oscim.android.MapActivity.java

private static boolean containsViewport(SharedPreferences sharedPreferences) {
    return sharedPreferences.contains(KEY_LATITUDE) && sharedPreferences.contains(KEY_LONGITUDE)
            && sharedPreferences.contains(KEY_MAP_SCALE);
}

From source file:org.catnut.plugin.fantasy.Photo.java

public static boolean shouldRefresh() {
    CatnutApp app = CatnutApp.getTingtingApp();
    SharedPreferences pref = app.getPreferences();
    return !pref.contains(app.getString(R.string.pref_first_run)) ? true
            : pref.getBoolean(app.getString(R.string.pref_enable_fantasy),
                    app.getResources().getBoolean(R.bool.default_plugin_status))
                    && System.currentTimeMillis() - pref.getLong(LAST_FANTASY_MILLIS, 0) > DateTime.DAY_MILLIS;
}

From source file:Main.java

public static boolean isInstalled(Context ctx, String packageName) {
    SharedPreferences sp = ctx.getSharedPreferences(DIGG_PREFERENCES, Context.MODE_PRIVATE);
    if (sp.contains(packageName)) {
        return true;
    } else {//from  w w w  .  j av a2  s.com
        PackageManager pm = ctx.getPackageManager();
        try {
            pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
            sp.edit().putInt(packageName, 1).commit();
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}

From source file:Main.java

/**
 * Checks if the key is already saved in the preferences
 *
 * @param context the context//from  w  w w.  j  a  v a  2 s .  com
 * @param keyId   the key id
 * @return true if found
 */
public static boolean containsKey(Context context, @StringRes int keyId) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    return sharedPreferences.contains(getKey(context, keyId));
}

From source file:Main.java

public static void updateConfig(Context context) {
    SharedPreferences sp = getSP(context);
    SharedPreferences.Editor editor = sp.edit();
    PackageManager pm = context.getPackageManager();

    if (!sp.contains(APP_ACTIVE_TIME)) {
        editor.putLong(APP_ACTIVE_TIME, System.currentTimeMillis());
        editor.putBoolean(APP_IS_UPDATE, false);
    } else {//from  www.j av a  2s.com
        editor.putBoolean(APP_IS_UPDATE, true);
    }

    try {
        PackageInfo info = pm.getPackageInfo(context.getPackageName(), 0);
        String versionName = info.versionName;
        editor.putString(APP_LAST_VERSION, versionName);
    } catch (PackageManager.NameNotFoundException e) {
    }

    editor.apply();
}

From source file:com.cloudmine.api.DeviceIdentifier.java

/**
 * Retrieves the unique id for this application and device from the preferences. If this is the
 * first time the application has been run, a new unique id will be generated and saved in the
 * preferences//w  w  w .  ja v  a2  s. c o m
 * @param context the application context, accessable from an activity this.getApplicationContext()
 */
public static void initialize(Context context) {
    //Not related to BaseDeviceIdentifier but we need to do the DI somewhere and this is as good as any
    LibrarySpecificClassCreator.setCreator(new LibrarySpecificClassCreator(new AndroidBase64Encoder(),
            new AndroidHeaderFactory(), new AndroidAsynchronousHttpClient()));
    //                new VolleyAsynchronousHttpClient(context.getApplicationContext())));
    //Deserialize all geopoints as locally savable objects
    ClassNameRegistry.register(CMGeoPointInterface.GEOPOINT_CLASS, LocallySavableCMGeoPoint.class);
    ClassNameRegistry.register(JavaCMUser.CLASS_NAME, com.cloudmine.api.CMUser.class);
    SharedPreferences preferences = context.getSharedPreferences("CLOUDMINE_PREFERENCES", Context.MODE_PRIVATE);
    boolean isNotSet = !preferences.contains(UNIQUE_ID_KEY);
    if (isNotSet) {
        String uniqueId = generateUniqueDeviceIdentifier();
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(UNIQUE_ID_KEY, uniqueId);
        editor.commit();
    }
    uniqueId = preferences.getString(UNIQUE_ID_KEY, null); //null here so if we aren't getting the unique key, we fail hard
    if (uniqueId == null) {
        throw new RuntimeException("Unable to get unique id");
    } else {
        Log.e("CloudMine", "set unique id to " + uniqueId);
    }
}

From source file:com.halseyburgund.rwframework.util.RWSharedPrefsHelper.java

/**
 * Removes the data with the specified key from the indicated shared
 * preferences.//  w w  w  . j  a  va2 s  .  c om
 * 
 * @param context to be used to access shared preferences
 * @param preferencesName of shared preferences to be used
 * @param key for data to be deleted
 */
public static void remove(Context context, String preferencesName, String key) {
    SharedPreferences settings = context.getSharedPreferences(preferencesName, Context.MODE_PRIVATE);
    if (settings.contains(RWSharedPrefsHelper.PREFIX + key)) {
        SharedPreferences.Editor editor = settings.edit();
        editor.remove(RWSharedPrefsHelper.PREFIX + key);
        editor.commit();
    }
}

From source file:Main.java

/**
 * Returns the cached key for this device. Device keys are stored in SharedPreferences and are
 * used to track devices. Returns null if no device key was cached.
 *
 * @param username          REQUIRED: The current user.
 * @param userPoolId        REQUIRED: Client ID of the application.
 * @param context           REQUIRED: Application context.
 * @return device key as String, null if the device-key is not available.
 *///from   w w  w  . j ava 2  s .c  om
public static String getDeviceKey(String username, String userPoolId, Context context) {
    try {
        SharedPreferences cipCachedDeviceDetails = context
                .getSharedPreferences(getDeviceDetailsCacheForUser(username, userPoolId), 0);
        if (cipCachedDeviceDetails != null && cipCachedDeviceDetails.contains(COGNITO_DEVICE_KEY)) {
            return cipCachedDeviceDetails.getString(COGNITO_DEVICE_KEY, null);
        }
    } catch (Exception e) {
        Log.e(TAG, "Error accessing SharedPreferences" + e.getMessage());
    }
    return null;
}