本文整理汇总了C#中Android.Content.Context.GetSharedPreferences方法的典型用法代码示例。如果您正苦于以下问题:C# Context.GetSharedPreferences方法的具体用法?C# Context.GetSharedPreferences怎么用?C# Context.GetSharedPreferences使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Content.Context
的用法示例。
在下文中一共展示了Context.GetSharedPreferences方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: JPushUtil
public JPushUtil (Context _context)
{
context = _context;
handler = new Handler(DealMessage);
//或得共享实例变量
sp_userinfo = context.GetSharedPreferences(Global.SHAREDPREFERENCES_USERINFO,FileCreationMode.Private);
sp_jpushInfo = context.GetSharedPreferences (Global.SHAREDPREFERENCES_JPUSH, FileCreationMode.Private);
}
示例2: OnReceive
public override void OnReceive(Context context, Intent intent)
{
PowerManager pm = (PowerManager)context.GetSystemService(Context.PowerService);
PowerManager.WakeLock w1 = pm.NewWakeLock (WakeLockFlags.Full | WakeLockFlags.AcquireCausesWakeup | WakeLockFlags.OnAfterRelease, "NotificationReceiver");
w1.Acquire ();
//Toast.MakeText (context, "Received intent!", ToastLength.Short).Show ();
var nMgr = (NotificationManager)context.GetSystemService (Context.NotificationService);
//var notification = new Notification (Resource.Drawable.Icon, context.Resources.GetString(Resource.String.ReminderTitle));
var notification = new Notification (Resource.Drawable.Icon, context.Resources.GetString(Resource.String.ReminderTitle));
//Clicking the pending intent does not go to the Home Activity Screen, but to the last activity that was active before leaving the app
var pendingIntent = PendingIntent.GetActivity (context, 0, new Intent (context, typeof(Home)), PendingIntentFlags.UpdateCurrent);
//Notification should be language specific
notification.SetLatestEventInfo (context, context.Resources.GetString(Resource.String.ReminderTitle), context.Resources.GetString(Resource.String.InvalidationText), pendingIntent);
notification.Flags |= NotificationFlags.AutoCancel;
nMgr.Notify (0, notification);
// Vibrator vibrator = (Vibrator) context.GetSystemService(Context.VibratorService);
// if (vibrator != null)
// vibrator.Vibrate(400);
//change shared preferences such that the questionnaire button can change its availability
ISharedPreferences sharedPref = context.GetSharedPreferences("com.FSoft.are_u_ok.PREFERENCES",FileCreationMode.Private);
ISharedPreferencesEditor editor = sharedPref.Edit();
editor.PutBoolean("QuestionnaireActive", false );
editor.Commit ();
//insert a line of -1 into some DB values to indicate that the questions have not been answered at the scheduled time
MoodDatabase dbMood = new MoodDatabase(context);
ContentValues insertValues = new ContentValues();
insertValues.Put("date", DateTime.Now.ToString("dd.MM.yy"));
insertValues.Put("time", DateTime.Now.ToString("HH:mm"));
insertValues.Put("mood", -1);
insertValues.Put("people", -1);
insertValues.Put("what", -1);
insertValues.Put("location", -1);
//use the old value of questionFlags
Android.Database.ICursor cursor;
cursor = dbMood.ReadableDatabase.RawQuery("SELECT date, QuestionFlags FROM MoodData WHERE date = '" + DateTime.Now.ToString("dd.MM.yy") + "'", null); // cursor query
int alreadyAsked = 0; //default value: no questions have been asked yet
if (cursor.Count > 0) { //data was already saved today and questions have been asked, so retrieve which ones have been asked
cursor.MoveToLast (); //take the last entry of today
alreadyAsked = cursor.GetInt(cursor.GetColumnIndex("QuestionFlags")); //retrieve value from last entry in db column QuestionFlags
}
insertValues.Put("QuestionFlags", alreadyAsked);
dbMood.WritableDatabase.Insert ("MoodData", null, insertValues);
//set the new alarm
AlarmReceiverQuestionnaire temp = new AlarmReceiverQuestionnaire();
temp.SetAlarm(context);
w1.Release ();
//check these pages for really waking up the device
// http://stackoverflow.com/questions/6864712/android-alarmmanager-not-waking-phone-up
// https://forums.xamarin.com/discussion/7490/alarm-manager
//it's good to use the alarm manager for tasks that should last even days:
// http://stackoverflow.com/questions/14376470/scheduling-recurring-task-in-android/
}
示例3: GetRegistrationId
public static string GetRegistrationId(Context context)
{
var result = string.Empty;
//Get the shared pref for c2dmsharp, and read the registration id
var prefs = context.GetSharedPreferences("c2dmsharp", FileCreationMode.Private);
result = prefs.GetString("registration_id", string.Empty);
return result;
}
示例4: GetUserFromPreferences
public static MySqlUser GetUserFromPreferences(Context context)
{
ISharedPreferences prefs = context.GetSharedPreferences("userinformation", FileCreationMode.Private);
return new MySqlUser(prefs.GetInt("idUser", 0),
prefs.GetString("name", ""),
prefs.GetString("role", ""),
prefs.GetString("password", ""),
prefs.GetInt("number", 0),
prefs.GetString("position", ""));
}
示例5: SaveUserPreferences
public static UserMobile SaveUserPreferences(Context context, UserMobile user)
{
SettingsMobile.Instance.User = user;
ISharedPreferences prefs = context.GetSharedPreferences(RDNationSettingsString, FileCreationMode.WorldReadable);
ISharedPreferencesEditor editor = prefs.Edit();
string s = Json.ConvertToString<UserMobile>(user);
editor.PutString(UserMobileKey, s);
editor.Commit();
return user;
}
示例6: StoreUserInPreferences
public void StoreUserInPreferences(Context context, MySqlUser user)
{
ISharedPreferences prefs = context.GetSharedPreferences("userinformation", FileCreationMode.Private);
ISharedPreferencesEditor editor = prefs.Edit();
editor.PutInt("idUser", user.idUser);
editor.PutString("name", user.name);
editor.PutString("role", user.role);
editor.PutString("password", user.password);
editor.PutInt("number", user.number);
editor.PutString("position", user.position);
editor.Commit();
}
示例7: connectivity
public connectivity(Context c)
{
Singleton = this;
AppContext = c;
if (Singleton == null)
{
Singleton = this;
}
MessageEvents = new UIChangedEvent();
prefs = c.GetSharedPreferences("ConPrefs", FileCreationMode.Private);
}
示例8: MojioClient
public MojioClient(Context context, Guid appId, Guid secretKey, string Url = Live)
: this(Url)
{
CurrentContext = context;
var preferences = context.GetSharedPreferences(SharedPreferencesName, FileCreationMode.Private);
if (preferences.Contains(TokenPreferenceName))
{
var token = preferences.GetString(TokenPreferenceName, null);
TokenId = new Guid(token);
Begin(appId, secretKey, TokenId);
}
else
Begin(appId, secretKey);
var edits = preferences.Edit();
edits.PutString(TokenPreferenceName, Token.Id.ToString());
edits.Commit ();
}
示例9: OnReceive
public override void OnReceive ( Context context, Intent intent )
{
var alarmManager = (AlarmManager) context.GetSystemService (Context.AlarmService);
var intentTracker = new Intent (context, typeof (LokTrackerAlarmReceiver));
var intentPending = PendingIntent.GetBroadcast (context, 0, intentTracker, 0);
var prefs = context.GetSharedPreferences ("lok", 0);
var intervalMinute = prefs.GetInt ("interval", 1);
var currentlyTracking = prefs.GetBoolean ("currentlyTracking", false);
if (currentlyTracking)
alarmManager.SetRepeating (
AlarmType.ElapsedRealtimeWakeup,
SystemClock.ElapsedRealtime (),
intervalMinute * 60000,
intentPending);
else
alarmManager.Cancel (intentPending);
}
示例10: DeviceUuidFactory
public DeviceUuidFactory(Context context)
{
if (uuid == null)
{
lock (_lock)
{
if (uuid == null)
{
var prefs = context.GetSharedPreferences(PREFS_FILE, FileCreationMode.Private);
var id = prefs.GetString(PREFS_DEVICE_ID, null);
if (!string.IsNullOrWhiteSpace(id))
{
// Use the ids previously computed and stored in the prefs file
uuid = UUID.FromString(id);
}
else
{
var androidId = Settings.Secure.GetString(context.ContentResolver, Settings.Secure.AndroidId);
// Use the Android ID unless it's broken, in which case fallback on deviceId,
// unless it's not available, then fallback on a random number which we store
// to a prefs file
if ("9774d56d682e549c" == androidId)
{
//Generate a new UUID rather than require READ_PHONE_STATE
var c = new Java.Lang.String(androidId);
uuid = UUID.NameUUIDFromBytes(c.GetBytes("utf8"));
}
else
{
uuid = UUID.RandomUUID();
}
prefs.Edit().PutString(PREFS_DEVICE_ID, uuid.ToString()).Apply();
}
}
}
}
}
示例11: OnReceive
public override void OnReceive(Context context, Intent intent)
{
PowerManager pm = (PowerManager)context.GetSystemService(Context.PowerService);
PowerManager.WakeLock w1 = pm.NewWakeLock (WakeLockFlags.Full | WakeLockFlags.AcquireCausesWakeup | WakeLockFlags.OnAfterRelease, "NotificationReceiver");
w1.Acquire ();
//Toast.MakeText (context, "Received intent!", ToastLength.Short).Show ();
var nMgr = (NotificationManager)context.GetSystemService (Context.NotificationService);
var notification = new Notification (Resource.Drawable.Icon, context.Resources.GetString(Resource.String.ReminderTitle));
//Clicking the pending intent does not go to the Home Activity Screen, but to the last activity that was active before leaving the app
var pendingIntent = PendingIntent.GetActivity (context, 0, new Intent (context, typeof(Home)), PendingIntentFlags.UpdateCurrent);
//Notification should be language specific
notification.SetLatestEventInfo (context, context.Resources.GetString(Resource.String.ReminderTitle), context.Resources.GetString(Resource.String.ReminderText), pendingIntent);
notification.Flags |= NotificationFlags.AutoCancel;
nMgr.Notify (0, notification);
Vibrator vibrator = (Vibrator) context.GetSystemService(Context.VibratorService);
if (vibrator != null)
vibrator.Vibrate(400);
//change shared preferences such that the questionnaire button can change its availability
ISharedPreferences sharedPref = context.GetSharedPreferences("com.FSoft.are_u_ok.PREFERENCES",FileCreationMode.Private);
ISharedPreferencesEditor editor = sharedPref.Edit();
editor.PutBoolean("QuestionnaireActive", true );
editor.Commit ();
//start an new alarm here for the invalidation period
//Call setAlarm in the Receiver class
AlarmReceiverInvalid temp = new AlarmReceiverInvalid();
temp.SetAlarm (context); //call it with the context of the activity
w1.Release ();
//check these pages for really waking up the device
// http://stackoverflow.com/questions/6864712/android-alarmmanager-not-waking-phone-up
// https://forums.xamarin.com/discussion/7490/alarm-manager
//it's good to use the alarm manager for tasks that should last even days:
// http://stackoverflow.com/questions/14376470/scheduling-recurring-task-in-android/
}
示例12: GetUserPreferences
public static UserMobile GetUserPreferences(Context context)
{
if (SettingsMobile.Instance.User == null)
{
// this is an Activity
ISharedPreferences prefs = context.GetSharedPreferences(RDNationSettingsString, FileCreationMode.WorldReadable);
//ISharedPreferencesEditor editor = prefs.Edit();
var s = prefs.GetString(UserMobileKey, String.Empty);
if (!String.IsNullOrEmpty(s))
{
SettingsMobile.Instance.User = Json.DeserializeObject<UserMobile>(s);
}
else
{
SettingsMobile.Instance.User = new UserMobile() { IsLoggedIn = false };
}
// editor.PutInt(("number_of_times_accessed", accessCount++);
//editor.PutString("date_last_accessed", DateTime.Now.ToString("yyyy-MMM-dd"));
//editor.Apply();
}
return SettingsMobile.Instance.User;
}
示例13: SetComputeInstalledApps
public static void SetComputeInstalledApps(Context context, Dictionary<String, int> apps)
{
ISharedPreferences prefs = context.GetSharedPreferences(context.PackageName, FileCreationMode.Private);
prefs.Edit().PutString("InstalledComputeApps", JsonConvert.SerializeObject(apps)).Commit();
}
示例14: ServerManagedPolicy
/// <summary>
/// Initializes a new instance of the <see cref="ServerManagedPolicy"/> class.
/// The server managed policy.
/// </summary>
/// <param name="context">
/// The context for the current application
/// </param>
/// <param name="obfuscator">
/// An obfuscator to be used with preferences.
/// </param>
public ServerManagedPolicy(Context context, IObfuscator obfuscator)
{
// Import old values
ISharedPreferences sp = context.GetSharedPreferences(PrefsFile, FileCreationMode.Private);
this.preferences = new PreferenceObfuscator(sp, obfuscator);
string lastResponse = this.preferences.GetString(
PrefLastResponse, ((int)PolicyServerResponse.Retry).ToString());
this.LastResponse = (PolicyServerResponse)Enum.Parse(typeof(PolicyServerResponse), lastResponse);
this.ValidityTimestamp =
long.Parse(this.preferences.GetString(PrefValidityTimestamp, DefaultValidityTimestamp));
this.RetryUntil = long.Parse(this.preferences.GetString(PrefRetryUntil, DefaultRetryUntil));
this.MaxRetries = long.Parse(this.preferences.GetString(PrefMaxRetries, DefaultMaxRetries));
this.RetryCount = long.Parse(this.preferences.GetString(PrefRetryCount, DefaultRetryCount));
}
示例15: DroidSimpleStorage
public DroidSimpleStorage(string groupName, Context context)
: base(groupName)
{
Prefs = context.GetSharedPreferences(groupName, FileCreationMode.Private);
}