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


Java SharedPreferences.getString方法代码示例

本文整理汇总了Java中android.content.SharedPreferences.getString方法的典型用法代码示例。如果您正苦于以下问题:Java SharedPreferences.getString方法的具体用法?Java SharedPreferences.getString怎么用?Java SharedPreferences.getString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.SharedPreferences的用法示例。


在下文中一共展示了SharedPreferences.getString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: tryGetAccessToken

import android.content.SharedPreferences; //导入方法依赖的package包/类
public static String tryGetAccessToken(Context ctx, String hostPackage, ArrayList<String> scopes) {
	
	if (TextUtils.isEmpty(hostPackage))
	{
		Log.d(_tag, "hostPackage is empty!");
		return null;
	}
	Log.d(_tag, "trying to find prefs for "+hostPackage);
	SharedPreferences prefs = getPrefsForHost(ctx, hostPackage);
	String scopesString = prefs.getString(PREF_KEY_SCOPE, "");
	Log.d(_tag, "available scopes: "+ scopesString);
	ArrayList<String> currentScope = stringToStringArray(scopesString);
	if (isSubset(scopes, currentScope))
	{
		return prefs.getString(PREF_KEY_TOKEN, null);
	}
	else
	{
		Log.d(_tag, "looks like scope changed. Access token invalid.");
		return null;
	}
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:23,代码来源:AccessManager.java

示例2: isMetric

import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
 * Returns true if the user has selected metric temperature display.
 *
 * @param context Context used to get the SharedPreferences
 * @return true if metric display should be used, false if imperial display should be used
 */
public static boolean isMetric(Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);

    String keyForUnits = context.getString(R.string.pref_units_key);
    String defaultUnits = context.getString(R.string.pref_units_metric);
    String preferredUnits = sp.getString(keyForUnits, defaultUnits);
    String metric = context.getString(R.string.pref_units_metric);

    boolean userPrefersMetric = false;
    if (metric.equals(preferredUnits)) {
        userPrefersMetric = true;
    }

    return userPrefersMetric;
}
 
开发者ID:changja88,项目名称:Android_Sunshine_Watch,代码行数:22,代码来源:SunshinePreferences.java

示例3: onCreatePreferences

import android.content.SharedPreferences; //导入方法依赖的package包/类
@Override
public void onCreatePreferences(Bundle bundle, String s) {
    // Add 'general' preferences, defined in the XML file
    addPreferencesFromResource(R.xml.pref_general);

    SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
    PreferenceScreen prefScreen = getPreferenceScreen();
    int count = prefScreen.getPreferenceCount();
    for (int i = 0; i < count; i++) {
        Preference p = prefScreen.getPreference(i);
        if (!(p instanceof CheckBoxPreference)) {
            String value = sharedPreferences.getString(p.getKey(), "");
            setPreferenceSummary(p, value);
        }
    }
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:17,代码来源:SettingsFragment.java

示例4: onSharedPreferenceChanged

import android.content.SharedPreferences; //导入方法依赖的package包/类
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    //get the preference that was changed
    Preference preference = findPreference(key);

    // Updates the summary for the preference if is not null
    if (null != preference) {
        // You don't need to set up preference summaries for checkbox preferences because
        // they are already set up in xml using summaryOff and summary On
        if (!(preference instanceof CheckBoxPreference) && !(preference instanceof MultiSelectListPreference)) {
            String value = sharedPreferences.getString(preference.getKey(), "");
            setPreferenceSummary(preference, value);
        }
    }
}
 
开发者ID:Jugendhackt,项目名称:Camera-warner,代码行数:16,代码来源:SettingsFragment.java

示例5: sendNotification

import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
 * 发送通知
 */
private void sendNotification(List<TodoEvent> todoEventList) {
    SharedPreferences setting = PreferenceManager.getDefaultSharedPreferences(this);

    if (setting.getBoolean(Consts.NOTIFICATION_KEY, false)) {
        Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH) + 1;
        int day = c.get(Calendar.DAY_OF_MONTH);
        StringBuilder builder;
        if (day<10){
            builder = new StringBuilder().append(year+"年"+month+"月"+"0"+day+"日");
        }else{
            builder = new StringBuilder().append(year+"年"+month+"月"+day+"日");
        }
        String dayString = builder.toString();
        int eventCount = 0;
        boolean vibrate = setting.getBoolean(Consts.VIBRATE_KEY, false);
        String ringtoneName = setting.getString("ringtoneName", "");
        if (ringtoneName.startsWith("默认铃声 (")&&ringtoneName.endsWith(")"))
            ringtoneName = ringtoneName.replace("默认铃声 (","").replace(")","");

        for (TodoEvent event : todoEventList) {
            if (event.getEventDate().equals(dayString)) {
                eventCount++;
            }
        }

        Intent i = new Intent(INTENT_EVENT);
        i.putExtra("event_num", eventCount);
        i.putExtra("vibrate", vibrate);
        i.putExtra("ringtoneName", ringtoneName);
        PendingIntent pi = PendingIntent.getBroadcast(this, 777, i, 0);
        AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
        am.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), pi);
    }

}
 
