List of usage examples for android.content Context createDeviceProtectedStorageContext
public abstract Context createDeviceProtectedStorageContext();
From source file:com.stasbar.knowyourself.Utils.java
/** * Returns the default {@link SharedPreferences} instance from the underlying storage context. *///from ww w. j a v a 2 s.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. *//*from w w w .ja va 2s .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); }
From source file:com.example.android.directboot.alarms.AlarmStorage.java
public AlarmStorage(Context context) { Context storageContext;// w w w .j a va 2s .co m if (BuildCompat.isAtLeastN()) { // All N devices have split storage areas, but we may need to // move the existing preferences to the new device protected // storage area, which is where the data lives from now on. final Context deviceContext = context.createDeviceProtectedStorageContext(); if (!deviceContext.moveSharedPreferencesFrom(context, ALARM_PREFERENCES_NAME)) { Log.w(TAG, "Failed to migrate shared preferences."); } storageContext = deviceContext; } else { storageContext = context; } mSharedPreferences = storageContext.getSharedPreferences(ALARM_PREFERENCES_NAME, Context.MODE_PRIVATE); }