Exemple #1
0
        void SendNotification(string messageBody)
        {
            try
            {
                var response = JsonConvert.DeserializeObject <PushNotificationRequest>(messageBody);

                var intent = new Intent(this, typeof(EventDetailActivity));
                intent.PutExtra("eventId", response.EventId);

                // intent.AddFlags(ActivityFlags.ClearTop);
                var pendingIntent = PendingIntent.GetActivity(this, 0 /* Request code */, intent, PendingIntentFlags.OneShot);

                var defaultSoundUri     = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
                var notificationBuilder = new Android.Support.V4.App.NotificationCompat.Builder(this)
                                          .SetContentTitle(response.EventTitle)
                                          .SetContentText(response.Question)
                                          .SetAutoCancel(true)
                                          .SetSound(defaultSoundUri)
                                          .SetContentIntent(pendingIntent);

                var notificationManager = NotificationManager.FromContext(this);

                notificationManager.Notify(0, notificationBuilder.Build());
            }
            catch (Exception ex) { }
        }
Exemple #2
0
        private void ReleaseResidentVehicleNotification(string jsonNotificationMessage)
        {
            try {
                NotificationCompat.Builder mBuilder = new Android.Support.V4.App.NotificationCompat.Builder(this)
                                                      .SetPriority(NotificationCompat.PriorityHigh)
                                                      .SetVibrate(new long[] { 1000, 2000, 3000 })
                                                      .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                                                      .SetSmallIcon(Resource.Mipmap.im_logo_d)
                                                      .SetContentTitle("Запит по фізичній особі")
                                                      .SetContentText("Оброблено")
                                                      .SetContentIntent(PendingIntent.GetActivity(this, 0, MainActivity.GetIntentWithParsedResidentVehicleDetail(this, jsonNotificationMessage), PendingIntentFlags.UpdateCurrent))
                                                      .SetAutoCancel(true);

                if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                {
                    mBuilder.SetVibrate(new long[] { 0 });
                }

                NotificationManager mNotificationManager = (NotificationManager)GetSystemService(Android.Content.Context.NotificationService);
                mNotificationManager.Notify(0, mBuilder.Build());
            }
            catch (Exception exc) {
                Console.WriteLine("Cant build bar notification. {0}", exc.Message);
                Debugger.Break();
            }
        }
 private void AddPlayPauseActionCompat(Android.Support.V4.App.NotificationCompat.Builder builder)
 {
     if (_player.IsPlaying)
     {
         builder.AddAction(GenerateActionCompat(Android.Resource.Drawable.IcMediaPause, "Pause", ActionPause));
     }
     else
     {
         builder.AddAction(GenerateActionCompat(Android.Resource.Drawable.IcMediaPlay, "Play", ActionPlay));
     }
 }
Exemple #4
0
        public new void NotifyExpired()
        {
            var builder = new Android.Support.V4.App.NotificationCompat.Builder(this, CHANNEL_ID)
                          .SetAutoCancel(true)                                         // Dismiss the notification from the notification area when the user clicks on it
                          .SetContentTitle("Expired Items")                            // Set the title
                          .SetSmallIcon(Resource.Drawable.Icon)                        // This is the icon to display
                          .SetContentText("You have expired Items in your inventory"); // the message to display.

            // Finally, publish the notification:
            var notificationManager = Android.Support.V4.App.NotificationManagerCompat.From(this);

            notificationManager.Notify(NOTIFICATION_ID, builder.Build());
        }
Exemple #5
0
        void createNotification(string title, string desc)
        {
            Android.Support.V4.App.NotificationCompat.Builder builder = new Android.Support.V4.App.NotificationCompat.Builder(this);
            var uiIntent            = new Intent(this, typeof(MainActivity));
            var notification1       = builder.SetContentIntent(PendingIntent.GetActivity(this, 0, uiIntent, 0)).SetSmallIcon(Resource.Drawable.Icon).SetTicker(desc).SetWhen(DateTime.Now.Millisecond).SetAutoCancel(true).SetContentTitle(title).SetContentText(desc).Build();
            var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;

            // var notification = new Notification(Resource.Drawable.Icon, title);
            //  notification.Flags = NotificationFlags.AutoCancel;
            //  notification.SetLatestEventInfo(this, title, desc, PendingIntent.GetActivity(this, 0, uiIntent, 0));

            notificationManager.Notify(1, notification1);
        }
