public void OnConnected(Bundle p0) { Log.Debug ("LocClient", "Connected"); if (currentRequest == ConnectionUpdateRequest.None) return; if (callbackIntent == null) { var intent = new Intent (this, typeof(BikrActivityService)); callbackIntent = PendingIntent.GetService (this, Resource.Id.bikr_intent_location, intent, PendingIntentFlags.UpdateCurrent); } if (currentRequest == ConnectionUpdateRequest.Start) { var req = new LocationRequest () .SetInterval (5000) .SetFastestInterval (2000) .SetSmallestDisplacement (5) .SetPriority (LocationRequest.PriorityHighAccuracy); client.RequestLocationUpdates (req, callbackIntent); prevStoredLocation = client.LastLocation; Log.Info ("LocClient", "Requested updates"); } else { client.RemoveLocationUpdates (callbackIntent); prevStoredLocation = null; Log.Info ("LocClient", "Finished updates"); } currentRequest = ConnectionUpdateRequest.None; client.Disconnect (); }
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) { var LocationServiceIntent = new Intent ("com.ETCTimeApp.SaveLocationService"); pendingSaveLocationServiceIntent = PendingIntent.GetService (this, 0, LocationServiceIntent, 0); alarm = (AlarmManager)this.BaseContext.GetSystemService (Context.AlarmService); //repeat every 10 minutes alarm.SetRepeating (AlarmType.RtcWakeup, 10000, 1 * 5000 * 60, pendingSaveLocationServiceIntent); var pendingIntent = PendingIntent.GetActivity (this, 1, new Intent (this, typeof(MainActivity)), 0); var resultString = "Location service is running on background!"; int ic_small = Resource.Drawable.gps_small; var builder = new NotificationCompat.Builder (this) .SetAutoCancel (true) .SetContentIntent (pendingIntent) .SetContentTitle ("ETC Location Notification") .SetSmallIcon (ic_small) .SetContentText (resultString); // start our service foregrounded, that way it won't get cleaned up from memory pressure StartForeground ((int)NotificationFlags.ForegroundService, builder.Build ()); return StartCommandResult.Sticky; }
protected override void OnCreate (Bundle savedInstanceState) { base.OnCreate (savedInstanceState); SetContentView(Resource.Layout.main_activity); mAddGeofencesButton = FindViewById<Button>(Resource.Id.add_geofences_button); mRemoveGeofencesButton = FindViewById<Button>(Resource.Id.remove_geofences_button); mAddGeofencesButton.Click += AddGeofencesButtonHandler; mRemoveGeofencesButton.Click += RemoveGeofencesButtonHandler; mGeofenceList = new List<IGeofence>(); mGeofencePendingIntent = null; mSharedPreferences = GetSharedPreferences(Constants.SHARED_PREFERENCES_NAME, FileCreationMode.Private); mGeofencesAdded = mSharedPreferences.GetBoolean(Constants.GEOFENCES_ADDED_KEY, false); SetButtonsEnabledState(); PopulateGeofenceList(); BuildGoogleApiClient(); }
public static void ProgramNextAlarm(Context context) { ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(context); int hour = prefs.GetInt(General.ALARM_HOUR, DateTime.Now.Hour); int minute = prefs.GetInt(General.ALARM_MINUTE, DateTime.Now.Minute); int seconds = TimeCalculator.GetSecondsUntilNextCheck(new DateTime(1984, 10, 12, hour, minute, 00)); //GET TIME IN SECONDS AND INITIALIZE INTENT Intent i = new Intent(context, typeof(AlarmBroadcastReceiver)); //PASS CONTEXT,YOUR PRIVATE REQUEST CODE,INTENT OBJECT AND FLAG Android.App.PendingIntent pi = Android.App.PendingIntent.GetBroadcast(context, 1, i, 0); //INITIALIZE ALARM MANAGER Android.App.AlarmManager alarmManager = (Android.App.AlarmManager)context.GetSystemService(Context.AlarmService); //SET THE ALARM long triggermillis = Java.Lang.JavaSystem.CurrentTimeMillis() + (seconds * 1000); if (Build.VERSION.SdkInt >= BuildVersionCodes.M) { alarmManager.SetAndAllowWhileIdle(Android.App.AlarmType.RtcWakeup, triggermillis, pi); } else //if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat) { alarmManager.SetExact(Android.App.AlarmType.RtcWakeup, triggermillis, pi); } //else // alarmManager.Set(Android.App.AlarmType.RtcWakeup, triggermillis, pi); }
public MediaNotificationManagerImplementation(Context appliactionContext, MediaSessionCompat.Token sessionToken, Type serviceType) { _sessionToken = sessionToken; _appliactionContext = appliactionContext; _intent = new Intent(_appliactionContext, serviceType); var mainActivity = _appliactionContext.PackageManager.GetLaunchIntentForPackage(_appliactionContext.PackageName); _pendingIntent = PendingIntent.GetActivity(_appliactionContext, 0, mainActivity, PendingIntentFlags.UpdateCurrent); }
/** * Starts a new activity for the user to buy an item for sale. This method * forwards the intent on to the PurchaseObserver (if it exists) because * we need to start the activity on the activity stack of the application. * * @param pendingIntent a PendingIntent that we received from Android Market that * will create the new buy page activity * @param intent an intent containing a request id in an extra field that * will be passed to the buy page activity when it is created */ public static void buyPageIntentResponse(PendingIntent pendingIntent, Intent intent) { if (sPurchaseObserver == null) { if (Consts.DEBUG) Log.Debug(TAG, "UI is not running"); return; } sPurchaseObserver.startBuyPageActivity(pendingIntent, intent); }
public void Remind(int seconds, string title, string message) { Intent alarmIntent = new Intent(Forms.Context, typeof(AlarmReceiver)); alarmIntent.PutExtra("message", message); alarmIntent.PutExtra("title", title); pendingIntent = PendingIntent.GetBroadcast(Forms.Context, 0, alarmIntent, PendingIntentFlags.UpdateCurrent); AlarmManager alarmManager = (AlarmManager)Forms.Context.GetSystemService(Context.AlarmService); alarmManager.Set(AlarmType.ElapsedRealtimeWakeup, SystemClock.ElapsedRealtime() + seconds * 1000, pendingIntent); }
public override void OnViewCreated (View view, Bundle savedInstanceState) { notificationManager = (NotificationManager)Activity.GetSystemService (Context.NotificationService); numberOfNotifications = view.FindViewById <TextView> (Resource.Id.number_of_notifications); var addNotification = view.FindViewById <Button> (Resource.Id.add_notification); addNotification.Click += (sender, e) => AddNotificationAndUpdateSummaries (); // Create a PendingIntent to be fired upon deletion of a Notification. var deleteIntent = new Intent (MainActivity.ACTION_NOTIFICATION_DELETE); deletePendingIntent = PendingIntent.GetBroadcast (Activity, REQUEST_CODE, deleteIntent, 0); }
public MediaNotificationManager(MusicService serv) { service = serv; UpdateSessionToken(); notificationColor = ResourceHelper.GetThemeColor(service, Android.Resource.Attribute.ColorPrimary, Color.DarkGray); notificationManager = (NotificationManager) service .GetSystemService(Context.NotificationService); string pkg = service.PackageName; pauseIntent = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionPause).SetPackage(pkg), PendingIntentFlags.CancelCurrent); playIntent = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionPlay).SetPackage(pkg), PendingIntentFlags.CancelCurrent); previousIntent = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionPrev).SetPackage(pkg), PendingIntentFlags.CancelCurrent); nextIntent = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionNext).SetPackage(pkg), PendingIntentFlags.CancelCurrent); notificationManager.CancelAll (); mCb.OnPlaybackStateChangedImpl = (state) => { playbackState = state; LogHelper.Debug (Tag, "Received new playback state", state); if (state != null && (state.State == PlaybackStateCode.Stopped || state.State == PlaybackStateCode.None)) { StopNotification (); } else { Notification notification = CreateNotification (); if (notification != null) { notificationManager.Notify (NotificationId, notification); } } }; mCb.OnMetadataChangedImpl = (meta) => { metadata = meta; LogHelper.Debug (Tag, "Received new metadata ", metadata); Notification notification = CreateNotification (); if (notification != null) { notificationManager.Notify (NotificationId, notification); } }; mCb.OnSessionDestroyedImpl = () => { LogHelper.Debug (Tag, "Session was destroyed, resetting to the new session token"); UpdateSessionToken (); }; }
public override void OnUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { Console.WriteLine("PlayerWidgetProvider - OnUpdate - appWidgetIds.length: {0}", appWidgetIds.Length); AlarmManager alarmManager = (AlarmManager)context.GetSystemService(Context.AlarmService); Intent intentAlarm = new Intent(context, typeof(WidgetService)); intentAlarm.SetAction(AppWidgetManager.ActionAppwidgetUpdate); intentAlarm.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds); if (_pendingIntentWidgetService == null) _pendingIntentWidgetService = PendingIntent.GetService(context, 0, intentAlarm, PendingIntentFlags.CancelCurrent); Calendar time = Calendar.Instance; time.Set(CalendarField.Minute, 0); time.Set(CalendarField.Second, 0); time.Set(CalendarField.Millisecond, 0); alarmManager.SetRepeating(AlarmType.Rtc, time.Time.Time, 1000 * 10, _pendingIntentWidgetService); //alarmManager.SetRepeating(AlarmType.ElapsedRealtime, SystemClock.ElapsedRealtime(), 1000, _pendingIntentWidgetService); for (int a = 0; a < appWidgetIds.Length; a++) { int appWidgetId = appWidgetIds[a]; RemoteViews views = new RemoteViews(context.PackageName, Resource.Layout.WidgetPlayer); //var intentBackground = new Intent(context, typeof (WidgetService)); //intentBackground.SetAction(SessionsWidgetActions.op.ToString()); //intentBackground.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds); //var pendingIntentBackgroundClick = PendingIntent.GetService(context, appWidgetId, intentBackground, PendingIntentFlags.UpdateCurrent); //views.SetOnClickPendingIntent(Resource.Id.widgetPlayer, pendingIntentBackgroundClick); var intentPrevious = new Intent(context, typeof(WidgetService)); intentPrevious.SetAction(SessionsWidgetActions.SessionsWidgetPrevious.ToString()); intentPrevious.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds); var pendingIntentPreviousClick = PendingIntent.GetService(context, appWidgetId, intentPrevious, PendingIntentFlags.UpdateCurrent); views.SetOnClickPendingIntent(Resource.Id.widgetPlayer_btnPrevious, pendingIntentPreviousClick); var intentPlayPause = new Intent(context, typeof(WidgetService)); intentPlayPause.SetAction(SessionsWidgetActions.SessionsWidgetPlayPause.ToString()); intentPlayPause.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds); var pendingIntentPlayPauseClick = PendingIntent.GetService(context, appWidgetId, intentPlayPause, PendingIntentFlags.UpdateCurrent); views.SetOnClickPendingIntent(Resource.Id.widgetPlayer_btnPlayPause, pendingIntentPlayPauseClick); var intentNext = new Intent(context, typeof(WidgetService)); intentNext.SetAction(SessionsWidgetActions.SessionsWidgetNext.ToString()); intentNext.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds); var pendingIntentNextClick = PendingIntent.GetService(context, appWidgetId, intentNext, PendingIntentFlags.UpdateCurrent); views.SetOnClickPendingIntent(Resource.Id.widgetPlayer_btnNext, pendingIntentNextClick); appWidgetManager.UpdateAppWidget(appWidgetId, views); } }
public void StartService() { _locMan = Application.Context.GetSystemService (Context.LocationService) as LocationManager; if (_locMan.GetProvider (LocationManager.GpsProvider) != null && _locMan.IsProviderEnabled (LocationManager.GpsProvider)) { _pi = PendingIntent.GetBroadcast(Application.Context, 0, new Intent(), PendingIntentFlags.UpdateCurrent); _locMan.RequestLocationUpdates(LocationManager.GpsProvider, 2000, 5, _pi); _locMan.GetLastKnownLocation (LocationManager.GpsProvider); } else throw new GPSNotEnabledException (Const.NO_GPS_ERROR_MESSAGE); }
public void OnConnected(Bundle p0) { Log.Debug ("ActRecognition", "Connected"); if (currentRequest == ConnectionUpdateRequest.None) return; if (callbackIntent == null) { var intent = new Intent (context, typeof(BikrActivityService)); callbackIntent = PendingIntent.GetService (context, Resource.Id.bikr_intent_activity, intent, PendingIntentFlags.UpdateCurrent); } if (currentRequest == ConnectionUpdateRequest.Start) { client.RequestActivityUpdates ((int)desiredDelay, callbackIntent); Log.Info ("ActRecognition", "Enabling activity updates w/ {0}", desiredDelay.ToString ()); } else { client.RemoveActivityUpdates (callbackIntent); Log.Info ("ActRecognition", "Disabling activity updates"); } currentRequest = ConnectionUpdateRequest.None; client.Disconnect (); }
/// <summary> /// The on download progress. /// </summary> /// <param name="progress"> /// The progress. /// </param> public void OnDownloadProgress(DownloadProgressInfo progress) { this.progressInfo = progress; if (null != this.clientProxy) { this.clientProxy.OnDownloadProgress(progress); } if (progress.OverallTotal <= 0) { // we just show the text this.notification.TickerText = new String(this.currentTitle); this.notification.Icon = Android.Resource.Drawable.StatSysDownload; this.notification.SetLatestEventInfo(this.context, this.label, this.currentText, this.PendingIntent); this.currentNotification = this.notification; } else { this.customNotification.CurrentBytes = progress.OverallProgress; this.customNotification.TotalBytes = progress.OverallTotal; this.customNotification.Icon = Android.Resource.Drawable.StatSysDownload; this.customNotification.PendingIntent = this.PendingIntent; this.customNotification.Ticker = string.Format("{0}: {1}", this.label, this.currentText); this.customNotification.Title = this.label; this.customNotification.TimeRemaining = progress.TimeRemaining; this.currentNotification = this.customNotification.UpdateNotification(this.context); } this.notificationManager.Notify(NotificationId, this.currentNotification); }
public override void OnCreate() { base.OnCreate (); Console.SetOut(new AndroidLogTextWriter()); DataAccess.Configurator.ArtLocalDirectory = CacheDir.AbsolutePath; _container = new Athena.IoC.Container(); _model = new AmpacheModel(); _container.Register<AmpacheModel>().To(_model); DataAccess.Configurator.Configure(_container); var am = (AlarmManager)ApplicationContext.GetSystemService(Context.AlarmService); var ping = new Intent(PingReceiver.INTENT); _pingIntent = PendingIntent.GetBroadcast(ApplicationContext, 0, ping, PendingIntentFlags.UpdateCurrent); am.SetRepeating(AlarmType.RtcWakeup, Java.Lang.JavaSystem.CurrentTimeMillis() + (long)TimeSpan.FromMinutes(5).TotalMilliseconds, (long)TimeSpan.FromMinutes(5).TotalMilliseconds, _pingIntent); var stm = Resources.OpenRawResource(Resource.Drawable.ct_default_artwork); var stream = new System.IO.MemoryStream(); stm.CopyTo(stream); stream.Position = 0; Start(stream); _player = new AndroidPlayer(_model, ApplicationContext); _notifications = new AmpacheNotifications(this.ApplicationContext, _model); var telSvc = this.ApplicationContext.GetSystemService(Context.TelephonyService) as Android.Telephony.TelephonyManager; if(telSvc != null) { telSvc.Listen(new AmpachePhoneStateListener(_model), Android.Telephony.PhoneStateListenerFlags.CallState); } }
public override void StopAutoShutOff() { StartForeground(AmpacheNotifications.NOTIFICATION_ID, _notifications.AmpacheNotification); var am = (AlarmManager)ApplicationContext.GetSystemService(Context.AlarmService); am.Cancel(_stopIntent); _stopIntent.Dispose(); _stopIntent = null; }
public void OnConnected (Bundle connectionHint) { // Use mRequestType to determine what action to take. Only Add used in this sample if (mRequestType == RequestType.Add) { // Get the PendingIntent for the geofence monitoring request mGeofenceRequestIntent = GeofenceTransitionPendingIntent; // Send a request to add the current geofences LocationServices.GeofencingApi.AddGeofences (apiClient, mGeofenceList, mGeofenceRequestIntent); } }
private void StartAlarm() { Context context = BaseContext; _alarmManager = (AlarmManager) context.GetSystemService(Context.AlarmService); _intentTracker = new Intent(context, typeof(GPSAlarmReceiver)); _intentPending = PendingIntent.GetBroadcast(context, 0, _intentTracker, 0); var pref = GetSharedPreferences("LainLadangLainBelalang", 0); _jedaMenit = pref.GetInt("menitInterval", 1); _alarmManager.SetRepeating(AlarmType.ElapsedRealtimeWakeup, SystemClock.ElapsedRealtime(), _jedaMenit * 60000, _intentPending); }
internal virtual void StartBuyPageActivity(PendingIntent pendingIntent, Intent intent) { //if (mStartIntentSender != null) { // This is on Android 2.0 and beyond. The in-app buy page activity // must be on the activity stack of the application. try { // This implements the method call: mActivity.StartIntentSender(pendingIntent.IntentSender, intent, 0, 0, 0); mActivity.StartIntentSender(pendingIntent.IntentSender, intent, 0, 0, 0); // mStartIntentSenderArgs[0] = pendingIntent.IntentSender; // mStartIntentSenderArgs[1] = intent; // mStartIntentSenderArgs[2] = Convert.ToInt32(0); // mStartIntentSenderArgs[3] = Convert.ToInt32(0); // mStartIntentSenderArgs[4] = Convert.ToInt32(0); // mStartIntentSender.Invoke(mActivity, mStartIntentSenderArgs); } catch (Exception e) { Log.Error(TAG, "error starting activity", e); } } // else // { // This is on Android version 1.6. The in-app buy page activity must be on its // own separate activity stack instead of on the activity stack of // the application. // try // { // pendingIntent.Send(mActivity, 0, intent); // code // } // catch (PendingIntent.CanceledException e) // { // Log.Error(TAG, "error starting activity", e); //} // } }
public void ScheduleCallbackAlarm(PendingIntent callbackPendingIntent, DateTime callbackTime) { AlarmManager alarmManager = _service.GetSystemService(Context.AlarmService) as AlarmManager; long delayMS = (long)(callbackTime - DateTime.Now).TotalMilliseconds; long callbackTimeMS = Java.Lang.JavaSystem.CurrentTimeMillis() + delayMS; // https://github.com/predictive-technology-laboratory/sensus/wiki/Backwards-Compatibility #if __ANDROID_23__ if (Build.VERSION.SdkInt >= BuildVersionCodes.M) alarmManager.SetExactAndAllowWhileIdle(AlarmType.RtcWakeup, callbackTimeMS, callbackPendingIntent); // API level 23 added "while idle" option, making things even tighter. else if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat) alarmManager.SetExact(AlarmType.RtcWakeup, callbackTimeMS, callbackPendingIntent); // API level 19 differentiated Set (loose) from SetExact (tight) else #endif { alarmManager.Set(AlarmType.RtcWakeup, callbackTimeMS, callbackPendingIntent); // API 1-18 treats Set as a tight alarm } }
private Request(Context context, string senderId) { this.context = context; this.senderId = senderId; appIntent = PendingIntent.GetBroadcast(context, 0, new Intent(), 0); }
/// <summary> /// Used for registration with dependency service /// </summary> public static void Init(string deviceID, string googleProjectNumber, string registrationId, int notificationIcon, PendingIntent pendingIntent) { SenderID = googleProjectNumber; DeviceID = deviceID; RegistrationID = registrationId; NotificationIcon = notificationIcon; PendingIntent = pendingIntent; }
public FixtureAlarmService(Context context) { _context = context; var intent = new Intent(_context, typeof(FixtureTodayAlarmReceiver)); _pendingIntent = PendingIntent.GetBroadcast(context, 0, intent, 0); }
public Builder SetContentIntent(PendingIntent intent) { ContentIntent = intent; return this; }
private void CancelAlarm() { Context context = BaseContext; _intentTracker = new Intent(context, typeof(GPSAlarmReceiver)); _intentPending = PendingIntent.GetBroadcast(context, 0, _intentTracker, 0); _alarmManager = (AlarmManager) context.GetSystemService(AlarmService); _alarmManager.Cancel(_intentPending); }
public Builder SetDeleteIntent(PendingIntent intent) { Notification.DeleteIntent = intent; return this; }
/// <summary> /// Initializes a new instance of the <see cref="LvlRunnable"/> class. /// </summary> /// <param name="context"> /// The context. /// </param> /// <param name="intent"> /// The intent. /// </param> internal LvlRunnable(DownloaderService context, PendingIntent intent) { Debug.WriteLine("DownloaderService.LvlRunnable.ctor"); this.context = context; this.context.pPendingIntent = intent; }
public RecommendationBuilder SetIntent (PendingIntent intent) { mIntent = intent; return this; }
private void AddFences() { pendingIntent = CreatePendingIntent(); GeofencingRequest fenceReq = new GeofencingRequest.Builder().AddGeofences(fencesToAdd).Build(); currentStage = FencingStage.Adding; var result = LocationServices.GeofencingApi.AddGeofences(googleApiClient, fenceReq, pendingIntent); result.SetResultCallback(this); }
public void OnSendFinished(PendingIntent pendingIntent, Intent intent, Result resultCode, string resultData, Bundle resultExtras) { var res = ResultOk; if (res != null) { res(resultCode == Result.Ok); } }
/// <summary> /// Method to send SMS . If Failed then Invoked Three times /// </summary> /// <param name="PhoneNumber"></param> /// <param name="Code"></param> /// <returns></returns> public bool sendSMS(string PhoneNumber, int Code) { try { phoneNumberAndCodeDictionary.Clear(); phoneNumberAndCodeDictionary.Add(PhoneNumber, Code); if (MyAttempts > 0) { sentPI = PendingIntent.GetBroadcast(this, 0, new Intent(SENT), 0); //When sms sent OS broadcast and this object gets that broadcast message and fires on receive message SmsManager.Default.SendTextMessage(PhoneNumber, null, Code.ToString(), sentPI, null); MyAttempts--; return true; } return false; } catch (Exception ex) { AccessUI accessUi = new AccessUI(); accessUi.ShowToast(ex.Message); return true; } }
public override void StartAutoShutOff() { StopForeground(false); var am = (AlarmManager)ApplicationContext.GetSystemService(Context.AlarmService); am.Set(AlarmType.ElapsedRealtimeWakeup, Java.Lang.JavaSystem.CurrentTimeMillis() + (long)TimeSpan.FromMinutes(30).Milliseconds, _stopIntent); var stop = new Intent(StopServiceReceiver.INTENT); _stopIntent = PendingIntent.GetBroadcast(ApplicationContext, ++_intentId, stop, PendingIntentFlags.UpdateCurrent); am.Set(AlarmType.RtcWakeup, Java.Lang.JavaSystem.CurrentTimeMillis() + (long)TimeSpan.FromMinutes(30).TotalMilliseconds , _stopIntent); }