android.app.Application.getSharedPreferences()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(155)

本文整理了Java中android.app.Application.getSharedPreferences()方法的一些代码示例,展示了Application.getSharedPreferences()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Application.getSharedPreferences()方法的具体详情如下:
包路径:android.app.Application
类名称:Application
方法名:getSharedPreferences

Application.getSharedPreferences介绍

暂无

代码示例

代码示例来源:origin: xfumihiro/ViewInspector

@Provides @Singleton SharedPreferences provideSharedPreferences(Application app) {
 return app.getSharedPreferences("view-inspector", MODE_PRIVATE);
}

代码示例来源:origin: robolectric/robolectric

@Test
@Config(minSdk = N)
public void testMoveSharedPreferencesFrom() throws Exception {
 String PREFS = "PREFS";
 String PREF_NAME = "TOKEN_PREF";
 context
   .getSharedPreferences(PREFS, Context.MODE_PRIVATE)
   .edit()
   .putString(PREF_NAME, "token")
   .commit();
 Context dpContext = context.createDeviceProtectedStorageContext();
 assertThat(dpContext.getSharedPreferences(PREFS, Context.MODE_PRIVATE).contains(PREF_NAME))
   .isFalse();
 assertThat(context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).contains(PREF_NAME))
   .isTrue();
 assertThat(dpContext.moveSharedPreferencesFrom(context, PREFS)).isTrue();
 assertThat(dpContext.getSharedPreferences(PREFS, Context.MODE_PRIVATE).contains(PREF_NAME))
   .isTrue();
 assertThat(context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).contains(PREF_NAME))
   .isFalse();
}

代码示例来源:origin: facebook/facebook-android-sdk

@Before
public void before() throws Exception {
  FacebookSdk.setApplicationId("123456789");
  FacebookSdk.setAutoLogAppEventsEnabled(false);
  FacebookSdk.sdkInitialize(RuntimeEnvironment.application);
  RuntimeEnvironment.application.getSharedPreferences(
      ProfileCache.SHARED_PREFERENCES_NAME,
      Context.MODE_PRIVATE)
      .edit().
      clear().
      commit();
}

代码示例来源:origin: facebook/facebook-android-sdk

@Before
public void before() throws Exception {
  mockStatic(FacebookSdk.class);
  sharedPreferences = RuntimeEnvironment.application.getSharedPreferences(
      AccessTokenManager.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
  sharedPreferences.edit().clear().commit();
  cachingStrategyFactory = mock(
      AccessTokenCache.SharedPreferencesTokenCachingStrategyFactory.class);
  when(cachingStrategyFactory.create()).thenReturn(cachingStrategy);
  stub(PowerMockito.method(Utility.class, "awaitGetGraphMeRequestWithCache")).toReturn(
      new JSONObject().put("id", "1000"));
}

代码示例来源:origin: Rukey7/MvpApp

SharedPreferences sp = applicationLike.getApplication().getSharedPreferences(ShareConstants.TINKER_SHARE_PREFERENCE_CONFIG, Context.MODE_MULTI_PROCESS);
int fastCrashCount = sp.getInt(currentVersion, 0) + 1;
if (fastCrashCount >= MAX_CRASH_COUNT) {

代码示例来源:origin: hidroh/materialistic

@Test
  public void testRefreshQuery() {
    RuntimeEnvironment.application.getSharedPreferences("WidgetConfiguration_" + appWidgetId, MODE_PRIVATE)
        .edit()
        .putString(RuntimeEnvironment.application.getString(R.string.pref_widget_theme),
            RuntimeEnvironment.application.getString(R.string.pref_widget_theme_value_light))
        .putString(RuntimeEnvironment.application.getString(R.string.pref_widget_query), "Google")
        .apply();
    widgetProvider.onReceive(RuntimeEnvironment.application,
        new Intent(BuildConfig.APPLICATION_ID + ".ACTION_REFRESH_WIDGET")
            .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId));
    View view = shadowOf(widgetManager).getViewFor(appWidgetId);
    assertThat((TextView) view.findViewById(R.id.title))
        .containsText("Google");
    assertThat((TextView) view.findViewById(R.id.subtitle))
        .doesNotContainText(R.string.loading_text);
  }
}

代码示例来源:origin: hidroh/materialistic

@Test
public void testUpdateBest() {
  RuntimeEnvironment.application.getSharedPreferences("WidgetConfiguration_" + appWidgetId, MODE_PRIVATE)
      .edit()
      .putString(RuntimeEnvironment.application.getString(R.string.pref_widget_theme),
          RuntimeEnvironment.application.getString(R.string.pref_widget_theme_value_dark))
      .putString(RuntimeEnvironment.application.getString(R.string.pref_widget_section),
          RuntimeEnvironment.application.getString(R.string.pref_widget_section_value_best))
      .apply();
  widgetProvider.onReceive(RuntimeEnvironment.application,
      new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE)
          .putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[]{appWidgetId}));
  View view = shadowOf(widgetManager).getViewFor(appWidgetId);
  assertThat((TextView) view.findViewById(R.id.title))
      .containsText(R.string.title_activity_best);
  assertThat((TextView) view.findViewById(R.id.subtitle))
      .doesNotContainText(R.string.loading_text);
}

