/// <summary> /// Builds a PendingIntent that will display the main activity of the app. This is used when the /// user taps on the notification; it will take them to the main activity of the app. /// </summary> /// <returns>The content intent.</returns> private Android.App.PendingIntent BuildIntentToShowMainActivity() { Intent showMainActivityIntent = new Intent(this, GetType()); showMainActivityIntent.SetAction(ActionShowMainActivity); Android.App.PendingIntentFlags intentFlags = Android.App.PendingIntentFlags.UpdateCurrent; if (Build.VERSION.SdkInt >= BuildVersionCodes.S) { intentFlags |= Android.App.PendingIntentFlags.Mutable; } Android.App.PendingIntent pendingIntent = Android.App.PendingIntent.GetService(this, 0, showMainActivityIntent, intentFlags); return(pendingIntent); }
/// <summary> /// Builds the Notification.Action that will allow the user to stop the service via the /// notification in the status bar /// </summary> /// <returns>The stop service action.</returns> private NotificationCompat.Action BuildStopServiceAction() { Intent stopServiceIntent = new Intent(this, GetType()); stopServiceIntent.SetAction(ActionStopService); Android.App.PendingIntentFlags intentFlags = 0; if (Build.VERSION.SdkInt >= BuildVersionCodes.S) { intentFlags |= Android.App.PendingIntentFlags.Mutable; } Android.App.PendingIntent stopServicePendingIntent = Android.App.PendingIntent.GetService(this, 0, stopServiceIntent, intentFlags); var builder = new NotificationCompat.Action.Builder(Resource.Drawable.ic_stat_cancel, GetText(Resource.String.service_stop_comm), stopServicePendingIntent); return(builder.Build()); }
/// <summary> /// The get expansion files. /// </summary> /// <returns> /// The get expansion files. /// </returns> private bool GetExpansionFiles() { bool result = false; try { // Build the intent that launches this activity. Intent launchIntent = Intent; var intent = new Intent(this, typeof(ExpansionDownloaderActivity)); intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop); intent.SetAction(launchIntent.Action); if (launchIntent.Categories != null) { foreach (string category in launchIntent.Categories) { intent.AddCategory(category); } } // Build PendingIntent used to open this activity when user // taps the notification. Android.App.PendingIntentFlags intentFlags = Android.App.PendingIntentFlags.UpdateCurrent; if (Build.VERSION.SdkInt >= BuildVersionCodes.S) { intentFlags |= Android.App.PendingIntentFlags.Mutable; } Android.App.PendingIntent pendingIntent = Android.App.PendingIntent.GetActivity( this, 0, intent, intentFlags); // Always force download of LVL DownloadsDB.GetDB(this).UpdateMetadata(0, 0); // Request to start the download DownloaderServiceRequirement startResult = DownloaderService.StartDownloadServiceIfRequired( this, pendingIntent, typeof(ExpansionDownloaderService)); // The DownloaderService has started downloading the files, // show progress otherwise, the download is not needed so we // fall through to starting the actual app. if (startResult != DownloaderServiceRequirement.NoDownloadRequired) { InitializeDownloadUi(); result = true; } } catch (PackageManager.NameNotFoundException e) { #if DEBUG Android.Util.Log.Debug(Tag, "Cannot find own package!"); #endif e.PrintStackTrace(); } #pragma warning disable 168 catch (Exception ex) #pragma warning restore 168 { // ignored #if DEBUG Android.Util.Log.Debug(Tag, "Exception: ", EdiabasLib.EdiabasNet.GetExceptionText(ex)); #endif } return(result); }