本文整理了Java中android.content.SharedPreferences.getStringSet()
方法的一些代码示例,展示了SharedPreferences.getStringSet()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SharedPreferences.getStringSet()
方法的具体详情如下:
包路径:android.content.SharedPreferences
类名称:SharedPreferences
方法名:getStringSet
[英]Retrieve a set of String values from the preferences.
Note that you must not modify the set instance returned by this call. The consistency of the stored data is not guaranteed if you do, nor is your ability to modify the instance at all.
[中]从首选项中检索一组字符串值。
请注意,您不得修改此调用返回的set实例。如果您这样做,则无法保证存储数据的一致性,也根本无法修改实例。
代码示例来源:origin: smuyyh/BookReader
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public Set<String> getStringSet(String key) {
return this.prefs.getStringSet(key, null);
}
代码示例来源:origin: smuyyh/BookReader
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public Set<String> getStringSet(String key, Set<String> defaultVal) {
return this.prefs.getStringSet(key, defaultVal);
}
代码示例来源:origin: naman14/Timber
/**
* 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;
}
代码示例来源:origin: aa112901/remusic
/**
* 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;
}
代码示例来源:origin: aa112901/remusic
public static ArrayList<String> getIgnoredPermissions() {
ArrayList<String> ignoredPermissions = new ArrayList<String>();
ignoredPermissions.addAll(sharedPreferences.getStringSet(KEY_IGNORED_PERMISSIONS, new HashSet<String>()));
return ignoredPermissions;
}
代码示例来源:origin: naman14/Timber
public static ArrayList<String> getIgnoredPermissions() {
ArrayList<String> ignoredPermissions = new ArrayList<String>();
ignoredPermissions.addAll(sharedPreferences.getStringSet(KEY_IGNORED_PERMISSIONS, new HashSet<String>()));
return ignoredPermissions;
}
代码示例来源:origin: commonsguy/cw-omnibus
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);
}
代码示例来源:origin: commonsguy/cw-omnibus
@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);
}
}
代码示例来源:origin: evernote/android-job
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();
}
}
代码示例来源:origin: naman14/Timber
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();
}
代码示例来源:origin: evernote/android-job
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;
}
}
代码示例来源:origin: stackoverflow.com
HashSet<String> setCookies = new HashSet<String>();
setCookies.add(cookie.toString());
ediWriter.putStringSet(uri.toString(), spePreferences.getStringSet(uri.toString(), setCookies));
ediWriter.commit();
代码示例来源:origin: robolectric/robolectric
@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);
}
代码示例来源:origin: robolectric/robolectric
@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();
}
代码示例来源:origin: f2prateek/rx-preferences
@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);
}
代码示例来源:origin: stackoverflow.com
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>()));
代码示例来源:origin: Neamar/KISS
@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;
}
代码示例来源:origin: UweTrottmann/SeriesGuide
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);
}
}
}
代码示例来源:origin: jonfinerty/Once
private void waitForLoad() {
if (preferences == null) {
preferences = preferenceLoader.get();
set = preferences.getStringSet(STRING_SET_KEY, new HashSet<String>());
}
}
代码示例来源:origin: Neamar/KISS
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;
}
内容来源于网络,如有侵权,请联系作者删除!