android.app.Application#getSharedPreferences ( )源码实例Demo

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

源代码1 项目: SAI   文件: BackupViewModel.java
public BackupViewModel(@NonNull Application application) {
    super(application);

    mFilterPrefs = application.getSharedPreferences("backup_filter", Context.MODE_PRIVATE);

    BackupPackagesFilterConfig filterConfig = new BackupPackagesFilterConfig(mFilterPrefs);
    mBackupFilterConfig.setValue(filterConfig);
    mComplexFilterConfig = filterConfig.toComplexFilterConfig(application);

    mPackagesLiveData.setValue(new ArrayList<>());

    mBackupManager = DefaultBackupManager.getInstance(getApplication());
    mBackupRepoPackagesObserver = (packages) -> search(mCurrentSearchQuery);
    mBackupManager.getApps().observeForever(mBackupRepoPackagesObserver);

    mLiveFilterApplier.asLiveData().observeForever(mLiveFilterObserver);
    mBackupFilterConfig.setValue(new BackupPackagesFilterConfig(mComplexFilterConfig));
}
 
源代码2 项目: Tracker   文件: Tracker.java
public void init(Application context, TrackerConfiguration config) {
	if (config == null) {
		throw new IllegalArgumentException("config can't be null");
	}

	isInit = true;
	this.context = context;
	setTrackerConfig(config);
	preferences = context.getSharedPreferences(context.getPackageName(), MODE_PRIVATE);
	if (preferences.getBoolean(KEY_IS_NEW_DEVICE, true) && !TextUtils.isEmpty(config.getNewDeviceUrl())) {
		submitDeviceInfo();
	}
	context.registerActivityLifecycleCallbacks(new ActivityLifecycleListener());
	if (config.getUploadCategory() == UPLOAD_CATEGORY.REAL_TIME) {
		UploadEventService.enter(context, config.getHostName(), config.getHostPort(), null);
	} else {
		if (!requestConfig) {
			startRequestConfig();
		}
	}
}
 
源代码3 项目: Android-NoSql   文件: SharedPrefsTest.java
@Before
public void setUp() throws Exception {
    final Application application = RuntimeEnvironment.application;
    sharedPreferences = application.getSharedPreferences("test", Context.MODE_PRIVATE);
    sharedPreferences.edit().clear().apply();

    //dataSaver = new SharedPreferencesDataSaver(sharedPreferences);
    dataSaver = new PaperDataSaver(application);
    dataSaver = spy(dataSaver);

    AndroidNoSql.initWith(
            dataSaver
    );
    noSql = NoSql.getInstance();
    noSql.reset();
}
 
源代码4 项目: toothpick   文件: SmoothieApplicationModuleTest.java
@Test
public void testModule_shouldReturnNamedSharedPreferences() throws Exception {
  // GIVEN
  Application application = ApplicationProvider.getApplicationContext();

  String sharedPreferencesName = "test";
  String itemKey = "isValid";
  SharedPreferences sharedPreferences =
      application.getSharedPreferences(sharedPreferencesName, Context.MODE_PRIVATE);
  sharedPreferences.edit().putBoolean(itemKey, true).commit();

  Scope appScope = Toothpick.openScope(application);
  appScope.installModules(new SmoothieApplicationModule(application, sharedPreferencesName));

  // WHEN
  SharedPreferences sharedPreferencesFromScope = appScope.getInstance(SharedPreferences.class);

  // THEN
  assertThat(sharedPreferencesFromScope.getBoolean(itemKey, false), is(true));
}
 
/**
 * Helper method for getting a boolean value from the apps stored preferences.
 *
 * @param preference the preference key.
 * @param defaultValue the default value to return if the key is not found.
 * @return the value stored or the default if the stored value is not found.
 */
public boolean getAndSetBooleanPreference(String preference, boolean defaultValue) {
  Application application = (Application) firebaseApp.getApplicationContext();
  SharedPreferences preferences =
      application.getSharedPreferences(PREFERENCES_PACKAGE_NAME, Context.MODE_PRIVATE);

  // Value set at runtime overrides anything else, but default to defaultValue.
  if (preferences.contains(preference)) {
    boolean result = preferences.getBoolean(preference, defaultValue);
    return result;
  }
  // No preferences set yet - use and set defaultValue.
  setBooleanPreference(preference, defaultValue);
  return defaultValue;
}
 
/**
 * Helper method for getting a boolean value from the apps stored preferences.
 *
 * @param preference the preference key.
 * @param defaultValue the default value to return if the key is not found.
 * @return the value stored or the default if the stored value is not found.
 */
public boolean getBooleanPreference(String preference, boolean defaultValue) {
  Application application = (Application) firebaseApp.getApplicationContext();
  SharedPreferences preferences =
      application.getSharedPreferences(PREFERENCES_PACKAGE_NAME, Context.MODE_PRIVATE);

  // Value set at runtime overrides anything else, but default to defaultValue.
  if (preferences.contains(preference)) {
    boolean result = preferences.getBoolean(preference, defaultValue);
    return result;
  }
  // No preferences set yet - use  defaultValue.
  return defaultValue;
}
 
/**
 * Helper method for getting a boolean value from the apps stored preferences.
 *
 * @param preference the preference key.
 * @return whether the preference has been set or not
 */
public boolean isPreferenceSet(String preference) {
  Application application = (Application) firebaseApp.getApplicationContext();
  SharedPreferences preferences =
      application.getSharedPreferences(PREFERENCES_PACKAGE_NAME, Context.MODE_PRIVATE);

  return preferences.contains(preference);
}
 
/**
 * Saves the provided identity id as the currently active id in the app preferences.
 *
 * @param application The caller's application object.
 */