Exemple #6
0
        void CreateNotification()
        {
            var intent = new Intent(this, typeof(MainActivity));

            // Build the notification:
            var builder = new Android.Support.V4.App.NotificationCompat.Builder(this, CHANNEL_ID)
                          .SetContentTitle("Wifi is off!!")                             // Set the title
                          .SetSmallIcon(Resource.Drawable.notification_icon_background) // This is the icon to display
                          .SetOngoing(true)
                          .SetContentIntent(PendingIntent.GetActivity(this, NOTIFICATION_ID, intent, PendingIntentFlags.CancelCurrent));

            // Finally, publish the notification:
            var notificationManager = NotificationManagerCompat.From(this);

            notificationManager.Notify(NOTIFICATION_ID, builder.Build());
        }
        void SendNotification(string messageBody, string subtitle, string message)
        {
            //Display notification however necessary
            var intent = new Intent(this, typeof(MainActivity));

            intent.AddFlags(ActivityFlags.ClearTop);
            var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);

            var notificationBuilder = new Android.Support.V4.App.NotificationCompat.Builder(this)
                                      .SetSmallIcon(Resource.Drawable.Icon)
                                      .SetStyle(new NotificationCompat.BigTextStyle().BigText(message))
                                      .SetContentTitle("title")
                                      .SetContentText(subtitle)
                                      .SetContentIntent(pendingIntent);

            var notificationManager = NotificationManager.FromContext(this);

            notificationManager.Notify(0, notificationBuilder.Build());
        }
Exemple #8
0
        private void TODO_RELEASE_TEMPORARY_NOTIFICATION_FOR_DEV(string contentText)
        {
            try {
                NotificationCompat.Builder mBuilder = new Android.Support.V4.App.NotificationCompat.Builder(this)
                                                      .SetPriority(NotificationCompat.PriorityHigh)
                                                      .SetVibrate(new long[] { 1000 })
                                                      .SetSmallIcon(Resource.Mipmap.im_logo_d)
                                                      .SetContentTitle(contentText)
                                                      .SetContentIntent(PendingIntent.GetActivity(this, 0, MainActivity.GetIntentWithParsedResidentVehicleDetail(this, "{ }"), PendingIntentFlags.UpdateCurrent))
                                                      .SetAutoCancel(true);

                NotificationManager mNotificationManager = (NotificationManager)GetSystemService(Android.Content.Context.NotificationService);
                mNotificationManager.Notify(0, mBuilder.Build());
            }
            catch (Exception exc) {
                Console.WriteLine("TODO_RELEASE_TEMPORARY_NOTIFICATION_FOR_DEV cant build bar notification. {0}", exc.Message);
                Debugger.Break();
            }
        }
        /// <summary>
        /// When we start on the foreground we will present a notification to the user
        /// When they press the notification it will take them to the main page so they can control the music
        /// </summary>
        public void StartForeground()
        {
            try
            {
                var pendingIntent = PendingIntent.GetActivity(ApplicationContext, 0,
                                                              new Intent(ApplicationContext, typeof(MainActivity)),
                                                              PendingIntentFlags.UpdateCurrent);

                var builder = new Android.Support.V4.App.NotificationCompat.Builder(Android.App.Application.Context, MainActivity.CHANNEL_ID)
                              .SetAutoCancel(true)   // Dismiss the notification from the notification area when the user clicks on it
                              .SetContentTitle("BitChute video download started")
                              .SetSmallIcon(Resource.Drawable.bitchute_notification2)
                              .SetPriority(NotificationCompat.PriorityLow);

                StartForeground(-7777, builder.Build());
            }
            catch
            {
            }
        }
        void SendNotification(Message message)
        {
            Intent intent = new Intent(this, typeof(MainActivity));

            intent.AddFlags(ActivityFlags.ClearTop);
            PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0 /* Request code */, intent, PendingIntentFlags.OneShot);

            var defaultSoundUri     = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
            var notificationBuilder = new Android.Support.V4.App.NotificationCompat.Builder(this)
                                      .SetSmallIcon(Resource.Drawable.Icon)
                                      .SetContentTitle(message.AlertType)
                                      .SetContentText(message.CreatedDate.ToString())
                                      .SetAutoCancel(true)
                                      .SetSound(defaultSoundUri)
                                      .SetContentIntent(pendingIntent);

            var notificationManager = NotificationManager.FromContext(this);

            notificationManager.Notify(0 /* ID of notification */, notificationBuilder.Build());
        }
