List of usage examples for android.content SharedPreferences getStringSet
@Nullable Set<String> getStringSet(String key, @Nullable Set<String> defValues);
From source file:Main.java
public static Set<String> LoadLisPreferences(String key, Context context) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); Set<String> value = new HashSet<String>(); value = sharedPreferences.getStringSet(key, null); return value; }
From source file:com.google.android.apps.forscience.whistlepunk.PermissionUtils.java
public static boolean canRequestAgain(Activity activity, String permission) { // If the user has denied the permissions request, but not either never asked before // or clicked "never ask again", this will return true. In that case, we can request again. if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) { return true; }// ww w .j a v a 2 s. co m SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); Set<String> requestedPerms = prefs.getStringSet(KEY_PERMISSIONS_REQUESTED_SET, NO_STRINGS); // If the permission is in the set, they have asked for it already, and // at this point shouldShowRequestPermissionRationale is false, so they have also // clicked "never ask again". Return false -- we cannot request again. // If it was not found in the set, they haven't asked for it yet, so we can still ask. return !requestedPerms.contains(permission); }
From source file:com.commonsware.android.sawmonitor.PackageReceiver.java
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); }/*from ww w.j av a2 s .c om*/ PackageManager pm = ctxt.getPackageManager(); return (pm.checkPermission(SYSTEM_ALERT_WINDOW, pkg) == PackageManager.PERMISSION_GRANTED); }
From source file:com.commonsware.android.sawmonitor.SAWDetector.java
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; }//w w w.j a v a 2 s . c o m PackageManager pm = ctxt.getPackageManager(); return (pm.checkPermission(SYSTEM_ALERT_WINDOW, pkg) == PackageManager.PERMISSION_GRANTED); }
From source file:com.google.android.apps.forscience.whistlepunk.PermissionUtils.java
private static void requestPermission(Activity activity, String permission, int permissionType) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); // The set returned by getStringSet should not be modified. Set<String> requestedPerms = prefs.getStringSet(KEY_PERMISSIONS_REQUESTED_SET, null); Set<String> copyPerms = new HashSet<>(); if (requestedPerms != null) { copyPerms.addAll(requestedPerms); }/* w ww . j a va2s.c o m*/ copyPerms.add(permission); prefs.edit().putStringSet(KEY_PERMISSIONS_REQUESTED_SET, copyPerms).apply(); ActivityCompat.requestPermissions(activity, new String[] { permission }, permissionType); }
From source file:com.fusionx.lightirc.util.SharedPreferencesUtils.java
private static List<String> getIgnoreList(Context context, String filename) { final SharedPreferences serverSettings = context.getSharedPreferences(filename, MODE_PRIVATE); final Set<String> ignoreSet = serverSettings.getStringSet(PREF_IGNORE_LIST, new HashSet<String>()); return new ArrayList<>(ignoreSet); }
From source file:org.chromium.chrome.browser.media.MediaNotificationService.java
/** * Clear any previous media notifications. *//*from w ww .j a v a 2 s . co m*/ public static void clearMediaNotifications(Context context) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); Set<String> notificationIds = sharedPreferences.getStringSet(MEDIA_NOTIFICATION_IDS, null); if (notificationIds == null || notificationIds.isEmpty()) return; context.startService(new Intent(context, MediaNotificationService.class)); }
From source file:org.chromium.chrome.browser.media.MediaNotificationService.java
private static boolean shouldStartService(Context context, int mediaType, int tabId) { if (mediaType != MEDIATYPE_NO_MEDIA) return true; SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); Set<String> notificationIds = sharedPreferences.getStringSet(MEDIA_NOTIFICATION_IDS, null); if (notificationIds != null && !notificationIds.isEmpty() && notificationIds.contains(String.valueOf(tabId))) { return true; }/*from w w w. jav a2s . com*/ return false; }
From source file:cc.flydev.launcher.InstallShortcutReceiver.java
private static ArrayList<PendingInstallShortcutInfo> getAndClearInstallQueue(SharedPreferences sharedPrefs) { synchronized (sLock) { Set<String> strings = sharedPrefs.getStringSet(APPS_PENDING_INSTALL, null); if (DBG)/*from ww w . ja v a2 s . c om*/ Log.d(TAG, "Getting and clearing APPS_PENDING_INSTALL: " + strings); if (strings == null) { return new ArrayList<PendingInstallShortcutInfo>(); } ArrayList<PendingInstallShortcutInfo> infos = new ArrayList<PendingInstallShortcutInfo>(); for (String json : strings) { try { JSONObject object = (JSONObject) new JSONTokener(json).nextValue(); Intent data = Intent.parseUri(object.getString(DATA_INTENT_KEY), 0); Intent launchIntent = Intent.parseUri(object.getString(LAUNCH_INTENT_KEY), 0); String name = object.getString(NAME_KEY); String iconBase64 = object.optString(ICON_KEY); String iconResourceName = object.optString(ICON_RESOURCE_NAME_KEY); String iconResourcePackageName = object.optString(ICON_RESOURCE_PACKAGE_NAME_KEY); if (iconBase64 != null && !iconBase64.isEmpty()) { byte[] iconArray = Base64.decode(iconBase64, Base64.DEFAULT); Bitmap b = BitmapFactory.decodeByteArray(iconArray, 0, iconArray.length); data.putExtra(Intent.EXTRA_SHORTCUT_ICON, b); } else if (iconResourceName != null && !iconResourceName.isEmpty()) { Intent.ShortcutIconResource iconResource = new Intent.ShortcutIconResource(); iconResource.resourceName = iconResourceName; iconResource.packageName = iconResourcePackageName; data.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); } data.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent); PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, launchIntent); infos.add(info); } catch (org.json.JSONException e) { Log.d(TAG, "Exception reading shortcut to add: " + e); } catch (java.net.URISyntaxException e) { Log.d(TAG, "Exception reading shortcut to add: " + e); } } sharedPrefs.edit().putStringSet(APPS_PENDING_INSTALL, new HashSet<String>()).commit(); return infos; } }
From source file:cc.flydev.launcher.InstallShortcutReceiver.java
private static void addToStringSet(SharedPreferences sharedPrefs, SharedPreferences.Editor editor, String key, String value) {/*from ww w .j av a 2 s . c om*/ Set<String> strings = sharedPrefs.getStringSet(key, null); if (strings == null) { strings = new HashSet<String>(0); } else { strings = new HashSet<String>(strings); } strings.add(value); editor.putStringSet(key, strings); }