代码示例来源:origin: limpoxe/Android-Plugin-Framework

private static SharedPreferences getSharedPreference() {
  SharedPreferences sp = FairyGlobal.getHostApplication().getSharedPreferences("plugins.installed",
      Build.VERSION.SDK_INT < 11 ? Context.MODE_PRIVATE : Context.MODE_PRIVATE | 0x0004);
  return sp;
}

代码示例来源:origin: limpoxe/Android-Plugin-Framework

.getSharedPreferences("plugins.serviceMapping", Context.MODE_PRIVATE)
.edit().putString("plugins.serviceMapping.map", list).commit();

代码示例来源:origin: limpoxe/Android-Plugin-Framework

private static HashMap<String, String> restore() {
  String list = FairyGlobal.getHostApplication()
      .getSharedPreferences("plugins.serviceMapping", Context.MODE_PRIVATE)
      .getString("plugins.serviceMapping.map", "");
  Serializable object = null;

代码示例来源:origin: jonfinerty/Once

@Test
public void backwardsCompatibilityWithPre1Versions() {
  String tag = "version 0.5 tag";
  SharedPreferences sharedPreferences = RuntimeEnvironment.application.getSharedPreferences(PersistedMap.class.getSimpleName() + "TagLastSeenMap", Context.MODE_PRIVATE);
  sharedPreferences.edit().putLong(tag, 1234L).apply();
  Once.initialise(RuntimeEnvironment.application);
  Once.markDone(tag);
  Assert.assertTrue(Once.beenDone(tag, exactly(2)));
}

代码示例来源:origin: limpoxe/Android-Plugin-Framework

public static void removeNotSupportedPluginIfUpgraded() {
  SharedPreferences prefs = FairyGlobal.getHostApplication().getSharedPreferences("fairy_configs", Context.MODE_PRIVATE);
  String lastHostVersoinName = prefs.getString(KEY, null);
  String hostVersionName = null;

代码示例来源:origin: MindorksOpenSource/android-dagger2-example

@Provides
  SharedPreferences provideSharedPrefs() {
    return mApplication.getSharedPreferences("demo-prefs", Context.MODE_PRIVATE);
  }
}

代码示例来源:origin: stephanenicolas/toothpick

@Override
 public SharedPreferences get() {
  if (preferencesName != null) {
   return application.getSharedPreferences(preferencesName, Context.MODE_PRIVATE);
  }
  return PreferenceManager.getDefaultSharedPreferences(application);
 }
}

代码示例来源:origin: com.willowtreeapps/oak-demos

@Override
public EncryptedSharedPreferences get() {
  SharedPreferences sharedPreferences;
  if (preferencesName != null) {
    sharedPreferences = application
        .getSharedPreferences(preferencesName, Context.MODE_PRIVATE);
  } else {
    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(application);
  }
  return new EncryptedSharedPreferences(application, sharedPreferences);
}

代码示例来源:origin: chengzichen/KrGallery

public void checkFlashMode(String mode) {
  ArrayList<String> modes = CameraController.getInstance().availableFlashModes;
  if (modes.contains(currentFlashMode)) {
    return;
  }
  currentFlashMode = mode;
  configurePhotoCamera();
  SharedPreferences sharedPreferences = Gallery.applicationContext.getSharedPreferences("camera", Activity.MODE_PRIVATE);
  sharedPreferences.edit().putString(cameraInfo.frontCamera != 0 ? "flashMode_front" : "flashMode", mode).commit();
}

代码示例来源:origin: gdpancheng/LoonAndroid3

public static void ClearSharedPreferences(String dataBasesName) {
  SharedPreferences user = Ioc.getIoc().getApplication().getSharedPreferences(dataBasesName, 0);
  Editor editor = user.edit();
  editor.clear();
  editor.commit();
}

代码示例来源:origin: gdpancheng/LoonAndroid3

public static void removeSharedPreferences(String dataBasesName, String key) {
  SharedPreferences user = Ioc.getIoc().getApplication().getSharedPreferences(dataBasesName, 0);
  Editor editor = user.edit();
  editor.remove(key);
  editor.commit();
}

代码示例来源:origin: gdpancheng/LoonAndroid3

public static void WriteSharedPreferences(String dataBasesName, ThreeMap map) {
  if (map == null) {
    return;
  }
  SharedPreferences user = Ioc.getIoc().getApplication().getSharedPreferences(dataBasesName, 0);
  Editor editor = user.edit();
  map.addValueInEditor(editor);
  editor.commit();
}

代码示例来源:origin: brarcher/loyalty-card-locker

@Before
public void setUp()
{
  // Assume that this is not the first launch
  prefs = RuntimeEnvironment.application.getSharedPreferences("protect.card_locker", Context.MODE_PRIVATE);
  prefs.edit().putBoolean("firstrun", false).commit();
}

相关文章

微信公众号

最新文章

更多

Application类方法