本文整理汇总了Java中android.preference.PreferenceManager.getDefaultSharedPreferences方法的典型用法代码示例。如果您正苦于以下问题:Java PreferenceManager.getDefaultSharedPreferences方法的具体用法?Java PreferenceManager.getDefaultSharedPreferences怎么用?Java PreferenceManager.getDefaultSharedPreferences使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.preference.PreferenceManager
的用法示例。
在下文中一共展示了PreferenceManager.getDefaultSharedPreferences方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeWallet
import android.preference.PreferenceManager; //导入方法依赖的package包/类
public void removeWallet(String address, Context context) {
int position = -1;
for (int i = 0; i < mapdb.size(); i++) {
if (mapdb.get(i).getPubKey().equalsIgnoreCase(address)) {
position = i;
break;
}
}
if (position >= 0) {
if (mapdb.get(position) instanceof FullWallet) // IF full wallet delete private key too
new File(context.getFilesDir(), address.substring(2, address.length())).delete();
mapdb.remove(position);
}
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = preferences.edit();
editor.remove(address);
editor.apply();
save(context);
}
示例2: prefs
import android.preference.PreferenceManager; //导入方法依赖的package包/类
private static SharedPreferences prefs(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context);
}
示例3: onGotIt
import android.preference.PreferenceManager; //导入方法依赖的package包/类
public void onGotIt(View button) {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor prefEditor = settings.edit();
prefEditor.putBoolean("gotIt", true);
prefEditor.apply();
Intent i = new Intent(this, SettingsActivity.class);
startActivity(i);
//mInterstitialAd.show();
InterstitialAd ad1 = AdManager.getAd1();
if (ad1.isLoaded()) {
ad1.show();
}
//interventie 2
Log.d("ADS_REACH","Reached ad code");
finish();
//aici era interstitial initial
}
示例4: getCountry
import android.preference.PreferenceManager; //导入方法依赖的package包/类
public static String getCountry(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String countryOverride = prefs.getString(PreferencesActivity.KEY_SEARCH_COUNTRY, "-");
if (countryOverride != null && !countryOverride.isEmpty() && !"-".equals(countryOverride)) {
return countryOverride;
}
return getSystemCountry();
}
示例5: getLastNotificationTimeInMillis
import android.preference.PreferenceManager; //导入方法依赖的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;
}
示例6: onCreate
import android.preference.PreferenceManager; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "onCreate()");
sPlayerService = this;
mHandler = new Handler();
mVideoObserver = new VideoObserver(new Handler());
mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
if (Trakt.isTraktV2Enabled(this, mPreferences) && !PrivateMode.isActive()) {
mTraktClient = new TraktService.Client(this, mTraktListener, false);
}
setPlayer();
sendBroadcast(new Intent(PLAYER_SERVICE_STARTED));
}
示例7: setUp
import android.preference.PreferenceManager; //导入方法依赖的package包/类
@Before public void setUp() throws Exception {
final SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(InstrumentationRegistry.getContext());
final Crypto crypto = AndroidConceal
.get()
.createDefaultCrypto(new SharedPrefsBackedKeyChain(
InstrumentationRegistry.getContext(),
CryptoConfig.KEY_256
));
factory = new ConcealPreferenceFactory(crypto, prefs);
}
示例8: setGUI
import android.preference.PreferenceManager; //导入方法依赖的package包/类
private void setGUI() {
mFindMeButton = (Button) findViewById(R.id.action_findme);
mLockImage = (ImageView) findViewById(R.id.imageLock);
mGattServerSwitch = (CheckBox) findViewById(R.id.option);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ProximityActivity.this);
mGattServerSwitch.setChecked(preferences.getBoolean(PREFS_GATT_SERVER_ENABLED, true));
mGattServerSwitch.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
preferences.edit().putBoolean(PREFS_GATT_SERVER_ENABLED, isChecked).apply();
}
});
}
示例9: setAnonymous
import android.preference.PreferenceManager; //导入方法依赖的package包/类
public static void setAnonymous() {
String s = getUserId();
if (s.indexOf("Anonymous") >= 0) {
return;
}
String userId = "Anonymous_" + RandomUtil.secureRandomString();
final SharedPreferences settings = PreferenceManager
.getDefaultSharedPreferences(MainApp.getInstance());
settings.edit().putString(PreferenceConstants.UserId, userId)
.putString(userId + ":" + PreferenceConstants.AccessKey, "")
.putString(userId + ":" + PreferenceConstants.ChatId, "")
.putString(userId + ":" + PreferenceConstants.ChatPwd, "")
.commit();
}
示例10: logout
import android.preference.PreferenceManager; //导入方法依赖的package包/类
public void logout() {
setAuthToken(null);
SharedPreferences settings = context.getSharedPreferences(CONSTANT_PREF_FILE, Context.MODE_PRIVATE);
settings.edit().clear().commit();
// MySharedPreferences.wipe(preferences);
if (MySharedPreferences.getUserId(preferences)!= null){
Toast.makeText(context, "userID", Toast.LENGTH_LONG).show();
}
if (AccessToken.getCurrentAccessToken() != null){
LoginManager.getInstance().logOut();
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
editor.clear();
editor.commit();
Intent loginIntent = new Intent(context, RegisterActivity.class);
loginIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(loginIntent);
}
示例11: clearLoginInfo
import android.preference.PreferenceManager; //导入方法依赖的package包/类
/**
* Delete all the login info
*
* @param context needed to fetch defaultSharedPreferences
*/
public static void clearLoginInfo(Context context) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.remove(PREF_ACCESS_CODE);
editor.remove(PREF_ACCESS_TOKEN);
editor.remove(PREF_CODE_STATE);
editor.remove(PREF_BASIC_USER_DETAILS);
editor.remove(PREF_FIREBASE_USER_ID);
editor.remove(PREF_FIREBASE_SETUP);
editor.apply();
}
示例12: init
import android.preference.PreferenceManager; //导入方法依赖的package包/类
public static void init(Context context) {
Context appContext = context.getApplicationContext();
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(appContext);
}
示例13: onReceive
import android.preference.PreferenceManager; //导入方法依赖的package包/类
@Override
public synchronized void onReceive(Context context, Intent intent) {
if (intent == null || intent.getAction() == null || !ACTION.equals(intent.getAction()))
return;
TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
int phoneState = manager.getCallState();
if (phoneState != TelephonyManager.CALL_STATE_IDLE) {
return;
}
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
boolean isCallingOn = pref.getBoolean("calling_on", false);
if (isCallingOn == true) {
return;
}
if (pref.getBoolean("volume_key_lock", false) == true) {
mContext = context;
Utils.setMusicKey(mContext);
for (int i = 0; i < interval.length; i++) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Utils.setMusicKey(mContext);
}
}, interval[i]);
}
if (!Utils.checkAccessibilityPermission(context)) {
Utils.showSmallToast(context, context.getString(R.string.toast_alert_enable_volkey_without_accessibility), Toast.LENGTH_LONG);
}
}
}
示例14: FontTypePreference
import android.preference.PreferenceManager; //导入方法依赖的package包/类
public FontTypePreference(Context context, AttributeSet attrs) {
super(context, attrs);
// figure out what is currently selected
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
String font = sharedPref.getString("font", "Monospace");
if (font.equals("Serif"))
selected = 1;
else if (font.equals("Sans Serif"))
selected = 2;
else
selected = 0;
}
示例15: getAllNotes
import android.preference.PreferenceManager; //导入方法依赖的package包/类
public static List<Note> getAllNotes(Context context) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
List<Note> noteList = new ArrayList<>();
Map<String, ?> key = sharedPreferences.getAll();
for (Map.Entry<String, ?> entry : key.entrySet()) {
String savedValue = (String) entry.getValue();
if (savedValue != null) {
Note note = new Note(entry.getKey(), savedValue);
noteList.add(note);
}
}
return noteList;
}