开发者ID:wendyltan,项目名称:EasyTodo,代码行数:41,代码来源:MainActivity.java

示例6: loadOtherLanguages

import android.content.SharedPreferences; //导入方法依赖的package包/类
private void loadOtherLanguages() {
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("langconfig", Activity.MODE_PRIVATE);
    String locales = preferences.getString("locales", null);
    if (locales == null || locales.length() == 0) {
        return;
    }
    String[] localesArr = locales.split("&");
    for (String locale : localesArr) {
        LocaleInfo localeInfo = LocaleInfo.createWithString(locale);
        if (localeInfo != null) {
            otherLanguages.add(localeInfo);
        }
    }
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:15,代码来源:LocaleController.java

示例7: isTV

import android.content.SharedPreferences; //导入方法依赖的package包/类
public static boolean isTV(Context ct){
    SharedPreferences mPreferences = PreferenceManager.getDefaultSharedPreferences(ct);
    String mode = mPreferences.getString("uimode", "0");
    if (mode.equals("1"))
        return false;
    if (mode.equals("2"))
        return true;
    return ArchosFeatures.isTV(ct);
}
 
开发者ID:archos-sa,项目名称:aos-Video,代码行数:10,代码来源:TVUtils.java

示例8: getUsage

import android.content.SharedPreferences; //导入方法依赖的package包/类
private void getUsage(int uid, String restrictionName, String methodName, MatrixCursor cursor) {
	SharedPreferences prefs = getContext().getSharedPreferences(PREF_USAGE + "." + restrictionName,
			Context.MODE_PRIVATE);
	String values = prefs.getString(getUsagePref(uid, methodName), null);
	if (values != null) {
		String[] value = values.split(":");
		long timeStamp = Long.parseLong(value[0]);
		boolean restricted = Boolean.parseBoolean(value[1]);
		cursor.addRow(new Object[] { uid, restrictionName, methodName, restricted, timeStamp });
	}
}
 
开发者ID:ukanth,项目名称:XPrivacy,代码行数:12,代码来源:PrivacyProvider.java

示例9: updateWheelSizeSummary

import android.content.SharedPreferences; //导入方法依赖的package包/类
private void updateWheelSizeSummary() {
	final PreferenceScreen screen = getPreferenceScreen();
	final SharedPreferences preferences = getPreferenceManager().getSharedPreferences();

	final String value = preferences.getString(SETTINGS_WHEEL_SIZE, String.valueOf(SETTINGS_WHEEL_SIZE_DEFAULT));
	screen.findPreference(SETTINGS_WHEEL_SIZE).setSummary(getString(R.string.csc_settings_wheel_diameter_summary, value));
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:8,代码来源:SettingsFragment.java

示例10: onCreate

import android.content.SharedPreferences; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_registername);

    tbName = (EditText)findViewById(R.id.tbName);
    tbEmail = (EditText)findViewById(R.id.tbEmail);
    btnNext = (ImageButton)findViewById(R.id.btnNext);
    imgSelected = (ImageView)findViewById(R.id.imgSelected);

    SharedPreferences srpef = getSharedPreferences("UserInfo",Context.MODE_PRIVATE);
    SharedPreferences.Editor edit = srpef.edit();
    String pic = srpef.getString("pic","");
    if(pic.equals("male"))
        imgSelected.setImageResource(R.drawable.male);
    else if(pic.equals("female"))
        imgSelected.setImageResource(R.drawable.female);


    btnNext.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            SharedPreferences sharedPreferences = getSharedPreferences("UserInfo", Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPreferences.edit();

            editor.putString("name", tbName.getText().toString());
            editor.putString("email",tbEmail.getText().toString());
            editor.commit();

            Toast.makeText(getApplicationContext(),"Name & Email Set", Toast.LENGTH_LONG).show();
            Intent intent = new Intent(getApplicationContext(),RegisterGenPassActivity.class);
            startActivity(intent);
        }
    });



}
 