Exemple #11
0
        /// <summary>
        /// Notification builder
        /// </summary>
        /// <param name="title"></param>
        /// <param name="text"></param>
        /// <param name="notificationID"></param>
        /// <returns></returns>
        private Android.Support.V4.App.NotificationCompat.Builder publishnotification_(string title, string text, int notificationID)
        {
            // Generate notification
            Intent notificationIntent = new Intent(ActivityContext.mActivity, typeof(MainActivity));

            Android.Support.V4.App.TaskStackBuilder stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(ActivityContext.mActivity);
            stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)));
            stackBuilder.AddNextIntent(notificationIntent);

            PendingIntent contentIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

            // Instantiate the builder and set notification elements, including
            // the pending intent:
            Android.Support.V4.App.NotificationCompat.Builder builder = new Android.Support.V4.App.NotificationCompat.Builder(ActivityContext.mActivity, CHANNEL_ID)
                                                                        .SetContentTitle(title)
                                                                        .SetContentText(text)
                                                                        .SetSmallIcon(Resource.Drawable.Icon)
                                                                        .SetAutoCancel(true)
                                                                        .SetContentIntent(contentIntent);

            // Build the notification:
            Notification notification = builder.Build();

            // Get the notification manager:
            NotificationManager notificationManager =
                ActivityContext.mActivity.GetSystemService(Context.NotificationService) as NotificationManager;

            // Publish the notification:
            notificationManager.Notify(notificationID, notification);

#if DEBUG
            Console.WriteLine("Notification published: " + notificationID);
#endif

            Log.println("Notification published: " + notificationID);

            return(builder);
        }
        //https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/hierarchical
        //https://documentation.onesignal.com/docs/customize-notification-icons
        void SendNotification(string messageBody, string _titulo)
        {
            var intent = new Intent(this, typeof(MainActivity));

            intent.AddFlags(ActivityFlags.ClearTop);
            //intent.PutExtra
            var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);

            //Bitmap largeIcon = BitmapFactory.DecodeResource(Resources, Resource.Drawable.ICONOAPP);
            var notificationManager = NotificationManager.FromContext(this);
            var notificationBuilder = new Android.Support.V4.App.NotificationCompat.Builder(this)
                                      .SetSmallIcon(Resource.Drawable.Logo_Redondo_512x512_Blanco)//color// .SetLargeIcon(largeIcon)
                                      .SetContentTitle(_titulo)
                                      .SetContentText(messageBody)
                                      .SetContentIntent(pendingIntent)
                                      .SetColor(40150209)
                                      .SetStyle(new NotificationCompat.BigTextStyle().BigText(messageBody))
                                      .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                                      .SetPriority(1)
                                      .SetAutoCancel(true);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                // The id of the channel.    ----The user-visible name of the channel.
                NotificationChannel mChannel = new NotificationChannel("channelTratoEspecial", "Canal Visible", NotificationImportance.High);
                // Configure the notification channel.
                mChannel.Description = "Description channel";
                mChannel.EnableLights(true);
                // Sets the notification light color for notifications posted to this
                // channel, if the device supports this feature.
                mChannel.LightColor = Color.Red;
                mChannel.SetShowBadge(true);
                notificationBuilder.SetChannelId("channelTratoEspecial");
                notificationManager.CreateNotificationChannel(mChannel);
            }
            notificationManager.Notify(0, notificationBuilder.Build());
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            SetContentView (Resource.Layout.MainScreen);

            TextView txtCommuteBuddy = FindViewById<TextView> (Resource.Id.selectService);
            Button btnMTA = FindViewById<Button> (Resource.Id.btnMTA);
            Button btnHighway = FindViewById<Button> (Resource.Id.btnHighway);

            btnMTA.Click += delegate {
                StartActivity(typeof(MTAfeed));
            };

            btnHighway.Click += delegate {
                StartActivity(typeof(highwayFeed));
            };

            XmlSerializer MtaSerializer = new XmlSerializer (typeof(Service), new XmlRootAttribute ("service"));
            XmlTextReader mtaReader = new XmlTextReader ("http://www.mta.info/status/serviceStatus.txt");
            Service mtaObject = (Service)MtaSerializer.Deserialize (mtaReader);

            String statusString = (String)mtaObject.mta [7].name + " - " + mtaObject.mta[7].status;
            SpannedString statusSpanned = new SpannedString (Html.FromHtml (statusString));

            int notificationId = 1000;
            Intent resultIntent = new Intent(this, typeof(MTAfeed));

            Android.Support.V4.App.TaskStackBuilder stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(this);
            stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MTAfeed)));
            stackBuilder.AddNextIntent(resultIntent);

            PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

            Android.Support.V4.App.NotificationCompat.Builder note = new Android.Support.V4.App.NotificationCompat.Builder (this)
                .SetContentTitle("Service Change")
                    .SetAutoCancel(true)
                    .SetContentIntent(resultPendingIntent)
                .SetSmallIcon(Resource.Drawable.icon)
                    .SetContentText(statusSpanned);

            NotificationManager notificationManager = (NotificationManager)GetSystemService (Context.NotificationService);
            notificationManager.Notify (notificationId, note.Build());
        }
