@TargetApi(Build.VERSION_CODES.HONEYCOMB) public Set<String> getStringSet(String key) { return this.prefs.getStringSet(key, null); }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public Set<String> getStringSet(String key, Set<String> defaultVal) { return this.prefs.getStringSet(key, defaultVal); }
/** * Get list of previous Permissions, from last refreshMonitoredList() call and they may be outdated, * use getGrantedPermissions() to get current */ public static ArrayList<String> getPreviousPermissions() { ArrayList<String> prevPermissions = new ArrayList<String>(); prevPermissions.addAll(sharedPreferences.getStringSet(KEY_PREV_PERMISSIONS, new HashSet<String>())); return prevPermissions; }
/** * Get list of previous Permissions, from last refreshMonitoredList() call and they may be outdated, * use getGrantedPermissions() to get current */ public static ArrayList<String> getPreviousPermissions() { ArrayList<String> prevPermissions = new ArrayList<String>(); prevPermissions.addAll(sharedPreferences.getStringSet(KEY_PREV_PERMISSIONS, new HashSet<String>())); return prevPermissions; }
public static ArrayList<String> getIgnoredPermissions() { ArrayList<String> ignoredPermissions = new ArrayList<String>(); ignoredPermissions.addAll(sharedPreferences.getStringSet(KEY_IGNORED_PERMISSIONS, new HashSet<String>())); return ignoredPermissions; }
public static ArrayList<String> getIgnoredPermissions() { ArrayList<String> ignoredPermissions = new ArrayList<String>(); ignoredPermissions.addAll(sharedPreferences.getStringSet(KEY_IGNORED_PERMISSIONS, new HashSet<String>())); return ignoredPermissions; }
private static boolean hasSAW(Context ctxt, String pkg) { SharedPreferences prefs= PreferenceManager.getDefaultSharedPreferences(ctxt); Set<String> whitelist= prefs.getStringSet(WhitelistReceiver.PREF_WHITELIST, new HashSet<String>()); if (whitelist.contains(pkg)) { return false; } PackageManager pm=ctxt.getPackageManager(); return(pm.checkPermission(SYSTEM_ALERT_WINDOW, pkg)== PackageManager.PERMISSION_GRANTED); }
@Override public void onReceive(Context ctxt, Intent intent) { String pkg=intent.getData().getSchemeSpecificPart(); SharedPreferences prefs= PreferenceManager.getDefaultSharedPreferences(ctxt); Set<String> whitelist=prefs.getStringSet(PREF_WHITELIST, new HashSet<String>()); whitelist.add(pkg); prefs.edit().putStringSet(PREF_WHITELIST, whitelist).apply(); NotificationManager mgr= (NotificationManager)ctxt.getSystemService( Context.NOTIFICATION_SERVICE); mgr.cancel(SAWDetector.NOTIFY_ID); } }
public JobStorage(Context context, String databasePath) { mPreferences = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE); mLock = new ReentrantReadWriteLock(); mCacheId = new JobCacheId(); mDbHelper = new JobOpenHelper(context, databasePath); mFailedDeleteIds = mPreferences.getStringSet(FAILED_DELETE_IDS, new HashSet<String>()); if (!mFailedDeleteIds.isEmpty()) { tryToCleanupFinishedJobs(); } }
ScrobbleUploader(ScrobbleQuery query) { if (queries == null) { queries = new HashSet<>(); queries.addAll(preferences.getStringSet(PREFERENCE_CACHE_NAME, new HashSet<String>())); } if (query != null) { synchronized (sLock) { if (isUploading) { cachedirty = true; queries.add(query.toString()); save(); return; } } newquery = query; } upload(); }
private Context mockContext() { SharedPreferences preferences = mock(SharedPreferences.class); when(preferences.getStringSet(anyString(), ArgumentMatchers.<String>anySet())).thenReturn(new HashSet<String>()); Context context = mock(MockContext.class); when(context.getApplicationContext()).thenReturn(context); when(context.getSharedPreferences(anyString(), anyInt())).thenReturn(preferences); return context; } }
HashSet<String> setCookies = new HashSet<String>(); setCookies.add(cookie.toString()); ediWriter.putStringSet(uri.toString(), spePreferences.getStringSet(uri.toString(), setCookies)); ediWriter.commit();
@Test public void commit_shouldStoreValues() throws Exception { editor.commit(); SharedPreferences anotherSharedPreferences = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE); assertTrue(anotherSharedPreferences.getBoolean("boolean", false)); assertThat(anotherSharedPreferences.getFloat("float", 666f)).isEqualTo(1.1f); assertThat(anotherSharedPreferences.getInt("int", 666)).isEqualTo(2); assertThat(anotherSharedPreferences.getLong("long", 666L)).isEqualTo(3L); assertThat(anotherSharedPreferences.getString("string", "wacka wa")).isEqualTo("foobar"); assertThat(anotherSharedPreferences.getStringSet("stringSet", null)).isEqualTo(stringSet); }
@Test public void putStringSet_shouldRemovePairIfValueIsNull() throws Exception { editor.putStringSet("deleteMe", new HashSet<String>()); editor.putStringSet("deleteMe", null); editor.commit(); assertThat(sharedPreferences.getStringSet("deleteMe", null)).isNull(); }
@Override public Set<String> get(@NonNull String key, @NonNull SharedPreferences preferences) { Set<String> value = preferences.getStringSet(key, null); assert value != null; // Not called unless key is present. return Collections.unmodifiableSet(value); }
SharedPreferences ss = getSharedPreferences("db", 0); Set<String> hs = ss.getStringSet("set", new HashSet<String>()); Set<String> in = new HashSet<String>(hs); in.add(String.valueOf(hs.size()+1)); ss.edit().putStringSet("set", in).commit(); // brevity // SharedPreferences sss = getSharedPreferences("db", 0); // not needed Log.i("chauster", "2.set = "+ ss.getStringSet("set", new HashSet<String>()));
@NonNull public Set<String> getExcluded() { Set<String> excluded = PreferenceManager.getDefaultSharedPreferences(context).getStringSet("excluded-apps", null); if (excluded == null) { excluded = new HashSet<>(); excluded.add(context.getPackageName()); } return excluded; }
private synchronized void loadSubscriptions() { subscribers = new HashMap<>(); Set<String> serializedSubscriptions = sharedPrefs.getStringSet(PREF_SUBSCRIPTIONS, null); if (serializedSubscriptions != null) { for (String serializedSubscription : serializedSubscriptions) { String[] arr = serializedSubscription.split("\\|", 2); ComponentName subscriber = ComponentName.unflattenFromString(arr[0]); String token = arr[1]; subscribers.put(subscriber, token); } } }
private void waitForLoad() { if (preferences == null) { preferences = preferenceLoader.get(); set = preferences.getStringSet(STRING_SET_KEY, new HashSet<String>()); } }
private boolean validateNameExists() { Set<String> availableSearchProviders = prefs.getStringSet("available-search-providers", SearchProvider.getSearchProviders(this.getContext())); for (String searchProvider : availableSearchProviders) { String[] nameAndUrl = searchProvider.split("\\|"); if (nameAndUrl.length == 2) { if (nameAndUrl[0].equals(providerName.getText().toString())) { return false; } } } return true; }