本文整理了Java中android.content.SharedPreferences.contains()
方法的一些代码示例,展示了SharedPreferences.contains()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SharedPreferences.contains()
方法的具体详情如下:
包路径:android.content.SharedPreferences
类名称:SharedPreferences
方法名:contains
[英]Checks whether the preferences contains a preference.
[中]检查首选项是否包含首选项。
代码示例来源:origin: libgdx/libgdx
@Override
public boolean contains (String key) {
return sharedPrefs.contains(key);
}
代码示例来源:origin: libgdx/libgdx
@Override
public boolean contains (String key) {
return sharedPrefs.contains(key);
}
代码示例来源:origin: androidannotations/androidannotations
public final boolean exists() {
return sharedPreferences.contains(key);
}
代码示例来源:origin: facebook/facebook-android-sdk
private boolean hasCachedAccessToken() {
return sharedPreferences.contains(CACHED_ACCESS_TOKEN_KEY);
}
代码示例来源:origin: smuyyh/BookReader
public boolean exists(String key) {
return prefs.contains(key);
}
代码示例来源:origin: stackoverflow.com
double getDouble(final SharedPreferences prefs, final String key, final double defaultValue) {
if ( !prefs.contains(key))
return defaultValue;
return Double.longBitsToDouble(prefs.getLong(key, 0));
}
代码示例来源:origin: stackoverflow.com
SharedPreferences spref = PreferenceManager.getDefaultSharedPreferences(this);
if (spref.contains("email")) {
String sEmailAddr = spref.getString("email", "");
}
代码示例来源:origin: HotBitmapGG/bilibili-android-client
public static boolean hasString(String key) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(BilibiliApp.getInstance());
return sharedPreferences.contains(key);
}
代码示例来源:origin: grandcentrix/tray
@Override
public boolean shouldMigrate() {
if (mPreferences.contains(mSharedPrefsKey)) {
return true;
}
TrayLog.v("key '" + mSharedPrefsKey + "' in SharedPreferences '"
+ mSharedPrefsName + "' not found. skipped import");
return false;
}
代码示例来源:origin: hidroh/materialistic
@Synthetic
boolean hasOldValue(Context context, SharedPreferences sp) {
return sp.contains(context.getString(oldKey));
}
}
代码示例来源:origin: ankidroid/Anki-Android
private Long getLastDeckId() {
SharedPreferences state = getSharedPreferences(PERSISTENT_STATE_FILE,0);
if (!state.contains(LAST_DECK_ID_KEY)) {
return null;
}
return state.getLong(LAST_DECK_ID_KEY, -1);
}
代码示例来源:origin: facebook/facebook-android-sdk
public static SourceApplicationInfo getStoredSourceApplicatioInfo() {
SharedPreferences sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(
FacebookSdk.getApplicationContext());
if (!sharedPreferences.contains(CALL_APPLICATION_PACKAGE_KEY)) {
return null;
}
String callingApplicationPackage = sharedPreferences.getString(
CALL_APPLICATION_PACKAGE_KEY,
null);
boolean openedByAppLink = sharedPreferences.getBoolean(OPENED_BY_APP_LINK_KEY, false);
return new SourceApplicationInfo(callingApplicationPackage, openedByAppLink);
}
代码示例来源:origin: jeasonlzy/okhttp-OkGo
@Override
public synchronized boolean removeCookie(HttpUrl url) {
if (!cookies.containsKey(url.host())) return false;
//内存移除
ConcurrentHashMap<String, Cookie> urlCookie = cookies.remove(url.host());
//文件移除
Set<String> cookieTokens = urlCookie.keySet();
SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
for (String cookieToken : cookieTokens) {
if (cookiePrefs.contains(COOKIE_NAME_PREFIX + cookieToken)) {
prefsWriter.remove(COOKIE_NAME_PREFIX + cookieToken);
}
}
prefsWriter.remove(url.host());
prefsWriter.apply();
return true;
}
代码示例来源:origin: jeasonlzy/okhttp-OkGo
/** 根据url移除当前的cookie */
@Override
public synchronized boolean removeCookie(HttpUrl url, Cookie cookie) {
if (!cookies.containsKey(url.host())) return false;
String cookieToken = getCookieToken(cookie);
if (!cookies.get(url.host()).containsKey(cookieToken)) return false;
//内存移除
cookies.get(url.host()).remove(cookieToken);
//文件移除
SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
if (cookiePrefs.contains(COOKIE_NAME_PREFIX + cookieToken)) {
prefsWriter.remove(COOKIE_NAME_PREFIX + cookieToken);
}
prefsWriter.putString(url.host(), TextUtils.join(",", cookies.get(url.host()).keySet()));
prefsWriter.apply();
return true;
}
代码示例来源:origin: TommyLemon/APIJSON
/**判断是否已存
* @param key
* @return
*/
public boolean isContain(String key) {
if (StringUtil.isNotEmpty(key, true) == false) {
Log.e(TAG, "isContain StringUtil.isNotEmpty(key, true) == false >> return false;");
return false;
}
return sp.contains(StringUtil.getTrimedString(key));
}
代码示例来源:origin: TommyLemon/Android-ZBLibrary
/**判断是否已存
* @param key
* @return
*/
public boolean isContain(String key) {
if (StringUtil.isNotEmpty(key, true) == false) {
Log.e(TAG, "isContain StringUtil.isNotEmpty(key, true) == false >> return false;");
return false;
}
return sp.contains(StringUtil.getTrimedString(key));
}
代码示例来源:origin: facebook/facebook-android-sdk
@Test
public void testSaveWritesToCacheIfToken() throws JSONException {
AccessToken accessToken = createAccessToken();
AccessTokenCache cache = new AccessTokenCache(sharedPreferences, cachingStrategyFactory);
cache.save(accessToken);
verify(cachingStrategy, never()).save(any(Bundle.class));
assertTrue(sharedPreferences.contains(AccessTokenCache.CACHED_ACCESS_TOKEN_KEY));
AccessToken savedAccessToken = AccessToken.createFromJSONObject(
new JSONObject(sharedPreferences.getString(
AccessTokenCache.CACHED_ACCESS_TOKEN_KEY, null)));
assertEquals(accessToken, savedAccessToken);
}
代码示例来源:origin: facebook/facebook-android-sdk
@Test
public void testClearCacheClearsCache() {
AccessToken accessToken = createAccessToken();
AccessTokenCache cache = new AccessTokenCache(sharedPreferences, cachingStrategyFactory);
cache.save(accessToken);
cache.clear();
assertFalse(sharedPreferences.contains(AccessTokenCache.CACHED_ACCESS_TOKEN_KEY));
verify(cachingStrategy, never()).clear();
}
代码示例来源:origin: facebook/facebook-android-sdk
@Test
public void testClearCacheClearsLegacyCache() {
when(FacebookSdk.isLegacyTokenUpgradeSupported()).thenReturn(true);
AccessToken accessToken = createAccessToken();
AccessTokenCache cache = new AccessTokenCache(sharedPreferences, cachingStrategyFactory);
cache.save(accessToken);
cache.clear();
assertFalse(sharedPreferences.contains(AccessTokenCache.CACHED_ACCESS_TOKEN_KEY));
verify(cachingStrategy, times(1)).clear();
}
代码示例来源:origin: facebook/facebook-android-sdk
@Test
public void testLoadSavesTokenWhenUpgradingFromLegacyToken() throws JSONException {
when(FacebookSdk.isLegacyTokenUpgradeSupported()).thenReturn(true);
AccessToken accessToken = createAccessToken();
when(cachingStrategy.load()).thenReturn(
AccessTokenTestHelper.toLegacyCacheBundle(accessToken));
AccessTokenCache cache = new AccessTokenCache(sharedPreferences, cachingStrategyFactory);
cache.load();
assertTrue(sharedPreferences.contains(AccessTokenCache.CACHED_ACCESS_TOKEN_KEY));
AccessToken savedAccessToken = AccessToken.createFromJSONObject(
new JSONObject(sharedPreferences.getString(
AccessTokenCache.CACHED_ACCESS_TOKEN_KEY, null)));
assertEquals(accessToken, savedAccessToken);
}
内容来源于网络,如有侵权,请联系作者删除!