Exemple #14
0
        public override StartCommandResult OnStartCommand(Intent karaServiceIntent, StartCommandFlags flags, int startId)
        {
            // Code not directly related to publishing the notification has been omitted for clarity.
            // Normally, this method would hold the code to be run when the service is started.
            try
            {
                if (karaServiceIntent != null && karaServiceIntent.Action != null && karaServiceIntent.Action.Equals(ACTION_STOP_SERVICE))
                {
                    StopForeground(true);
                    StopSelf();
                    (MainContext as MainActivity).Terminate();
                    //var mainIntent = new Intent(this, typeof(MainActivity));
                    ////karaServiceIntent.AddFlags(ActivityFlags.);
                    //var pendingmainIntent = PendingIntent.GetActivity(KaraNewService.MainContext, 0, mainIntent, PendingIntentFlags.UpdateCurrent);


                    return(StartCommandResult.Sticky);
                }

                if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
                {
                    NotificationChannel channel = new NotificationChannel(channelId,
                                                                          "ForgoundNotifChannel",
                                                                          Android.App.NotificationImportance.High);
                    channel.LockscreenVisibility = NotificationVisibility.Public;
                    NotificationManager nm =
                        (NotificationManager)GetSystemService(NotificationService);
                    nm.CreateNotificationChannel(channel);
                }

                var mainActivityIntent = new Intent(this, typeof(MainActivity));
                karaServiceIntent.AddFlags(ActivityFlags.SingleTop | ActivityFlags.ClearTask);
                var pendingIntent = PendingIntent.GetActivity(KaraNewService.MainContext, 0, mainActivityIntent, PendingIntentFlags.UpdateCurrent);

                if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
                {
                    var notification = new Notification.Builder(this, channelId)
                                       .SetContentTitle("کارا")
                                       .SetContentText("برنامه کارا در حال اجراست")
                                       .SetSmallIcon(Resource.Drawable.icon)
                                       .SetOngoing(true)
                                       .SetContentIntent(pendingIntent)
                                       .AddAction(BuildStopServiceAction())
                                       .Build();

                    // Enlist this instance of the service as a foreground service
                    StartForeground(SERVICE_RUNNING_NOTIFICATION_ID, notification);
                }
                else
                {
                    var notificationCompat = new Android.Support.V4.App.NotificationCompat.Builder(this, channelId)
                                             .SetContentTitle("کارا")
                                             .SetContentText("برنامه کارا در حال اجراست")
                                             .SetSmallIcon(Resource.Drawable.icon)
                                             .SetOngoing(true)
                                             .SetContentIntent(pendingIntent)
                                             .AddAction(BuildStopServiceActionCompat())
                                             .Build();

                    StartForeground(SERVICE_RUNNING_NOTIFICATION_ID, notificationCompat);
                }

                CheckForPointsForeverAsync();
            }
            catch (Exception ex)
            {
                var data = new Dictionary <string, string>();
                data.Add("extra data", "exception occured in OnStartCommand");
                Crashes.TrackError(ex, data);
            }

            return(StartCommandResult.Sticky);
        }
