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:jp.co.ipublishing.esnavi.impl.user.UserClient.java

/**
 * GCMID??/*from w ww . jav  a  2  s  .c om*/
 *
 * @param context 
 * @return GCMID??????????????
 */
@NonNull
private static String getRegistrationId(@NonNull Context context) {
    final SharedPreferences prefs = getPreferences(context);
    final String registrationId = prefs.getString(PROPERTY_REG_ID, "");
    if (registrationId.isEmpty()) {
        Log.i(TAG, "Registration not found.");
        return "";
    }
    return registrationId;
}

From source file:com.google.android.apps.chrometophone.DeviceRegistrar.java

/**
 * Update the device to use GCM instead of C2DM.
 *//*from w  w w.  ja v a  2  s  .  c  om*/
static boolean updateC2DM(Context context) {
    SharedPreferences prefs = Prefs.get(context);
    String c2dmRegId = prefs.getString("deviceRegistrationID", null);
    // The old versions of the app that used C2DM stored the registration id in the default
    // preferences; the new version stores it in the GCM library.
    if (c2dmRegId != null) {
        Log.i(TAG, "Updating from C2DM to GCM");
        // Since the server will update the existing DeviceInfo entry to use GCM,
        // it's not necessary to call unregister
        GCMRegistrar.register(context, DeviceRegistrar.SENDER_ID);
        return true;
    } else {
        return false;
    }
}

From source file:Main.java

public static void writeCachedLocationSearchData(Context context, String recentData) {
    SharedPreferences cachePref = null;

    cachePref = context.getSharedPreferences(MOSTRECENT_LOCATIONSEARCH_SHARED_PREF, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = cachePref.edit();

    if (cachePref.getString(LOC1_KEY, null) == null) {
        editor.putString(LOC1_KEY, recentData);
    } else {/*from ww  w.  jav  a2 s  .c  om*/
        if (!cachePref.getString(LOC1_KEY, null).equalsIgnoreCase(recentData)) {
            editor.putString(LOC2_KEY, cachePref.getString(LOC1_KEY, ""));
            editor.putString(LOC1_KEY, recentData);
        }
    }
    editor.apply();
}

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

public static String loadInitialPersonEmail(Context context) {
    SharedPreferences prefs = context.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
    return prefs.getString(Constants.PREF_KEY_PERSON_INITIAL_EMAIL, null);
}

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

public static String loadInitialPersonUserName(Context context) {
    SharedPreferences prefs = context.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
    return prefs.getString(Constants.PREF_KEY_PERSON_INITIAL_USER_NAME, null);
}

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

public static String loadPersonEmail(Context context) {
    SharedPreferences prefs = context.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
    return prefs.getString(Constants.PREF_KEY_PERSON_EMAIL, null);
}

From source file:com.emacs.xpets.utils.Utils.java

public static String getBaseUrl(Context context) {
    String value = null;//from w  ww . ja  v a 2  s .  c o m
    if ((value = System.getProperty("BASE_URL")) == null) {
        SharedPreferences sp = context.getSharedPreferences("BASE_URL", Context.MODE_PRIVATE);
        value = sp.getString("BASE_URL", "http://www.xpets.net/api/");
        System.setProperty("BASE_URL", value);
    }

    return value;
}

From source file:net.mutil.util.HttpUtil.java

/**
 *  15//ww  w . ja  va  2 s  . co m
 * 
 * @param context
 * @return
 */
public static String getPageSize(Context context) {
    if (null == context) {
        return "15";
    }
    SharedPreferences sp = context.getSharedPreferences("PageSize", context.MODE_PRIVATE);
    return sp.getString("pagesize", "15");
}

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

private static HttpResponse makeRequestNoRetry(Context context, String deviceRegistrationID, String url,
        boolean newToken) throws Exception {
    // Get chosen user account
    SharedPreferences settings = Prefs.get(context);
    String accountName = settings.getString("accountName", null);
    if (accountName == null)
        throw new Exception("No account");

    // Get auth token for account
    Account account = new Account(accountName, "com.google");
    String authToken = getAuthToken(context, account);
    if (authToken == null) {
        throw new PendingAuthException(accountName);
    }/*from  w ww .jav  a  2 s.c  om*/
    if (newToken) {
        // Invalidate the cached token
        AccountManager accountManager = AccountManager.get(context);
        accountManager.invalidateAuthToken(account.type, authToken);
        authToken = getAuthToken(context, account);
    }

    // Register device with server
    DefaultHttpClient client = new DefaultHttpClient();
    String continueURL = url + "?devregid=" + deviceRegistrationID;
    URI uri = new URI(AUTH_URL + "?continue=" + URLEncoder.encode(continueURL, "UTF-8") + "&auth=" + authToken);
    HttpGet method = new HttpGet(uri);
    HttpResponse res = client.execute(method);
    return res;
}

From source file:io.kristal.appinfos.AppInfosPlugin.java

private synchronized static String getUniqueId(Context context) {
    String uniqueID = null;/*from  ww  w  . ja  v a2  s. c  o m*/
    SharedPreferences sharedPrefs = context.getSharedPreferences(PREF_UNIQUE_ID, Context.MODE_PRIVATE);
    uniqueID = sharedPrefs.getString(PREF_UNIQUE_ID, null);
    if (uniqueID == null) {
        uniqueID = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
        if (uniqueID == null || uniqueID.length() == 0 || "9774d56d682e549c".equals(uniqueID)) {
            // old version of reto meier
            //uniqueID = UUID.randomUUID().toString();
            uniqueID = "35" + //we make this look like a valid IMEI
                    Build.BOARD.length() % 10 + Build.BRAND.length() % 10 + Build.CPU_ABI.length() % 10
                    + Build.DEVICE.length() % 10 + Build.DISPLAY.length() % 10 + Build.HOST.length() % 10
                    + Build.ID.length() % 10 + Build.MANUFACTURER.length() % 10 + Build.MODEL.length() % 10
                    + Build.PRODUCT.length() % 10 + Build.TAGS.length() % 10 + Build.TYPE.length() % 10
                    + Build.USER.length() % 10; //13 digits
        }
        SharedPreferences.Editor editor = sharedPrefs.edit();
        editor.putString(PREF_UNIQUE_ID, uniqueID);
        editor.commit();
    }
    return uniqueID;
}