public override void OnStart (Android.Content.Intent intent, int startId) { base.OnStart (intent, startId); DBRepository dbr = new DBRepository (); userAndsoft = dbr.getUserAndsoft (); userTransics = dbr.getUserTransics (); var t = DateTime.Now.ToString("dd_MM_yy"); string dir_log = (Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads)).ToString(); ISharedPreferences pref = Application.Context.GetSharedPreferences("AppInfo", FileCreationMode.Private); string log = pref.GetString("Log", String.Empty); //GetTelId TelephonyManager tel = (TelephonyManager)this.GetSystemService(Context.TelephonyService); var telId = tel.DeviceId; //Si il n'y a pas de shared pref if (log == String.Empty){ log_file = Path.Combine (dir_log, t+"_"+telId+"_log.txt"); ISharedPreferencesEditor edit = pref.Edit(); edit.PutString("Log",log_file); edit.Apply(); }else{ //il y a des shared pref log_file = pref.GetString("Log", String.Empty); if (((File.GetCreationTime(log_file)).CompareTo(DateTime.Now)) > 3) { File.Delete(log_file); log_file = Path.Combine (dir_log, t+"_"+telId+"_log.txt"); ISharedPreferencesEditor edit = pref.Edit(); edit.PutString("Log",log_file); edit.Apply(); log_file = pref.GetString("Log", String.Empty); } } File.AppendAllText(log_file,"[SERVICE] Service Onstart call "+DateTime.Now.ToString("t")+"\n"); DoStuff (); // initialize location manager locMgr = GetSystemService (Context.LocationService) as LocationManager; if (locMgr.AllProviders.Contains (LocationManager.NetworkProvider) && locMgr.IsProviderEnabled (LocationManager.NetworkProvider)) { locMgr.RequestLocationUpdates (LocationManager.NetworkProvider, 2000, 1, this); File.AppendAllText(log_file,"[GPS] Lancer le"+DateTime.Now.ToString("t")+"\n"); } else { File.AppendAllText(log_file,"[GPS] Le GPS est désactiver"+DateTime.Now.ToString("t")+"\n"); } }
protected override void OnResume() { base.OnResume(); DBRepository dbr = new DBRepository (); dbr.SETBadges(Data.userAndsoft); if (dbr.is_user_Log_In() == "false") { Intent intent = new Intent (this, typeof(MainActivity)); this.StartActivity (intent); this.OverridePendingTransition (Resource.Animation.abc_slide_in_top,Resource.Animation.abc_slide_out_bottom); } var t = DateTime.Now.ToString ("dd_MM_yy"); string dir_log = (Android.OS.Environment.GetExternalStoragePublicDirectory (Android.OS.Environment.DirectoryDownloads)).ToString (); //Shared Preference ISharedPreferences pref = Application.Context.GetSharedPreferences ("AppInfo", FileCreationMode.Private); string log = pref.GetString ("Log", String.Empty); //GetTelId TelephonyManager tel = (TelephonyManager)this.GetSystemService (Context.TelephonyService); var telId = tel.DeviceId; //Si il n'y a pas de shared pref if (log == String.Empty) { Data.log_file = Path.Combine (dir_log, t + "_" + telId + "_log.txt"); ISharedPreferencesEditor edit = pref.Edit (); edit.PutString ("Log", Data.log_file); edit.Apply (); } else { //il y a des shared pref Data.log_file = pref.GetString ("Log", String.Empty); if (((File.GetCreationTime (Data.log_file)).CompareTo (DateTime.Now)) > 3) { File.Delete (Data.log_file); Data.log_file = Path.Combine (dir_log, t + "_" + telId + "_log.txt"); ISharedPreferencesEditor edit = pref.Edit (); edit.PutString ("Log", Data.log_file); edit.Apply (); Data.log_file = pref.GetString ("Log", String.Empty); } } var user = dbr.getUserAndsoft (); dbr.setUserdata (user); var version = this.PackageManager.GetPackageInfo(this.PackageName, 0).VersionName; lblTitle.Text = Data.userAndsoft + " " + version; indicatorTimer = new System.Timers.Timer(); indicatorTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnIndicatorTimerHandler); indicatorTimer.Interval = 1000; indicatorTimer.Enabled = true; indicatorTimer.Start(); }