Exemple #15
0
        //public static void ShowOkAlert(Context context,string Message)
        //{
        //    AlertDialog.Builder alert = new AlertDialog.Builder(context);
        //    alert.SetMessage(Message);
        //    alert.SetPositiveButton("Ok", (senderAlert, args) => {
        //    });
        //    Dialog dialog = alert.Create();
        //    dialog.Show();

        //}

        //Download from url------------------------------------------
        public static async void DownLoadSource(string url, Java.IO.File _appDirectory, Java.IO.File newFile, string filePath, Context context, string FileName, int notificationId)
        {
            // ShowToast(context,  context.Resources.GetString(Resource.String.downloading) + Newsrc);

            var NotificationId = notificationId;

            string localPath;

            try
            {
                System.Uri uri       = new System.Uri(url);
                WebClient  webClient = new WebClient();
                string     localFileName;
                webClient.DownloadDataAsync(uri);



                Log.Debug("tag", "File to download = " + newFile.ToString());
                MimeTypeMap mime = MimeTypeMap.Singleton;
                String      ext  = newFile.Name.Substring(newFile.Name.IndexOf(".") + 1);
                String      type = mime.GetMimeTypeFromExtension(ext);

                Intent openFile = new Intent(Intent.ActionView, Android.Net.Uri.FromFile(newFile));
                openFile.SetDataAndType(Android.Net.Uri.FromFile(newFile), type);
                openFile.AddFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop | ActivityFlags.NewTask);


                PendingIntent p = PendingIntent.GetActivity(context, 0, openFile, 0);

                var notification = new Android.Support.V4.App.NotificationCompat.Builder(context)
                                   .SetSmallIcon(Android.Resource.Drawable.StatNotifySync)
                                   .SetContentTitle(FileName)
                                   .SetContentText(" Downloading")

                                   .SetOngoing(false);
                notification.SetProgress(0, 0, true);
                NotificationManager notificationmanager = (NotificationManager)Android.App.Application.Context.GetSystemService(Service.NotificationService);
                // Build Notification with Notification Manager

                notificationmanager.Notify((int)NotificationId, notification.Build());


                webClient.DownloadDataCompleted += (s, e) =>
                {
                    try
                    {
                        if (!_appDirectory.Exists())
                        {
                            _appDirectory.Mkdirs();
                        }
                        var bytes = e.Result; // get the downloaded data
                        {
                            notification.SetContentText(" Downloaded");
                            notification.SetContentTitle(FileName);
                            notification.SetContentIntent(p);
                            notification.SetProgress(0, 0, false);
                            notification.SetAutoCancel(true);// Notification.Flags = NotificationFlags.AutoCancel;
                            //System.IO.File.WriteAllBytes(filePath, bytes);
                            notificationmanager.Notify((int)NotificationId, notification.Build());
                            // writes to local storage
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                };
            }
            catch (System.Exception ex)
            {
            }
        }
Exemple #16
0
        public static async void SendNotifications(List <CustomNotification> notificationList)
        {
            await Task.Run(() =>
            {
                try
                {
                    if (_notificationManager == null)
                    {
                        _notificationManager = Android.Support.V4.App.NotificationManagerCompat.From(Android.App.Application.Context);
                    }
                    if (notificationList.Count == 0)
                    {
                        return;
                    }
                    int notePos = 0;

                    foreach (var note in notificationList)
                    {
                        var resultIntent      = new Intent(Android.App.Application.Context, typeof(MainActivity));
                        var valuesForActivity = new Bundle();
                        valuesForActivity.PutInt(MainActivity.COUNT_KEY, _count);
                        valuesForActivity.PutString("URL", note.NoteLink);
                        resultIntent.SetAction(MainPlaybackSticky.ActionLoadUrl);
                        resultIntent.PutExtras(valuesForActivity);
                        var resultPendingIntent = PendingIntent.GetActivity(Android.App.Application.Context, MainActivity.NOTIFICATION_ID, resultIntent, PendingIntentFlags.UpdateCurrent);
                        resultIntent.AddFlags(ActivityFlags.SingleTop);
                        var alarmAttributes = new Android.Media.AudioAttributes.Builder()
                                              .SetContentType(Android.Media.AudioContentType.Sonification)
                                              .SetUsage(Android.Media.AudioUsageKind.Notification).Build();

                        if (!_sentNotificationList.Contains(note) && notePos == 0)
                        {
                            var builder = new Android.Support.V4.App.NotificationCompat.Builder(Android.App.Application.Context, MainActivity.CHANNEL_ID + 1)
                                          .SetAutoCancel(true)                   // Dismiss the notification from the notification area when the user clicks on it
                                          .SetContentIntent(resultPendingIntent) // Start up this activity when the user clicks the intent.
                                          .SetContentTitle(note.NoteText)
                                          .SetNumber(1)
                                          .SetSmallIcon(Resource.Drawable.bitchute_notification2)
                                          .SetContentText(note.NoteType)
                                          .SetPriority(Android.Support.V4.App.NotificationCompat.PriorityMin);

                            MainActivity.NOTIFICATION_ID++;
                            // publish the notification:
                            //var notificationManager = Android.Support.V4.App.NotificationManagerCompat.From(_ctx);
                            _notificationManager.Notify(MainActivity.NOTIFICATION_ID, builder.Build());
                            _sentNotificationList.Add(note);
                            notePos++;
                        }
                        else if (!_sentNotificationList.Contains(note))
                        {
                            var builder = new Android.Support.V4.App.NotificationCompat.Builder(Android.App.Application.Context, MainActivity.CHANNEL_ID)
                                          .SetAutoCancel(true)                   // Dismiss the notification from the notification area when the user clicks on it
                                          .SetContentIntent(resultPendingIntent) // Start up this activity when the user clicks the intent.
                                          .SetContentTitle(note.NoteText)        // Set the title
                                          .SetNumber(1)                          // Display the count in the Content Info
                                                                                 //.SetLargeIcon(_notificationBMP) // This is the icon to display
                                          .SetSmallIcon(Resource.Drawable.bitchute_notification2)
                                          .SetContentText(note.NoteType)
                                          .SetPriority(Android.Support.V4.App.NotificationCompat.PriorityLow);

                            MainActivity.NOTIFICATION_ID++;

                            // publish the notification:
                            //var notificationManager = Android.Support.V4.App.NotificationManagerCompat.From(_ctx);
                            _notificationManager.Notify(MainActivity.NOTIFICATION_ID, builder.Build());
                            _sentNotificationList.Add(note);
                            notePos++;
                        }
                        MainPlaybackSticky.NotificationsHaveBeenSent = true;
                    }
                }
                catch { }
            });
        }
Exemple #17
0
        private List <Paths> SearchForSongs()
        {
            string[] filters; char[] specialChars;

            using (IXmlParsable parser = new XmlFilterParser(InternalStorageHelper.InternalXmlFileLocation + "/FiltersAndSpecialChars"))
            {
                XmlFilterParser.RVal data = (XmlFilterParser.RVal)parser.FetchItems();
                filters      = data.filters;
                specialChars = data.specialChars;
            }
            List <Track> tracksFromSD = new List <Track>();
            bool         hasSd        = false;

            try
            {
                tracksFromSD = TrackFinder.GetListOfTracksFromSD(Context, filters, specialChars);
                hasSd        = true;
            }
            catch (NotMountedException e)
            {
                ISharedPreferences prefs = Context.GetSharedPreferences(Notification_Settings.Root, FileCreationMode.Private);
                if (prefs.GetBoolean(Notification_Settings.ErrorNotKey, true))
                {
                    using (var style = new Android.Support.V7.App.NotificationCompat.BigTextStyle())
                    {
                        using (Android.Support.V7.App.NotificationCompat.Builder builder = new Android.Support.V7.App.NotificationCompat.Builder(Context))
                        {
                            using (Android.Support.V4.App.NotificationCompat.Builder not = builder
                                                                                           .SetSmallIcon(Resource.Drawable.Logo).SetContentTitle("No SD card found!").SetContentText(e.Message)
                                                                                           .SetPriority((int)NotificationPriority.Min).SetStyle(style.BigText(e.Message))
                                                                                           .SetVibrate(new long[] { 1000, 1000, 1000, 1000 }))
                            {
                                var notificationManager = (NotificationManager)Context.GetSystemService(Context.NotificationService);
                                notificationManager.Notify(0, not.Build());
                            }
                        }
                    }
                }
            }
            List <Track> tracks = new List <Track>();

            try
            {
                tracks = TrackFinder.GetListOfTracksFromPhone(Context);
            }
            catch (Exception ex)
            {
                ((Activity)Context).RunOnUiThread(() => { Toast.MakeText(Context, ex.Message, ToastLength.Long).Show(); });
            }
            if (hasSd)
            {
                tracks = tracks.Union(tracksFromSD).ToList();
            }
            List <Paths> paths = new List <Paths>();

            foreach (var track in tracks)
            {
                paths.Add(new Paths()
                {
                    Path = track.Path, Title = track.FullTitle
                });
            }
            return(paths);
        }
Exemple #18
0
        /// <summary>
        /// Download progress
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <param name="builder_"></param>
        private void DownloadFileProgressChanged(object sender, DownloadProgressChangedEventArgs e, Android.Support.V4.App.NotificationCompat.Builder builder_)
        {
            // Progress
            string s = e.UserState as String;

            string[] s_ = s.Split(new char[] { '|' });

            try
            {
                if (e.ProgressPercentage < 100)
                {
                    // Notification
                    builder_.SetContentTitle("Downloading - " + e.ProgressPercentage + " %");
                    builder_.SetProgress(100, e.ProgressPercentage, false);
                }
                else
                {
                    builder_.SetContentTitle("Download completed");
                    builder_.SetProgress(100, e.ProgressPercentage, false);
                }

                NotificationManager notificationManager = (NotificationManager)ActivityContext.mActivity.GetSystemService(Context.NotificationService);
                notificationManager.Notify(Convert.ToInt32(s_[2]), builder_.Build());
            }
            catch
            {
            }

#if DEBUG
            Console.WriteLine(e.ProgressPercentage + " %");
#endif

            Log.println(e.ProgressPercentage + " %");
        }
Exemple #19
0
        /// <summary>
        /// Download file
        /// </summary>
        /// <param name="URL"></param>
        /// <param name="Title"></param>
        /// <param name="isVideo"></param>
        private void DownloadFile(string URL, string Title, bool isVideo, string file_extension)
        {
            WebClient DownloadFile = new WebClient();

            // Event when download progess changed
            int notificationID = uniquenotificationID();

            Android.Support.V4.App.NotificationCompat.Builder builder_ = publishnotification_("Downloading", Title, notificationID);

            DownloadFile.DownloadProgressChanged += (sender, e) => DownloadFileProgressChanged(sender, e, builder_);

            // Event when download completed
            DownloadFile.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted);

            // Start download
            var directory = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads);

            // Check if directory exists
            try
            {
                if (!System.IO.Directory.Exists(directory.AbsolutePath))
                {
                    System.IO.Directory.CreateDirectory(directory.AbsolutePath);
                }
            }
            catch { }

            string file = string.Empty;

            if (isVideo)
            {
                file = Path.Combine(directory.AbsolutePath, makeFilenameValid(Title).Replace("/", "")
                                    .Replace(".", "")
                                    .Replace("|", "")
                                    .Replace("?", "")
                                    .Replace("!", "") + file_extension);
            }
            else
            {
                if (URL.Contains("youtube"))
                {
                    file = Path.Combine(directory.AbsolutePath, makeFilenameValid(Title).Replace("/", "")
                                        .Replace(".", "")
                                        .Replace("|", "")
                                        .Replace("?", "")
                                        .Replace("!", "") + ".m4a");
                }
                else
                {
                    file = Path.Combine(directory.AbsolutePath, makeFilenameValid(Title).Replace("/", "")
                                        .Replace(".", "")
                                        .Replace("|", "")
                                        .Replace("?", "")
                                        .Replace("!", "") + ".mp3");
                }
            }

