示例#1
0
		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
0
        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
0
        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;
        }
 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
0
 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;
 }
 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
0
        public connectivity(Context c)
        {
            Singleton = this;
            AppContext = c;

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

            MessageEvents = new UIChangedEvent();

            prefs = c.GetSharedPreferences("ConPrefs", FileCreationMode.Private);
        }
        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
0
        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);
        }
        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
0
        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
0
        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
0
 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();
 }
 /// <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));
 }
 public DroidSimpleStorage(string groupName, Context context)
     : base(groupName)
 {
     Prefs = context.GetSharedPreferences(groupName, FileCreationMode.Private);
 }
        internal static ISharedPreferences GetGCMPreferences(Context context)
        {
            // This sample app persists the registration ID in shared preferences, but
                // how you store the registration ID in your app is up to you.

                return context.GetSharedPreferences(GcmPreferencesKey, FileCreationMode.Private);
        }
示例#17
0
 public static Dictionary<String, int> GetComputeInstalledApps(Context context)
 {
     ISharedPreferences prefs = context.GetSharedPreferences(context.PackageName, FileCreationMode.Private);
     return JsonConvert.DeserializeObject<Dictionary<String, int>>(prefs.GetString("InstalledComputeApps", null));
 }
示例#18
0
		public static bool Restore (Facebook session, Context context)
		{
			var savedSession = context.GetSharedPreferences (KEY, FileCreationMode.Private);
			session.AccessToken = savedSession.GetString (TOKEN, null);
			session.AccessExpires = savedSession.GetLong (EXPIRES, 0);
			return session.IsSessionValid;
		}
示例#19
0
		static ISharedPreferences GetGCMPreferences(Context context)
		{
			return context.GetSharedPreferences(PREFERENCES, FileCreationMode.Private);
		}
        /// <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(PreferencesFile, FileCreationMode.Private);
			this.Obfuscator = new PreferenceObfuscator(sp, obfuscator);

			this.lastResponse = this.Obfuscator.GetValue<PolicyServerResponse>(Preferences.LastResponse, Preferences.DefaultLastResponse);
			this.validityTimestamp = this.Obfuscator.GetValue<long>(Preferences.ValidityTimestamp, Preferences.DefaultValidityTimestamp);
			this.retryUntil = this.Obfuscator.GetValue<long>(Preferences.RetryUntil, Preferences.DefaultRetryUntil);
			this.maxRetries = this.Obfuscator.GetValue<long>(Preferences.MaximumRetries, Preferences.DefaultMaxRetries);
			this.retryCount = this.Obfuscator.GetValue<long>(Preferences.RetryCount, Preferences.DefaultRetryCount);
        }
示例#21
0
        public static void SetAuthToken(Context context, string authToken)
        {
            ISharedPreferences prefs = context.GetSharedPreferences(context.PackageName, FileCreationMode.Private);

            prefs.Edit().PutString("AuthToken", authToken).Commit();
        }
示例#22
0
        /// <summary>
        ///  
        /// </summary>
        /// <param name="context"></param>
        /// <returns>-1 for no device id</returns>
        public static int GetDeviceId(Context context)
        {
            ISharedPreferences prefs = context.GetSharedPreferences(context.PackageName, FileCreationMode.Private);

            return prefs.GetInt("DeviceID", -1);
        }
示例#23
0
 /// <summary>
 /// Create the SharedPreferences storage with private access only.
 /// </summary>
 /// <param name="context">Context.</param>
 public ROMPGeofenceStore(Context context)
 {
     mPrefs = context.GetSharedPreferences (SHARED_PREFERENCES, FileCreationMode.Private);
 }
示例#24
0
        public static void setDeviceId(Context context, int deviceId)
        {
            ISharedPreferences prefs = context.GetSharedPreferences(context.PackageName, FileCreationMode.Private);

            prefs.Edit().PutInt("DeviceID", deviceId).Commit();
        }
示例#25
0
		public static bool Save (Facebook session, Context context)
		{
			var editor = context.GetSharedPreferences (KEY, FileCreationMode.Private).Edit ();
			editor.PutString (TOKEN, session.AccessToken);
			editor.PutLong (EXPIRES, session.AccessExpires);
			return editor.Commit ();
		}
示例#26
0
        public static void setPassword(Context context, string password)
        {
            ISharedPreferences prefs = context.GetSharedPreferences(context.PackageName, FileCreationMode.Private);

            prefs.Edit().PutString("Password", password).Commit();
        }
示例#27
0
		public static void Clear (Context context)
		{
			var editor = context.GetSharedPreferences (KEY, FileCreationMode.Private).Edit ();
			editor.Clear ();
			editor.Commit ();
		}
示例#28
0
        public static void setUsername(Context context, string username)
        {
            ISharedPreferences prefs = context.GetSharedPreferences(context.PackageName, FileCreationMode.Private);

            prefs.Edit().PutString("Username", username).Commit();
        }
		static ISharedPreferences GetSharedPreferences(Context context) {
			return context.GetSharedPreferences(PlayerPreferences, FileCreationMode.Private);
		}
示例#30
0
 public static String GetAuthToken(Context context)
 {
     ISharedPreferences prefs = context.GetSharedPreferences(context.PackageName, FileCreationMode.Private);
     return prefs.GetString("AuthToken", "");
 }