public static void saveCurrentId(Application application, long newIdentityId) {
    SharedPreferences sharedPref = application.getSharedPreferences(APPS_PREFERENCES, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPref.edit();
    editor.putLong(CURRENT_ID, newIdentityId);
    editor.apply();
}
 
源代码9 项目: ACDD   文件: Utils.java
/**
 * save OpenAtlas runtime info to sharedPreference
 **/
public static void saveAtlasInfoBySharedPreferences(Application application) {
    Map<String, String> concurrentHashMap = new ConcurrentHashMap<String, String>();
    concurrentHashMap.put(getPackageInfo(application).versionName, "dexopt");
    SharedPreferences sharedPreferences = application.getSharedPreferences(OpenAtlasInternalConstant.OPENATLAS_CONFIGURE, Context.MODE_PRIVATE);
    if (sharedPreferences == null) {
        sharedPreferences = application.getSharedPreferences(OpenAtlasInternalConstant.OPENATLAS_CONFIGURE, Context.MODE_PRIVATE);
    }
    Editor edit = sharedPreferences.edit();
    for (String key : concurrentHashMap.keySet()) {
        edit.putString(key, concurrentHashMap.get(key));
    }
    edit.commit();
}
 
public RNPushNotificationHelper(Application context) {
    this.context = context;
    this.scheduledNotificationsPersistence = context.getSharedPreferences(RNPushNotificationHelper.PREFERENCES_KEY, Context.MODE_PRIVATE);
}
 
源代码11 项目: OmniList   文件: ListRemoteViewsFactory.java
ListRemoteViewsFactory(RemoteViewsService remoteViewsService, Application app, Intent intent) {
    this.app = (PalmApp) app;
    appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
    sharedPreferences = app.getSharedPreferences(Constants.PREFS_NAME, Context.MODE_MULTI_PROCESS);
    sharedPreferences.registerOnSharedPreferenceChangeListener(this);
}
 
源代码12 项目: DaggerAutoInject   文件: AppModule.java
@Provides
@Singleton
public SharedPreferences providesSharedPreferences(Application application){
    return application.getSharedPreferences("user", Context.MODE_PRIVATE);
}
 
源代码13 项目: eternity   文件: MessageStateStorage.java
@Inject
MessageStateStorage(Application application) {
  this.preferences = application.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
}
 
源代码14 项目: force-update   文件: ForceUpdate.java
public ForceUpdate(Application gApplication,
                   boolean gDebug,
                   VersionProvider gForcedVersionProvider, int gForcedVersionInterval,
                   VersionProvider gRecommendedVersionProvider, int gRecommendedVersionInterval,
                   VersionProvider gExcludedVersionListProvider, int gExcludedVersionListInterval,
                   VersionProvider gCurrentVersionProvider,
                   UpdateView gForcedVersionView,
                   UpdateView gRecommendedVersionView,
                   List<Class<?>> gForceUpdateActivities) {

    if(alreadyInstantiated) {
        throw new RuntimeException("ForceUpdate library is already initialized.");
    }

    String permission = "android.permission.INTERNET";
    int res = gApplication.checkCallingOrSelfPermission(permission);
    if(res != PackageManager.PERMISSION_GRANTED) {
        throw new RuntimeException("Internet permission is necessary for version checks.");
    }

    if(!gDebug && (gForcedVersionInterval < 60 || gRecommendedVersionInterval < 60 || gExcludedVersionListInterval < 60)) {
        throw new RuntimeException("Minimal fetch interval is 60s");
    }

    application = gApplication;

    minAllowedVersionProvider = gForcedVersionProvider;

    minAllowedVersionInterval = gForcedVersionInterval;

    recommendedVersionProvider = gRecommendedVersionProvider;

    recommendedVersionInterval = gRecommendedVersionInterval;

    excludedVersionProvider  = gExcludedVersionListProvider;

    excludedVersionInterval = gExcludedVersionListInterval;

    currentVersionProvider = gCurrentVersionProvider;

    forcedUpdateView = gForcedVersionView;

    recommendedUpdateView = gRecommendedVersionView;

    forceUpdateActivities = gForceUpdateActivities;

    sharedPreferences = gApplication.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);

    alreadyInstantiated = true;
}
 
源代码15 项目: AndroidArchitecture   文件: PreferencesManager.java
public PreferencesManager(Application application){
     sharedPreferences = application.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE);
}
 
public RNPushNotificationHelper(Application context) {
    this.context = context;
    this.config = new RNPushNotificationConfig(context);
    this.scheduledNotificationsPersistence = context.getSharedPreferences(RNPushNotificationHelper.PREFERENCES_KEY, Context.MODE_PRIVATE);
}
 
源代码17 项目: ViewInspector   文件: ApplicationModule.java
@Provides @Singleton SharedPreferences provideSharedPreferences(Application app) {
  return app.getSharedPreferences("view-inspector", MODE_PRIVATE);
}
 
源代码18 项目: DataInspector   文件: ApplicationModule.java
@Provides @Singleton SharedPreferences provideSharedPreferences(Application app) {
  return app.getSharedPreferences("data-inspector", MODE_PRIVATE);
}
 
源代码19 项目: dagger2-example   文件: DataModule.java
@Provides
@Singleton
SharedPreferences provideSharedPreferences(Application app) {
    return app.getSharedPreferences("daggerdemo", Context.MODE_PRIVATE);
}
 
源代码20 项目: u2020-mvp   文件: DataModule.java
@Provides
@ApplicationScope
SharedPreferences provideSharedPreferences(Application app) {
    return app.getSharedPreferences("u2020", MODE_PRIVATE);
}