#if DEBUG
            Console.WriteLine(file);
#endif

            Log.println(file);

            DownloadFile.DownloadFileAsync(new Uri(URL), file, file + "|" + Title + "|" + notificationID);

#if DEBUG
            Console.WriteLine("Download started");
#endif

            Log.println("Download started");
        }
Exemple #20
0
        public static Notification BuildPlayControlNotification()
        {
            var pendingIntent = PendingIntent.GetActivity(Android.App.Application.Context, 0,
                                                          new Intent(Android.App.Application.Context, typeof(MainActivity)),
                                                          PendingIntentFlags.UpdateCurrent);


            // Using RemoteViews to bind custom layouts into Notification
            RemoteViews views    = new RemoteViews(Android.App.Application.Context.PackageName, Resource.Layout.PlaystateNotification);
            RemoteViews bigViews = new RemoteViews(Android.App.Application.Context.PackageName, Resource.Layout.PlaystateNotification);



            Intent notificationIntent = new Intent(Android.App.Application.Context, typeof(MainActivity));

            Intent previousIntent = new Intent(Android.App.Application.Context, typeof(MainPlaybackSticky));

            previousIntent.SetAction(MainPlaybackSticky.ActionPrevious);
            PendingIntent ppreviousIntent = PendingIntent.GetService(Android.App.Application.Context, 0, previousIntent, 0);
            Intent        playIntent      = new Intent(Android.App.Application.Context, typeof(MainPlaybackSticky));

            playIntent.SetAction(MainPlaybackSticky.ActionPlay);
            PendingIntent pplayIntent = PendingIntent.GetService(Android.App.Application.Context, 0, playIntent, 0);
            Intent        nextIntent  = new Intent(Android.App.Application.Context, typeof(MainPlaybackSticky));

            nextIntent.SetAction(MainPlaybackSticky.ActionNext);
            PendingIntent pnextIntent = PendingIntent.GetService(Android.App.Application.Context, 0, nextIntent, 0);
            Intent        pauseIntent = new Intent(Android.App.Application.Context, typeof(MainPlaybackSticky));

            pauseIntent.SetAction(MainPlaybackSticky.ActionPause);
            PendingIntent ppauseIntent          = PendingIntent.GetService(Android.App.Application.Context, 0, pauseIntent, 0);
            Intent        playNoteInBkgrdIntent = new Intent(Android.App.Application.Context, typeof(MainPlaybackSticky));

            playNoteInBkgrdIntent.SetAction(MainPlaybackSticky.ActionBkgrdNote);
            PendingIntent pplayNoteInBkgrdIntent = PendingIntent.GetService(Android.App.Application.Context, 0, playNoteInBkgrdIntent, 0);
            Intent        playNoteResumeIntent   = new Intent(Android.App.Application.Context, typeof(MainPlaybackSticky));

            playNoteResumeIntent.SetAction(MainPlaybackSticky.ActionResumeNote);
            PendingIntent pplayNoteResumeIntent = PendingIntent.GetService(Android.App.Application.Context, 0, playNoteResumeIntent, 0);


            views.SetOnClickPendingIntent(Resource.Id.notificationPlay, pplayIntent);
            bigViews.SetOnClickPendingIntent(Resource.Id.notificationPlay, pplayIntent);
            views.SetOnClickPendingIntent(Resource.Id.notificationPause, ppauseIntent);
            bigViews.SetOnClickPendingIntent(Resource.Id.notificationPause, ppauseIntent);
            views.SetOnClickPendingIntent(Resource.Id.notificationNext, pnextIntent);
            bigViews.SetOnClickPendingIntent(Resource.Id.notificationNext, pnextIntent);
            views.SetOnClickPendingIntent(Resource.Id.notificationPrevious, ppreviousIntent);
            bigViews.SetOnClickPendingIntent(Resource.Id.notificationPrevious, ppreviousIntent);
            bigViews.SetOnClickPendingIntent(Resource.Id.notificationPlaysInBkgrdOnRb, pplayNoteInBkgrdIntent);
            views.SetOnClickPendingIntent(Resource.Id.notificationPlaysInBkgrdOnRb, pplayNoteInBkgrdIntent);
            bigViews.SetOnClickPendingIntent(Resource.Id.notificationPlaysInBkgrdOffRb, pplayNoteResumeIntent);
            views.SetOnClickPendingIntent(Resource.Id.notificationPlaysInBkgrdOffRb, pplayNoteResumeIntent);

            var builder = new Android.Support.V4.App.NotificationCompat.Builder(Android.App.Application.Context, MainActivity.BACKGROUND_CHANNEL_ID)
                          //.SetAutoCancel(true) // Dismiss the notification from the notification area when the user clicks on it
                          .SetContentTitle("BitChute streaming in background")
                          .SetSmallIcon(Resource.Drawable.bitchute_notification2)
                          .SetOngoing(true)
                          .SetPriority(Android.Support.V4.App.NotificationCompat.PriorityMax);

            var status = builder.Build();

            status.ContentView    = views;
            status.BigContentView = bigViews;
            status.Priority       = (int)NotificationPriority.Max;
            status.Icon           = Resource.Drawable.bitchute_notification2;
            status.ContentIntent  = pendingIntent;
            return(status);
        }