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


C# Context.GetSharedPreferences方法代码示例

本文整理汇总了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);
		}
开发者ID:lq-ever,项目名称:CommunityCenter,代码行数:8,代码来源:JPushUtil.cs

示例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/
        }
开发者ID:fsoyka,项目名称:RUOK,代码行数:60,代码来源:AlarmReceiverInvalid.cs

示例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;
        }
开发者ID:nuttapol,项目名称:PushSharp,代码行数:10,代码来源:C2dmClient.cs

示例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", ""));
 }
开发者ID:MxPtrs,项目名称:Karlsfeld-Volleyball-App,代码行数:10,代码来源:MySqlUser.cs

示例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;
 }
开发者ID:mukhtiarlander,项目名称:git_demo_torit,代码行数:10,代码来源:Settings.cs

示例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();
 }
开发者ID:MxPtrs,项目名称:Karlsfeld-Volleyball-App,代码行数:12,代码来源:MySqlUser.cs

示例7: connectivity

        public connectivity(Context c)
        {
            Singleton = this;
            AppContext = c;

            if (Singleton == null)
            {
                Singleton = this;
            }

            MessageEvents = new UIChangedEvent();

            prefs = c.GetSharedPreferences("ConPrefs", FileCreationMode.Private);
        }
开发者ID:nodoid,项目名称:network-connection,代码行数:14,代码来源:Singleton.cs

示例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 ();
        }
开发者ID:gao1183,项目名称:Mojio.Client,代码行数:19,代码来源:MojioClient.AndroidGcm.cs

示例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);
        }
开发者ID:ibnuda,项目名称:Lok,代码行数:19,代码来源:LokTrackerBootReceiver.cs

示例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();
                        }
                    }
                }
            }
        }
开发者ID:TheJaniceTong,项目名称:Judo-Xamarin,代码行数:41,代码来源:DeviceUuidFactory.cs

示例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/
        }
开发者ID:fsoyka,项目名称:RUOK,代码行数:40,代码来源:AlarmReceiverQuestionnaire.cs

示例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;
        }
开发者ID:mukhtiarlander,项目名称:git_demo_torit,代码行数:23,代码来源:Settings.cs

示例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();
 }
开发者ID:mmfraser,项目名称:dissertation,代码行数:5,代码来源:App.cs

示例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));
 }
开发者ID:jonlipsky,项目名称:Android.Play.ExpansionLibrary,代码行数:24,代码来源:ServerManagedPolicy.cs

示例15: DroidSimpleStorage

 public DroidSimpleStorage(string groupName, Context context)
     : base(groupName)
 {
     Prefs = context.GetSharedPreferences(groupName, FileCreationMode.Private);
 }
开发者ID:perpetual-mobile,项目名称:SimpleStorage,代码行数:5,代码来源:DroidSimpleStorage.cs


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