开发者ID:mysterious-29,项目名称:FileCrypt,代码行数:40,代码来源:RegisterSetNameActivity.java

示例11: retrieve

import android.content.SharedPreferences; //导入方法依赖的package包/类
private static byte[] retrieve(Context context, String key) throws IOException {
  SharedPreferences settings = context.getSharedPreferences(PREFERENCES_NAME, 0);
  String encodedValue        = settings.getString(key, "");

  if (TextUtils.isEmpty(encodedValue)) return null;
  else                                 return Base64.decode(encodedValue);
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:8,代码来源:MasterSecretUtil.java

示例12: getPassword

import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
 * Retourne le mot de passe enregistré dans les préférences.
 *
 * @param context Le contexte
 * @return La valeur ou NULL
 */
@Nullable
public static String getPassword(
    @NonNull Context context
) {
  SharedPreferences prefs = getSharedPreferences(context);
  try {
    return prefs.getString(PASSWORD, null);
  } catch (Exception e) {
    setPassword(context, null);
    return null;
  }
}
 
开发者ID:goutfeb,项目名称:ElephantAsia,代码行数:19,代码来源:Preferences.java

示例13: setDefaults

import android.content.SharedPreferences; //导入方法依赖的package包/类
private void setDefaults(SharedPreferences p)
{
	SharedPreferences.Editor e = p.edit();
	if(p.getString(PREF_DEFAULT_NICK, null) == null)
		e.putString(PREF_DEFAULT_NICK, "BananaPeel");
	if(p.getString(PREF_DEFAULT_NICK_ALT, null) == null)
		e.putString(PREF_DEFAULT_NICK_ALT, "BananaPeel_");
	if(p.getString(PREF_DEFAULT_USER, null) == null)
		e.putString(PREF_DEFAULT_USER, "android");
	if(p.getString(PREF_DEFAULT_REAL_NAME, null) == null)
		e.putString(PREF_DEFAULT_REAL_NAME, "Banana Peel");
	e.apply();
}
 
开发者ID:mniip,项目名称:bananapeel,代码行数:14,代码来源:IRCPreferences.java

示例14: run

import android.content.SharedPreferences; //导入方法依赖的package包/类
@Override
public void run() {
    try {
        Bundle extras = getIntent().getExtras();
        PublicKey pubKey = (PublicKey) extras.get("pubKey");

        // Get elections
        SharedPreferences sharedPrefs = getSharedPreferences(getString(R.string.shared_preferences_file), Context.MODE_PRIVATE);
        Gson gson = new Gson();
        String json = sharedPrefs.getString(getString(R.string.shared_preferences_key_election), "");
        Asset mcAsset = gson.fromJson(json, Election.class).getAsset();

        // Set address to app bar and click listener.
        BlockChain bc = BlockChain.getInstance(null);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setSubtitle("Address: " + bc.getAddress(pubKey).toString());
        }
        setAddressClickListener(bc.getAddress(pubKey).toString());

        // Load transactions
        final List<TransactionHistoryItem> transactions = bc.getMyTransactions(pubKey, mcAsset);
        Collections.sort(transactions); //sort transactions desc on date
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
            findViewById(R.id.loading_circle).setVisibility(View.GONE);
            if (transactions.size() > 0) {
                adapter.addAll(transactions);
                adapter.notifyDataSetChanged();
            } else {
                findViewById(R.id.no_transactions).setVisibility(View.VISIBLE);
            }
            }
        });

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:digital-voting-pass,项目名称:polling-station-app,代码行数:40,代码来源:TransactionHistoryActivity.java

示例15: getProfile

import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
 * Gets an instance of the user's own profile in order to assign username to comments added
 */
private void getProfile(){
    Context context = FollowedEventActivity.this;
    final SharedPreferences reader = context.getSharedPreferences(MY_PREFERENCES,Context.MODE_PRIVATE);
    final String userId = reader.getString("userId","");
    ElasticSearchController.GetProfileTask getProfileTask
            = new ElasticSearchController.GetProfileTask();
    getProfileTask.execute(userId);
    try {
        me = getProfileTask.get();
    } catch (Exception e) {
        Log.i("Error", "Failed to get profiles with id " + userId + " from async object");
    }
}
 
开发者ID:CMPUT301F17T09,项目名称:GoalsAndHabits,代码行数:17,代码来源:FollowedEventActivity.java


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