本文整理汇总了Java中android.content.SharedPreferences.getLong方法的典型用法代码示例。如果您正苦于以下问题:Java SharedPreferences.getLong方法的具体用法?Java SharedPreferences.getLong怎么用?Java SharedPreferences.getLong使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.SharedPreferences
的用法示例。
在下文中一共展示了SharedPreferences.getLong方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
* 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值
*/
public static Object get(Context context, String key, Object defaultObject) {
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
Context.MODE_PRIVATE);
if (defaultObject instanceof String) {
return sp.getString(key, (String) defaultObject);
} else if (defaultObject instanceof Integer) {
return sp.getInt(key, (Integer) defaultObject);
} else if (defaultObject instanceof Boolean) {
return sp.getBoolean(key, (Boolean) defaultObject);
} else if (defaultObject instanceof Float) {
return sp.getFloat(key, (Float) defaultObject);
} else if (defaultObject instanceof Long) {
return sp.getLong(key, (Long) defaultObject);
}
return null;
}
示例2: getLastNotificationTimeInMillis
import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
* Returns the last time that a notification was shown (in UNIX time)
*
* @param context Used to access SharedPreferences
* @return UNIX time of when the last notification was shown
*/
public static long getLastNotificationTimeInMillis(Context context) {
/* Key for accessing the time at which Sunshine last displayed a notification */
String lastNotificationKey = context.getString(R.string.pref_last_notification);
/* As usual, we use the default SharedPreferences to access the user's preferences */
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
/*
* Here, we retrieve the time in milliseconds when the last notification was shown. If
* SharedPreferences doesn't have a value for lastNotificationKey, we return 0. The reason
* we return 0 is because we compare the value returned from this method to the current
* system time. If the difference between the last notification time and the current time
* is greater than one day, we will show a notification again. When we compare the two
* values, we subtract the last notification time from the current system time. If the
* time of the last notification was 0, the difference will always be greater than the
* number of milliseconds in a day and we will show another notification.
*/
long lastNotificationTime = sp.getLong(lastNotificationKey, 0);
return lastNotificationTime;
}
示例3: getPreferedApnIdFromPreferences
import android.content.SharedPreferences; //导入方法依赖的package包/类
private static long getPreferedApnIdFromPreferences(Context context, SharedPreferences prefs) {
long id = prefs.getLong(Constants.PREF_PREFERRED_APN_ID, -1L);
if (id == -1L) return id;
// verify that there is still APN with such id
ContentResolver resolver = context.getContentResolver();
Cursor cursor = resolver.query(CURRENT_APNS, new String[] {COLUMN_ID}, COLUMN_ID + "=" + id, null, null);
try {
cursor.moveToFirst();
if (!cursor.isAfterLast()){
// yes! it is still there
return id;
} else {
// no such APN anymore, return "not found"
return -1;
}
} finally {
if (cursor != null) cursor.close();
}
}
示例4: get
import android.content.SharedPreferences; //导入方法依赖的package包/类
public static Object get(String fileName, Context context, String key, Object defaultObject) {
SharedPreferences sp = SharedPreferencesImpl.getSharedPreferences(context, getFileName(fileName),
Context.MODE_PRIVATE);
if (defaultObject instanceof String) {
return sp.getString(key, (String) defaultObject);
} else if (defaultObject instanceof Integer) {
return sp.getInt(key, (Integer) defaultObject);
} else if (defaultObject instanceof Boolean) {
return sp.getBoolean(key, (Boolean) defaultObject);
} else if (defaultObject instanceof Float) {
return sp.getFloat(key, (Float) defaultObject);
} else if (defaultObject instanceof Long) {
return sp.getLong(key, (Long) defaultObject);
} else if (null == defaultObject) {
return sp.getString(key, null);
}
return null;
}
示例5: needUpdateCDBRequest
import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
* define if CDB request need repeat
* @param context
* @return
*/
static boolean needUpdateCDBRequest(Context context)
{
SharedPreferences preferences = HelperFunctions.getWebTrekkSharedPreference(context);
if (preferences.contains(LAST_CBD_REQUEST_DATE)) {
long dates = preferences.getLong(LAST_CBD_REQUEST_DATE, 0);
return dates < getCurrentDateCounter();
}else
return false;
}
示例6: isRegisteredOnServer
import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
* Checks whether the device was successfully registered in the server side.
*
* @param context Current context
* @return True if registration was successful, false otherwise
*/
public static boolean isRegisteredOnServer(Context context, String gcmKey) {
final SharedPreferences prefs = context.getSharedPreferences(
PREFERENCES, Context.MODE_PRIVATE);
// Find registration threshold
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
long yesterdayTS = cal.getTimeInMillis();
long regTS = prefs.getLong(PROPERTY_REGISTERED_TS, 0);
gcmKey = gcmKey == null ? "" : gcmKey;
if (regTS > yesterdayTS) {
LOGV(TAG, "GCM registration current. regTS=" + regTS + " yesterdayTS=" + yesterdayTS);
final String registeredGcmKey = prefs.getString(PROPERTY_GCM_KEY, "");
if (registeredGcmKey.equals(gcmKey)) {
LOGD(TAG, "GCM registration is valid and for the correct gcm key: "
+ AccountUtils.sanitizeGcmKey(registeredGcmKey));
return true;
}
LOGD(TAG, "GCM registration is for DIFFERENT gcm key "
+ AccountUtils.sanitizeGcmKey(registeredGcmKey) + ". We were expecting "
+ AccountUtils.sanitizeGcmKey(gcmKey));
return false;
} else {
LOGV(TAG, "GCM registration expired. regTS=" + regTS + " yesterdayTS=" + yesterdayTS);
return false;
}
}
示例7: RestoreState
import android.content.SharedPreferences; //导入方法依赖的package包/类
private void RestoreState() {
try {
SharedPreferences mPrefs = getActivity().getPreferences(Activity.MODE_PRIVATE);
ActNewFlight.fPaused = mPrefs.getBoolean(m_KeysIsPaused, false);
ActNewFlight.dtPauseTime = mPrefs.getLong(m_KeysPausedTime, 0);
ActNewFlight.dtTimeOfLastPause = mPrefs.getLong(m_KeysTimeOfLastPause, 0);
ActNewFlight.accumulatedNight = (double) mPrefs.getFloat(m_KeysAccumulatedNight, (float) 0.0);
} catch (Exception e) {
Log.e(MFBConstants.LOG_TAG, Log.getStackTraceString(e));
}
}
示例8: get
import android.content.SharedPreferences; //导入方法依赖的package包/类
private Object get(SharedPreferences sp, String key, Object defaultObject) {
String type = defaultObject.getClass().getSimpleName();
if ("String".equals(type)) {
return sp.getString(key, (String) defaultObject);
} else if ("Integer".equals(type)) {
return sp.getInt(key, (Integer) defaultObject);
} else if ("Boolean".equals(type)) {
return sp.getBoolean(key, (Boolean) defaultObject);
} else if ("Float".equals(type)) {
return sp.getFloat(key, (Float) defaultObject);
} else if ("Long".equals(type)) {
return sp.getLong(key, (Long) defaultObject);
}
return null;
}
示例9: isModified
import android.content.SharedPreferences; //导入方法依赖的package包/类
private static boolean isModified(Context context, File archive, long currentCrc) {
SharedPreferences prefs = getMultiDexPreferences(context);
return (prefs.getLong("timestamp", -1) == getTimeStamp(archive) && prefs.getLong(KEY_CRC, -1) == currentCrc) ? false : true;
}
示例10: getLong
import android.content.SharedPreferences; //导入方法依赖的package包/类
public long getLong(Context context, String key, long defValue) {
SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
return sp.getLong(key, defValue);
}
示例11: getLastUpdate
import android.content.SharedPreferences; //导入方法依赖的package包/类
private long getLastUpdate(Context context) {
SharedPreferences sharedPref = context.getSharedPreferences("app_preferences", Context.MODE_PRIVATE);
return sharedPref.getLong("update_time", 0);
}
示例12: setNextAlarm
import android.content.SharedPreferences; //导入方法依赖的package包/类
public static void setNextAlarm(Context context) {
// Prepare alarm
Intent diaryAlertIntent = new Intent(context, AlarmHandler.class);
diaryAlertIntent.setAction(AlarmHandler.DIARY_ALERT);
PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, diaryAlertIntent, 0);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
// Get alarm time
SharedPreferences sharedPreferences = context.getSharedPreferences(
MainActivity.PREFERENCES, Context.MODE_PRIVATE);
long diaryReminderTime = sharedPreferences.getLong(
SettingsFragment.KEY_PREF_DIARY_ALERT_TIME, ~0);
if (diaryReminderTime != ~0 ) {
Calendar diaryAlertTime = Calendar.getInstance();
diaryAlertTime.setTimeInMillis(diaryReminderTime);
// Get a calendar for today and set the time to the alarm time
Calendar alarmCalendar = Calendar.getInstance();
alarmCalendar.setTimeInMillis(System.currentTimeMillis());
alarmCalendar.set(Calendar.HOUR_OF_DAY, diaryAlertTime.get(Calendar.HOUR_OF_DAY));
alarmCalendar.set(Calendar.MINUTE, diaryAlertTime.get(Calendar.MINUTE));
// Compare with current time to see if the next alarm is today or tomorrow
Calendar nowCalendar = Calendar.getInstance();
nowCalendar.setTimeInMillis(System.currentTimeMillis());
long alarmTime = alarmCalendar.getTimeInMillis();
// If alarm time is earlier in the day...
if( alarmCalendar.getTimeInMillis() <= nowCalendar.getTimeInMillis() ){
// ...then check if we already had today's
long lastDiaryReminderTime = sharedPreferences.getLong(AlarmHandler.LAST_DIARY_NOTIFICATION_PREF, ~0);
if (lastDiaryReminderTime != ~0 && lastDiaryReminderTime != 0) {
Calendar lastAlertTime = Calendar.getInstance();
lastAlertTime.setTimeInMillis(lastDiaryReminderTime);
// If last alert was in same year and day of year...
if (lastAlertTime.get(Calendar.YEAR) == nowCalendar.get(Calendar.YEAR) &&
lastAlertTime.get(Calendar.DAY_OF_YEAR) == nowCalendar.get(Calendar.DAY_OF_YEAR)) {
// ...set for tomorrow by adding one day
alarmTime = alarmTime + AlarmManager.INTERVAL_DAY;
}
// Otherwise, leave as is because we haven't done one today and it will trigger immediately
}
else {
// don't know when the last one was so set for tomorrow by adding one day
alarmTime = alarmTime + AlarmManager.INTERVAL_DAY;
}
}
// Otherwise leave as is and it will trigger later today
// Create the alarm
if (android.os.Build.VERSION.SDK_INT < 19) {
alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, alarmIntent);
} else {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmTime, alarmIntent);
}
}
}
示例13: getGeneratedDelay
import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
* Returns the delay used to generate the last alarm. If no previous alarm was generated,
* return the base delay.
*/
public long getGeneratedDelay() {
SharedPreferences preferences = getSharedPreferences();
return preferences.getLong(PREFERENCE_DELAY, mBaseMilliseconds);
}
示例14: getFirstStartupDate
import android.content.SharedPreferences; //导入方法依赖的package包/类
private static long getFirstStartupDate(Context context) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
return sharedPreferences.getLong(PREF_FIRST_STARTUP_DATE, 0);
}
示例15: getLong
import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
* 获取long值
*
* @param context 上下文
* @param key 键
* @param defValue 默认值
* @return 保存的值
*/
public static long getLong(Context context, String key, long defValue) {
SharedPreferences sp = getSp(context);
return sp.getLong(key, defValue);
}