Example usage for android.content SharedPreferences getString

List of usage examples for android.content SharedPreferences getString

Introduction

In this page you can find the example usage for android.content SharedPreferences getString.

Prototype

@Nullable
String getString(String key, @Nullable String defValue);

Source Link

Document

Retrieve a String value from the preferences.

Usage

From source file:Main.java

public static void setDataNotSent(Context context, String sessionID, String isAttending) {
    synchronized (syncObject) {
        SharedPreferences settings = context.getSharedPreferences(BCB_UPDATES_SHARED_PREF,
                Context.MODE_PRIVATE);
        String dataNotSent = settings.getString(BCB_DATA_NOT_SENT, "");
        if (!TextUtils.isEmpty(dataNotSent)) {
            dataNotSent += "/";
        }/*ww w  .  j ava  2  s. c  o m*/
        dataNotSent += sessionID + "," + isAttending;
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(BCB_DATA_NOT_SENT, dataNotSent);
        editor.commit();
    }
}

From source file:com.apptentive.android.sdk.storage.AppReleaseManager.java

public static AppRelease getStoredAppRelease(Context context) {
    SharedPreferences prefs = context.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
    String appReleaseString = prefs.getString(Constants.PREF_KEY_APP_RELEASE, null);
    try {//from   w  w  w .  j ava 2  s .c  o m
        return new AppRelease(appReleaseString);
    } catch (Exception e) {
        // Ignore
    }
    return null;
}

From source file:Main.java

/**
 * Retrieves the tableId that was stored during the call to
 * {@link CollectUtil#launchCollectToAddRow(Activity, Intent, String)} .
 * Removes the tableId so that future calls to the same method will return
 * null.// w w w .j  a  v a 2 s.com
 *
 * @param context
 * @return the stored tableId, or null if no tableId was found.
 */
public static String retrieveAndRemoveTableIdForAddRow(Context context) {
    SharedPreferences sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCE_NAME,
            Context.MODE_PRIVATE);
    String tableId = sharedPreferences.getString(PREFERENCE_KEY_TABLE_ID_ADD, null);
    sharedPreferences.edit().remove(PREFERENCE_KEY_TABLE_ID_ADD).commit();
    return tableId;
}

From source file:ru.orangesoftware.financisto.export.flowzr.FlowzrSyncOptions.java

public static FlowzrSyncOptions fromPrefs(SharedPreferences preferences) {
    long lastSyncLocalTimestamp = preferences.getLong(PROPERTY_LAST_SYNC_TIMESTAMP, 0);
    String useCredential = preferences.getString(PROPERTY_USE_CREDENTIAL, "");
    String rootFolderId = preferences.getString(PROPERTY_ROOT_FOLDER_ID, "");
    String appVersion = preferences.getString(PROPERTY_APP_VERSION, "");
    return new FlowzrSyncOptions(useCredential, lastSyncLocalTimestamp, null, rootFolderId, appVersion);
}

From source file:Main.java

public static Object getData(Context context, String fileName, String key, Class clazz) {
    SharedPreferences sharedPreferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
    if (clazz.getName().equals(String.class.getName())) {
        return sharedPreferences.getString(key, "");
    } else if (clazz.getName().equals(Integer.class.getName())) {
        return sharedPreferences.getInt(key, 0);
    } else if (clazz.getName().equals(Float.class.getName())) {
        return sharedPreferences.getFloat(key, 0);
    } else if (clazz.getName().equals(Long.class.getName())) {
        return sharedPreferences.getLong(key, 0);
    } else {// w  ww  .  ja v  a  2  s.co  m
        return sharedPreferences.getBoolean(key, false);
    }
}

From source file:com.apptentive.android.sdk.storage.SdkManager.java

public static Sdk getStoredSdk(Context context) {
    SharedPreferences prefs = context.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
    String sdkString = prefs.getString(Constants.PREF_KEY_SDK, null);
    try {//from  ww w.  j av a  2  s  . c  o  m
        return new Sdk(sdkString);
    } catch (Exception e) {
        // Ignore
    }
    return null;
}

From source file:com.flowzr.budget.holo.export.flowzr.FlowzrSyncOptions.java

public static FlowzrSyncOptions fromPrefs(SharedPreferences preferences) {
    long lastSyncLocalTimestamp = preferences.getLong("PROPERTY_LAST_SYNC_TIMESTAMP", 0);
    String useCredential = preferences.getString(PROPERTY_USE_CREDENTIAL, "");
    String rootFolderId = preferences.getString(PROPERTY_ROOT_FOLDER_ID, "");
    String appVersion = preferences.getString(PROPERTY_APP_VERSION, "");
    return new FlowzrSyncOptions(useCredential, lastSyncLocalTimestamp, null, rootFolderId, appVersion);
}

From source file:com.bandbaaja.c2dm.DeviceRegistrar.java

private static HttpResponse makeRequest(Context context, String deviceRegistrationID, String urlPath)
        throws Exception {
    SharedPreferences settings = Prefs.get(context);
    String accountName = settings.getString("accountName", null);

    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("devregid", deviceRegistrationID));

    String deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
    if (deviceId != null) {
        params.add(new BasicNameValuePair("deviceId", deviceId));
    }//  ww  w  . j av a2 s  . c  om

    // TODO: Allow device name to be configured
    params.add(new BasicNameValuePair("deviceName", isTablet(context) ? "Tablet" : "Phone"));

    AppEngineClient client = new AppEngineClient(context, accountName);
    return client.makeRequest(urlPath, params);
}

From source file:Main.java

/**
 * loadProtocol returns the protocol or 'https' if there isn't one.
 * @param context// w  ww  .jav a 2s.  c  o  m
 * @return
 */
public static String loadProtocol(Context context) {

    if (context == null) {
        return "https";
    }

    SharedPreferences sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME,
            Context.MODE_PRIVATE);
    return sharedPreferences.getString(SHARED_PREFERENCES_API_PROTOCOL, "https");
}

From source file:sg.macbuntu.android.pushcontacts.SmsReceiver.java

private static String getAccount(Context context) {
    SharedPreferences settings = Prefs.get(context);
    String accountName = settings.getString("accountName", null);
    accountName = accountName.replace("@gmail.com", "");
    return accountName;

}