Example usage for android.preference PreferenceManager getDefaultSharedPreferencesName

List of usage examples for android.preference PreferenceManager getDefaultSharedPreferencesName

Introduction

In this page you can find the example usage for android.preference PreferenceManager getDefaultSharedPreferencesName.

Prototype

public static String getDefaultSharedPreferencesName(Context context) 

Source Link

Document

Returns the name used for storing default shared preferences.

Usage

From source file:com.android.utils.SharedPreferencesUtils.java

/**
 * Move existing preferences file from credential protected storage to device protected storage.
 * This is used to migrate data between storage locations after an Android upgrade from
 * Build.VERSION < N to Build.VERSION >= N.
 *//*from  w  w  w . java  2  s .c  o m*/
public static void migrateSharedPreferences(Context context) {
    if (BuildCompat.isAtLeastN()) {
        Context deContext = ContextCompat.createDeviceProtectedStorageContext(context);
        deContext.moveSharedPreferencesFrom(context,
                PreferenceManager.getDefaultSharedPreferencesName(context));
    }
}

From source file:com.stasbar.knowyourself.Utils.java

/**
 * Returns the default {@link SharedPreferences} instance from the underlying storage context.
 *//* ww  w .  jav a 2s.c o m*/
@TargetApi(Build.VERSION_CODES.N)
public static SharedPreferences getDefaultSharedPreferences(Context context) {
    final Context storageContext;
    if (isNOrLater()) {
        // All N devices have split storage areas, but we may need to
        // migrate existing preferences into the new device encrypted
        // storage area, which is where our data lives from now on.
        storageContext = context.createDeviceProtectedStorageContext();
        if (!storageContext.moveSharedPreferencesFrom(context,
                PreferenceManager.getDefaultSharedPreferencesName(context))) {
            LogUtils.wtf("Failed to migrate shared preferences");
        }
    } else {
        storageContext = context;
    }

    return PreferenceManager.getDefaultSharedPreferences(storageContext);
}

From source file:com.android.deskclock.Utils.java

/**
 * Return the default shared preferences.
 *///  w w  w. ja v  a  2 s.  c  o m
public static SharedPreferences getDefaultSharedPreferences(Context context) {
    final Context storageContext;
    if (isNOrLater()) {
        // All N devices have split storage areas, but we may need to
        // migrate existing preferences into the new device protected
        // storage area, which is where our data lives from now on.
        final Context deviceContext = context.createDeviceProtectedStorageContext();
        if (!deviceContext.moveSharedPreferencesFrom(context,
                PreferenceManager.getDefaultSharedPreferencesName(context))) {
            LogUtils.wtf("Failed to migrate shared preferences");
        }
        storageContext = deviceContext;
    } else {
        storageContext = context;
    }

    return PreferenceManager.getDefaultSharedPreferences(storageContext);
}