void RetryDownload(Intent intent) { if (intent.HasExtra(General.ALARM_NOTIFICATION_EXTRA)) { DownloadReturns downloadReturns = (DownloadReturns)intent.GetIntExtra(General.ALARM_NOTIFICATION_EXTRA, 0); intent.RemoveExtra(General.ALARM_NOTIFICATION_EXTRA); string message = ""; switch (downloadReturns) { case DownloadReturns.NoInternetConection: message = Resources.GetString(Resource.String.download_error_no_internet_conection); break; case DownloadReturns.NoWiFiFound: message = Resources.GetString(Resource.String.download_error_no_wifi_found); break; case DownloadReturns.NoWritePermission: message = Resources.GetString(Resource.String.download_error_no_write_permission); break; case DownloadReturns.OpenFile: message = ""; break; } if (!string.IsNullOrEmpty(message)) { new AlertDialog.Builder(this) .SetTitle(Resource.String.app_name) .SetMessage(message + "\n" + Resources.GetString(Resource.String.download_error_retry)) .SetIcon(Resource.Drawable.baseline_warning_24) .SetPositiveButton(Resource.String.download_error_ok_button, DialogPositiveButtonClick) .SetNegativeButton(Resource.String.download_error_cancel_button, DialogNegativeButtonClick) .Show(); } else { if (intent.HasExtra(General.ALARM_NOTIFICATION_FILE)) { var title = intent.HasExtra(General.ALARM_NOTIFICATION_TITLE) ? intent.GetStringExtra(General.ALARM_NOTIFICATION_TITLE) : string.Empty; var image = intent.HasExtra(General.ALARM_NOTIFICATION_IMAGE) ? intent.GetStringExtra(General.ALARM_NOTIFICATION_IMAGE) : string.Empty; Task.Run(async() => await Task.Delay(1000)) .ContinueWith(async t => { await Play(intent.GetStringExtra(General.ALARM_NOTIFICATION_FILE), title, image); }, TaskScheduler.FromCurrentSynchronizationContext()); } } } }
private async void DialogPositiveButtonClick(object sender, DialogClickEventArgs dialogClickEventArgs) { ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this); bool isWiFi = prefs.GetBoolean(General.ALARM_ONLY_WIFI, true); try { CancellationTokenSource token = new CancellationTokenSource(); RssEnCaso[] rssEnCasos = await RssEnCaso.GetRssEnCasoAsync(true, token.Token); if (rssEnCasos.Length > 0) { DownloadReturns downloadReturns = General.ExecuteDownload(this, rssEnCasos[0], isWiFi, true); string notificationMessage = ""; switch (downloadReturns) { case DownloadReturns.NoInternetConection: notificationMessage = this.GetString(Resource.String.download_error_no_internet_conection); break; case DownloadReturns.NoWiFiFound: notificationMessage = this.GetString(Resource.String.download_error_no_wifi_found); break; case DownloadReturns.NoWritePermission: notificationMessage = this.GetString(Resource.String.download_error_no_write_permission); break; } if (!string.IsNullOrEmpty(notificationMessage)) { Toast.MakeText(this, notificationMessage, ToastLength.Long).Show(); } } } catch (WebException we) { Analytics.TrackEvent(we.Message); } }
private void StartDownload() { DownloadReturns downloadReturns = General.ExecuteDownload(context, items[position], false, true); string notificationMessage = ""; switch (downloadReturns) { case DownloadReturns.NoInternetConection: notificationMessage = context.GetString(Resource.String.download_error_no_internet_conection); break; case DownloadReturns.NoWiFiFound: notificationMessage = context.GetString(Resource.String.download_error_no_wifi_found); break; case DownloadReturns.NoWritePermission: notificationMessage = context.GetString(Resource.String.download_error_no_write_permission); break; } if (!string.IsNullOrEmpty(notificationMessage)) { Toast.MakeText(context, notificationMessage, ToastLength.Long).Show(); } }
public async override void OnReceive(Context context, Intent intent) { General.ProgramNextAlarm(context); ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(context); bool isWiFi = prefs.GetBoolean(General.ALARM_ONLY_WIFI, true); RssEnCaso rssEnCaso = null; try { CancellationTokenSource cts = new CancellationTokenSource(); RssEnCaso[] rssEnCasos = await RssEnCaso.GetRssEnCasoAsync(true, cts.Token); rssEnCaso = rssEnCasos[0]; } catch (WebException we) { Intent callIntent = new Intent(context, typeof(MainActivity)); callIntent.PutExtra(General.ALARM_NOTIFICATION_EXTRA, (int)DownloadReturns.NoInternetConection); PendingIntent pendingIntent = PendingIntent.GetActivity(context, 0, callIntent, PendingIntentFlags.UpdateCurrent); string notificationMessage = context.GetString(Resource.String.download_error_no_internet_conection); General.ShowNotification(context, notificationMessage, Resource.Drawable.main_nav_list, pendingIntent); Analytics.TrackEvent(we.Message); } if (rssEnCaso != null) { DownloadReturns downloadReturns = General.ExecuteDownload(context, rssEnCaso, isWiFi, false); string notificationMessage = ""; Intent callIntent = new Intent(context, typeof(MainActivity)); switch (downloadReturns) { case DownloadReturns.NoInternetConection: callIntent.PutExtra(General.ALARM_NOTIFICATION_EXTRA, (int)DownloadReturns.NoInternetConection); notificationMessage = context.GetString(Resource.String.download_error_no_internet_conection); break; case DownloadReturns.NoWiFiFound: callIntent.PutExtra(General.ALARM_NOTIFICATION_EXTRA, (int)DownloadReturns.NoWiFiFound); notificationMessage = context.GetString(Resource.String.download_error_no_wifi_found); break; case DownloadReturns.NoWritePermission: callIntent.PutExtra(General.ALARM_NOTIFICATION_EXTRA, (int)DownloadReturns.NoWritePermission); notificationMessage = context.GetString(Resource.String.download_error_no_write_permission); break; case DownloadReturns.ServiceStarted: callIntent = null; break; } if (callIntent != null) { PendingIntent pendingIntent = PendingIntent.GetActivity(context, 0, callIntent, PendingIntentFlags.UpdateCurrent); General.ShowNotification(context, notificationMessage, Resource.Drawable.main_nav_list, pendingIntent); } } //var jobScheduler = (JobScheduler)context.GetSystemService(Context.JobSchedulerService); //var javaClass = Java.Lang.Class.FromType(typeof(DownloadJobService)); //var componentName = new ComponentName(context, javaClass); //var jobInfo = new JobInfo // .Builder(1, componentName) // .SetMinimumLatency(1000) // .SetOverrideDeadline(2000) // .SetRequiredNetworkType(NetworkType.Any) // .SetRequiresDeviceIdle(false) // .SetRequiresCharging(false) // .Build(); //var scheduleResult = jobScheduler.Schedule(jobInfo); //if (JobScheduler.ResultSuccess == scheduleResult) //{ //} //else //{ //} }
public override bool OnStartJob(JobParameters @params) { Task.Run(async() => { ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this.ApplicationContext); bool isWiFi = prefs.GetBoolean(General.ALARM_ONLY_WIFI, true); RssEnCaso rssEnCaso = null; try { CancellationTokenSource cts = new CancellationTokenSource(); RssEnCaso[] rssEnCasos = await RssEnCaso.GetRssEnCasoAsync(true, cts.Token); rssEnCaso = rssEnCasos[0]; } catch (WebException we) { Intent callIntent = new Intent(this.ApplicationContext, typeof(MainActivity)); callIntent.PutExtra(General.ALARM_NOTIFICATION_EXTRA, (int)DownloadReturns.NoInternetConection); PendingIntent pendingIntent = PendingIntent.GetActivity(this.ApplicationContext, 0, callIntent, PendingIntentFlags.UpdateCurrent); string notificationMessage = this.ApplicationContext.GetString(Resource.String.download_error_no_internet_conection); General.ShowNotification(this.ApplicationContext, notificationMessage, Resource.Drawable.main_nav_list, pendingIntent); Analytics.TrackEvent(we.Message); } if (rssEnCaso != null) { DownloadReturns downloadReturns = General.ExecuteDownload(this.ApplicationContext, rssEnCaso, isWiFi, false); string notificationMessage = ""; Intent callIntent = new Intent(this.ApplicationContext, typeof(MainActivity)); switch (downloadReturns) { case DownloadReturns.NoInternetConection: callIntent.PutExtra(General.ALARM_NOTIFICATION_EXTRA, (int)DownloadReturns.NoInternetConection); notificationMessage = this.ApplicationContext.GetString(Resource.String.download_error_no_internet_conection); break; case DownloadReturns.NoWiFiFound: callIntent.PutExtra(General.ALARM_NOTIFICATION_EXTRA, (int)DownloadReturns.NoWiFiFound); notificationMessage = this.ApplicationContext.GetString(Resource.String.download_error_no_wifi_found); break; case DownloadReturns.NoWritePermission: callIntent.PutExtra(General.ALARM_NOTIFICATION_EXTRA, (int)DownloadReturns.NoWritePermission); notificationMessage = this.ApplicationContext.GetString(Resource.String.download_error_no_write_permission); break; case DownloadReturns.ServiceStarted: callIntent = null; break; } if (callIntent != null) { PendingIntent pendingIntent = PendingIntent.GetActivity(this.ApplicationContext, 0, callIntent, PendingIntentFlags.UpdateCurrent); General.ShowNotification(this.ApplicationContext, notificationMessage, Resource.Drawable.main_nav_list, pendingIntent); } } // Have to tell the JobScheduler the work is done. JobFinished(@params, false); }); return(true); }