当前位置: 首页>>代码示例>>Java>>正文


Java SharedPreferences.getLong方法代码示例

本文整理汇总了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;
}
 
开发者ID:Loofer,项目名称:Watermark,代码行数:22,代码来源:SPUtils.java

示例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;
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:28,代码来源:SunshinePreferences.java

示例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();
       }
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:21,代码来源:ApnControl.java

示例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;
}
 
开发者ID:miLLlulei,项目名称:Accessibility,代码行数:21,代码来源:SPUtils.java

示例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;
}
 
开发者ID:Webtrekk,项目名称:webtrekk-android-sdk,代码行数:18,代码来源:WebtrekkUserParameters.java

示例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;
    }
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:36,代码来源:ServerUtilities.java

示例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));
    }
}
 
开发者ID:ericberman,项目名称:MyFlightbookAndroid,代码行数:13,代码来源:ActNewFlight.java

示例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;
}
 
开发者ID:BaoBaoJianqiang,项目名称:HybridForAndroid,代码行数:16,代码来源:SpUtils.java

示例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;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:5,代码来源:MultiDexExtractor.java

示例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);
}
 
开发者ID:jopenbox,项目名称:android-lite-utils,代码行数:5,代码来源:SPUtils.java

示例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);
}
 
开发者ID:chashmeetsingh,项目名称:TrackIt-Android,代码行数:5,代码来源:DataHelper.java

示例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);
        }
    }
}
 
开发者ID:jgevans,项目名称:TherapyGuide,代码行数:58,代码来源:AlarmSetter.java

示例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);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:9,代码来源:ExponentialBackoffScheduler.java

示例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);
}
 
开发者ID:elimu-ai,项目名称:start-guide,代码行数:5,代码来源:StartPrefsHelper.java

示例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);
}
 
开发者ID:markchylshow,项目名称:Shopping_car_Demo,代码行数:13,代码来源:SPUtils.java


注:本文中的android.content.SharedPreferences.getLong方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。