android.content.Context#moveSharedPreferencesFrom ( )源码实例Demo

下面列出了android.content.Context#moveSharedPreferencesFrom ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: security-samples   文件: AlarmStorage.java
public AlarmStorage(Context context) {
    Context storageContext;
    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);
}
 
源代码2 项目: android-DirectBoot   文件: AlarmStorage.java
public AlarmStorage(Context context) {
    Context storageContext;
    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);
}
 
源代码3 项目: WADB   文件: WadbApplication.java
public static SharedPreferences getDefaultSharedPreferences() {
    Context context= getInstance();
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
        context = getInstance().createDeviceProtectedStorageContext();
        context.moveSharedPreferencesFrom(getInstance(),getDefaultSharedPreferenceName());
    }
    return context.getSharedPreferences(getDefaultSharedPreferenceName(), Context.MODE_PRIVATE);
}
 
源代码4 项目: talkback   文件: 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.
 */
public static void migrateSharedPreferences(Context context) {
  if (BuildVersionUtils.isAtLeastN()) {
    Context deContext = ContextCompat.createDeviceProtectedStorageContext(context);
    deContext.moveSharedPreferencesFrom(
        context, PreferenceManager.getDefaultSharedPreferencesName(context));
  }
}
 
 方法所在类
 同类方法