public void UpdatePlayPause()
 {
     if (AndroidMediaManager.SharedInstance.IsPlaying)
     {
         notificationBuilder.SetOngoing(true);
     }
     else
     {
         notificationBuilder.SetOngoing(false);
     }
     notification = notificationBuilder.Build();
     notificationManager.Notify(0, notification);
 }
        void SetNotificationPlaybackState(Notification.Builder builder)
        {
            var beginningOfTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            LogHelper.Debug(Tag, "updateNotificationPlaybackState. mPlaybackState=" + playbackState);
            if (playbackState == null || !started)
            {
                LogHelper.Debug(Tag, "updateNotificationPlaybackState. cancelling notification!");
                service.StopForeground(true);
                return;
            }
            if (playbackState.State == PlaybackStateCode.Playing &&
                playbackState.Position >= 0)
            {
                var timespan = ((long)(DateTime.UtcNow - beginningOfTime).TotalMilliseconds) - playbackState.Position;
                LogHelper.Debug(Tag, "updateNotificationPlaybackState. updating playback position to ", timespan / 1000, " seconds");

                builder.SetWhen(timespan).SetShowWhen(true).SetUsesChronometer(true);
            }
            else
            {
                LogHelper.Debug(Tag, "updateNotificationPlaybackState. hiding playback position");
                builder.SetWhen(0).SetShowWhen(false).SetUsesChronometer(false);
            }

            // Make sure that the notification can be dismissed by the user when we are not playing:
            builder.SetOngoing(playbackState.State == PlaybackStateCode.Playing);
        }
        private void Completed(object sender, AsyncCompletedEventArgs e)
        {
            timer.Stop();
            timer.Dispose();
            notificationManager.Cancel(notificationID);

            notificationID      = new System.Random().Next(10000, 99999);
            notificationBuilder = new Notification.Builder(ApplicationContext);
            notificationBuilder.SetOngoing(false)
            .SetSmallIcon(Resource.Drawable.icon);

            if (e.Cancelled == false && e.Error == null)
            {
                notificationBuilder.SetContentTitle("Download complete");
            }
            else
            {
                notificationBuilder.SetContentTitle("Upload failed");
            }

            notification = notificationBuilder.Build();
            notificationManager.Notify(notificationID, notification);

            notificationID = 0;

            notificationBuilder.Dispose();
            notification.Dispose();
            notificationManager.Dispose();

            uploadedBytes   = 0;
            totalBytes      = 0;
            percentComplete = 0;

            wClient.Dispose();
        }
Ejemplo n.º 4
0
        static NotificationHandler()
        {
            Intent intent = new Intent(Application.Context, typeof(CurrentSong));

            intent.AddFlags(ActivityFlags.SingleTop);
            PendingIntent pendingIntent = PendingIntent.GetActivity(Application.Context, 0, intent, PendingIntentFlags.UpdateCurrent);

            builder = new Notification.Builder(Application.Context, CHANNEL_ID);
            builder.SetContentIntent(pendingIntent);

            builder.SetOngoing(true);

            if (Android.OS.Build.VERSION.SdkInt <= Android.OS.BuildVersionCodes.M)
            {
                CreateNotificationMediaActions();
            }

            notificationManager = Application.Context.GetSystemService(Context.NotificationService) as NotificationManager;

            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
            {
                /* Create or update. */
                NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
                                                                      "tubeload song notification",
                                                                      NotificationImportance.Min);
                notificationManager.CreateNotificationChannel(channel);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Update the notification.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The updated notification.
        /// </returns>
        public Notification UpdateNotification(Context context)
        {
            var builder = new Notification.Builder(context);

            if (!string.IsNullOrEmpty(this.PausedText))
            {
                builder.SetContentTitle(this.PausedText);
                builder.SetContentText(string.Empty);
                builder.SetContentInfo(string.Empty);
            }
            else
            {
                builder.SetContentTitle(this.Title);
                if (this.TotalBytes > 0 && this.CurrentBytes != -1)
                {
                    builder.SetProgress((int)(this.TotalBytes >> 8), (int)(this.CurrentBytes >> 8), false);
                }
                else
                {
                    builder.SetProgress(0, 0, true);
                }

                builder.SetContentText(Helpers.GetDownloadProgressString(this.CurrentBytes, this.TotalBytes));
                builder.SetContentInfo(string.Format("{0}s left", Helpers.GetTimeRemaining(this.TimeRemaining)));
            }

            builder.SetSmallIcon(this.Icon != 0 ? this.Icon : Android.Resource.Drawable.StatSysDownload);
            builder.SetOngoing(true);
            builder.SetTicker(this.Ticker);
            builder.SetContentIntent(this.PendingIntent);

            return(builder.Notification);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Update the notification.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The updated notification.
        /// </returns>
        public Notification UpdateNotification(Context context)
        {
            if (builder == null)
            {
                builder = new Notification.Builder(context);
            }

            builder.SetContentTitle(this.Title);
            if (this.TotalBytes > 0 && this.CurrentBytes != -1)
            {
                builder.SetProgress((int)(this.TotalBytes >> 8), (int)(this.CurrentBytes >> 8), false);
            }
            else
            {
                builder.SetProgress(0, 0, true);
            }
            builder.SetContentText(Helpers.GetDownloadProgressString(this.CurrentBytes, this.TotalBytes));
            builder.SetContentInfo(context.GetString(Resource.String.time_remaining_notification, Helpers.GetTimeRemaining(this.TimeRemaining)));
            builder.SetSmallIcon(this.Icon != 0 ? this.Icon : Android.Resource.Drawable.StatSysDownload);
            builder.SetOngoing(true);
            builder.SetTicker(this.Ticker);
            builder.SetContentIntent(this.PendingIntent);

            return(builder.Notification);
        }
        public void checkchange()
        {
            while (true)
            {
                IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
                foreach (IPAddress ip in localIPs)
                {
                    if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        if (ipadre != ip.ToString())
                        {
                            servidor.Stop();
                            ipadre = ip.ToString();



                            servidor = new MultitubeWebServer(Android.OS.Environment.ExternalStorageDirectory.ToString(), 12345, ipadre, this);
                            var brandom = new Random();

                            Intent internado2                 = new Intent(this, typeof(serviciointerpreter23));
                            Intent internado3                 = new Intent(this, typeof(serviciointerpreter234));
                            var    pendingIntent3             = PendingIntent.GetService(ApplicationContext, brandom.Next(2000, 50000) + brandom.Next(2000, 50000), internado3, 0);
                            var    pendingIntent2             = PendingIntent.GetService(ApplicationContext, brandom.Next(2000, 50000) + brandom.Next(2000, 50000), internado2, 0);
                            Notification.Action       accion  = new Notification.Action(Resource.Drawable.drwaable, "Parar", pendingIntent2);
                            Notification.Action       accion2 = new Notification.Action(Resource.Drawable.drwaable, "Conectarse", pendingIntent3);
                            Notification.BigTextStyle textoo  = new Notification.BigTextStyle();
                            textoo.SetBigContentTitle("Stremeando en " + ipadre + ":12345");
                            textoo.SetSummaryText("Toque para parar de stremear su media");
                            textoo.BigText("Para conectarse introduzca " + ipadre + ":12345  " + "en su navegador o entre a multitubeweb.tk y toque conectar luego escanee el codigo que aparece al presionar el boton de + en multitubeweb.   al tocar parar se cierrar el servicio de streaming");


#pragma warning disable CS0618 // El tipo o el miembro están obsoletos
                            Notification.Builder nBuilder = new Notification.Builder(this);
#pragma warning restore CS0618 // El tipo o el miembro están obsoletos
                            nBuilder.SetContentTitle("Stremeando en " + ipadre + ":12345");
                            nBuilder.SetContentText("Toque para parar de stremear su media");
                            nBuilder.SetStyle(textoo);
                            nBuilder.SetColor(Android.Graphics.Color.DarkRed.ToArgb());
                            nBuilder.SetOngoing(true);
                            //   nBuilder.SetContentIntent(pendingIntent2);
                            nBuilder.SetSmallIcon(Resource.Drawable.antena);
                            nBuilder.AddAction(accion);
                            nBuilder.AddAction(accion2);
                            Notification notification = nBuilder.Build();
                            StartForeground(193423456, notification);



                            if (CheckInternetConnection() && Constants.UseFirebase)
                            {
                                meterdata();
                            }
                        }
                    }
                }
                MultiHelper.ExecuteGarbageCollection();
                Thread.Sleep(5000);
            }
        }
Ejemplo n.º 8
0
 public override void OnCreate()
 {
     Notification.Builder builder = new Notification.Builder(ApplicationContext);
     builder.SetContentTitle("DSAMobile");
     builder.SetContentText("DSAMobile service is running");
     builder.SetOngoing(true);
     _serviceNotification = builder.Build();
 }
        /// <summary>
        ///     Updates IsPlaying action on Notification and toggle dismissable status
        /// </summary>
        /// <param name="playbackSpeed">Unused for Android</param>
        public void UpdateIsPlaying(float playbackSpeed = -1)
        {
            var isPlaying = AndroidAudioPlayer.SharedInstance.IsPlaying;

            if (isPlaying)
            {
                notificationBuilder.SetOngoing(true);
                notificationBuilder.SetSmallIcon(Android.Resource.Drawable.IcMediaPlay);
            }
            else
            {
                notificationBuilder.SetOngoing(false);
                notificationBuilder.SetSmallIcon(Android.Resource.Drawable.IcMediaPause);
            }

            notification            = notificationBuilder.Build();
            notification.Actions[1] = isPlaying ? pauseAction : playAction;
            Notify();
        }
        private void WClient_UploadFileCompleted(object sender, System.Net.UploadFileCompletedEventArgs e)
        {
            timer.Stop();
            timer.Dispose();

            notificationManager.Cancel(notificationID);

            notificationID      = new Random().Next(10000, 99999);
            notificationBuilder = new Notification.Builder(ApplicationContext);
            notificationBuilder.SetOngoing(false)
            .SetSmallIcon(Resource.Drawable.icon);

            if (e.Cancelled == false && e.Error == null)
            {
                JsonResult result = JsonConvert.DeserializeObject <JsonResult>(System.Text.Encoding.UTF8.GetString(e.Result));

                if (result != null && result.Success == true)
                {
                    notificationBuilder.SetContentTitle("Upload complete");
                }
                else
                if (result.Success == false)
                {
                    notificationBuilder.SetContentTitle("Upload failed");
                    Intent        notificationIntent = new Intent(ApplicationContext, typeof(UploadErrorActivity));
                    PendingIntent contentIntent      = PendingIntent.GetActivity(ApplicationContext,
                                                                                 0, notificationIntent, PendingIntentFlags.UpdateCurrent);
                    notificationBuilder.SetContentIntent(contentIntent);
                    notificationBuilder.SetContentText(result.Message);
                    notificationBuilder.SetAutoCancel(true);
                }
            }
            else
            {
                notificationBuilder.SetContentTitle("Upload failed");
            }

            notification = notificationBuilder.Build();
            notificationManager.Notify(notificationID, notification);

            notificationID = 0;

            notificationBuilder.Dispose();
            notification.Dispose();
            notificationManager.Dispose();

            uploadedBytes   = 0;
            totalBytes      = 0;
            percentComplete = 0;
            wClient.Dispose();
        }
Ejemplo n.º 11
0
 private void InitNotification()
 {
     if (mNotificationBuilder == null)
     {
         mNotificationBuilder = new Notification.Builder(this);
         mNotificationBuilder.SetSmallIcon(Resource.Drawable.Ares);
         mNotificationBuilder.SetOngoing(true);
         TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this);
         stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)));
         Intent resultIntent = new Intent(this, typeof(MainActivity));
         stackBuilder.AddNextIntent(resultIntent);
         PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, PendingIntentFlags.UpdateCurrent);
         mNotificationBuilder.SetContentIntent(resultPendingIntent);
         mNotificationBuilder.SetPriority((int)NotificationPriority.Low);
     }
 }
        private async System.Threading.Tasks.Task UploadSingleFile(VideoDownloadInfo file)
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(file.VideoUrl);

            req.Method = "HEAD";
            HttpWebResponse resp = (HttpWebResponse)(req.GetResponse());

            totalBytes = resp.ContentLength;

            uploadedBytes   = 0;
            percentComplete = 0;

            Decimal fileSizeInMB  = Convert.ToDecimal(totalBytes) / (1024.0m * 1024.0m);
            var     totalfileSize = Math.Round(fileSizeInMB, 2);

            notificationManager = (NotificationManager)GetSystemService(NotificationService);
            notificationBuilder = new Notification.Builder(ApplicationContext);
            notificationBuilder.SetOngoing(true)
            .SetSmallIcon(Resource.Drawable.ic_file_download_white_18dp)
            .SetContentTitle("Downloading")
            .SetContentText(

                Math.Round((Convert.ToDecimal(uploadedBytes) / (1024.0m * 1024.0m)), 2) + " MB of " + totalfileSize + " MB")
            .SetProgress(100, percentComplete, false);

            notification   = notificationBuilder.Build();
            notificationID = new System.Random().Next(10000, 99999);
            notificationManager.Notify(notificationID, notification);

            timer          = new System.Timers.Timer();
            timer.Elapsed += Timer_Elapsed;
            timer.Interval = 1000;
            timer.Enabled  = true;
            timer.Start();

            wClient = new WebClient();
            wClient.DownloadFileCompleted   += new AsyncCompletedEventHandler(Completed);
            wClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);

            await wClient.DownloadFileTaskAsync(new Uri(file.VideoUrl), GetOutputVideoPath(file.VideoFileName));           // Defines the URL and destination directory for the downloaded file
        }
Ejemplo n.º 13
0
        /// <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>
        void StartForeground()
        {
            var intent = new Intent(ApplicationContext, typeof(MainActivity));

            intent.SetAction(Intent.ActionMain);
            intent.AddCategory(Intent.CategoryLauncher);
            ExtraUtils.PutSelectedTab(intent, (int)MainActivity.TabTitle.Player);

            var pendingIntent = PendingIntent.GetActivity(
                ApplicationContext,
                0,
                intent,
                PendingIntentFlags.UpdateCurrent
                );

            var notificationBuilder = new Notification.Builder(ApplicationContext);

            notificationBuilder.SetContentTitle(CurrentEpisode.Title);
            notificationBuilder.SetContentText(
                String.Format(
                    ApplicationContext.GetString(Resource.String.NotificationContentText),
                    ApplicationContext.GetString(Resource.String.ApplicationName)
                    )
                );
            notificationBuilder.SetSmallIcon(Resource.Drawable.ic_stat_av_play_over_video);
            notificationBuilder.SetTicker(
                String.Format(
                    Application.GetString(Resource.String.NoticifationTicker),
                    CurrentEpisode.Title
                    )
                );
            notificationBuilder.SetOngoing(true);
            notificationBuilder.SetContentIntent(pendingIntent);

            StartForeground(NotificationId, notificationBuilder.Build());
        }
Ejemplo n.º 14
0
        /// <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>
        void StartForeground ()
        {
            var intent = new Intent (ApplicationContext, typeof (MainActivity));
            intent.SetAction (Intent.ActionMain);
            intent.AddCategory (Intent.CategoryLauncher);
            ExtraUtils.PutSelectedTab (intent, (int) MainActivity.TabTitle.Player);

            var pendingIntent = PendingIntent.GetActivity (
                ApplicationContext,
                0,
                intent,
                PendingIntentFlags.UpdateCurrent
            );

            var notificationBuilder = new Notification.Builder (ApplicationContext);
            notificationBuilder.SetContentTitle (CurrentEpisode.Title);
            notificationBuilder.SetContentText (
                String.Format (
                    ApplicationContext.GetString (Resource.String.NotificationContentText),
                    ApplicationContext.GetString (Resource.String.ApplicationName)
                )
            );
            notificationBuilder.SetSmallIcon (Resource.Drawable.ic_stat_av_play_over_video);
            notificationBuilder.SetTicker (
                String.Format (
                    Application.GetString (Resource.String.NoticifationTicker),
                    CurrentEpisode.Title
                )
            );
            notificationBuilder.SetOngoing (true);
            notificationBuilder.SetContentIntent (pendingIntent);

            StartForeground (NotificationId, notificationBuilder.Build());
        }
        private async Task UploadSingleFile(MediaFile file)
        {
            Uri uri;

            if (file.MediaType == Core.Model.MediaType.Photo)
            {
                uri = new Uri(GlobalClass.BaseUrl + "Event/UploadEventFiles?eventid=" + file.EventID);
            }
            else
            {
                uri = new Uri(GlobalClass.BaseUrl + "Event/UploadVideo?eventid=" + file.EventID);
            }

            string uploadFilePath = file.FilePath;

            Java.IO.File mediaFile = new Java.IO.File(uploadFilePath);
            totalBytes = mediaFile.Length();

            if (totalBytes == 0)
            {
                return;
            }

            double totalMB = Convert.ToDouble(totalBytes) / (1024 * 1024); // Size in MB

            if (totalMB > MaxVideoSize)
            {
                notificationBuilder = new Notification.Builder(ApplicationContext);
                notificationManager = (NotificationManager)GetSystemService(NotificationService);

                notificationBuilder.SetOngoing(false)
                .SetSmallIcon(Resource.Drawable.icon);

                notificationBuilder.SetContentTitle("Upload failed");
                Intent        notificationIntent = new Intent(ApplicationContext, typeof(UploadErrorActivity));
                PendingIntent contentIntent      = PendingIntent.GetActivity(ApplicationContext,
                                                                             0, notificationIntent, PendingIntentFlags.UpdateCurrent);
                notificationBuilder.SetContentIntent(contentIntent);
                notificationBuilder.SetContentText("Video size is too large");
                notificationBuilder.SetAutoCancel(true);

                notification   = notificationBuilder.Build();
                notificationID = new Random().Next(10000, 99999);
                notificationManager.Notify(notificationID, notification);
                notificationID = 0;
                notificationBuilder.Dispose();
                notification.Dispose();
                notificationManager.Dispose();

                return;
            }
            else

            //  && (totalBytes / 1024) > 500
            if (file.MediaType == Core.Model.MediaType.Photo)
            {
                uploadFilePath = CompressFile.compressImage(uploadFilePath);
                mediaFile      = new Java.IO.File(uploadFilePath);
                totalBytes     = mediaFile.Length();
            }

            uploadedBytes   = 0;
            percentComplete = 0;
            var totalfileSize = Math.Round(totalMB, 2);

            notificationManager = (NotificationManager)GetSystemService(NotificationService);
            notificationBuilder = new Notification.Builder(ApplicationContext);
            notificationBuilder.SetOngoing(true)
            .SetSmallIcon(Resource.Drawable.ic_file_upload_white_18dp)
            .SetContentTitle("Uploading")
            .SetContentText
                (Math.Round((Convert.ToDecimal(uploadedBytes) / (1024.0m * 1024.0m)), 2) + " MB of " + totalfileSize + " MB")
            .SetProgress(100, percentComplete, false);

            notification   = notificationBuilder.Build();
            notificationID = new Random().Next(10000, 99999);
            notificationManager.Notify(notificationID, notification);
            try
            {
                timer          = new System.Timers.Timer();
                timer.Elapsed += Timer_Elapsed;
                timer.Interval = 1000;
                timer.Enabled  = true;
                timer.Start();
            }
            catch (Exception ex)
            {
                throw;
            }

            wClient = new WebClient();
            wClient.Headers.Add("authorization", "bearer " + GlobalClass.AccessToken);
            wClient.UploadFileAsync(uri, uploadFilePath);
            wClient.UploadProgressChanged += new UploadProgressChangedEventHandler(ProgressChanged);
            wClient.UploadFileCompleted   += WClient_UploadFileCompleted;
        }
        private void CreateBuilder()
        {
            var builder = new Notification.Builder(Application.Context, channelId);

            builder.SetChannelId(channelId);

            //Configure builder
            builder.SetContentTitle("track title goes here");
            builder.SetContentText("artist goes here");
            builder.SetWhen(0);

            //TODO: set if the notification can be destroyed by swiping
            //if (infos.dismissable)
            //{
            //	builder.setOngoing(false);
            //	Intent dismissIntent = new Intent("music-controls-destroy");
            //	PendingIntent dismissPendingIntent = PendingIntent.getBroadcast(context, 1, dismissIntent, 0);
            //	builder.setDeleteIntent(dismissPendingIntent);
            //}
            //else
            //{
            //	builder.setOngoing(true);
            //}
            if (AndroidMediaManager.SharedInstance.IsPlaying)
            {
                builder.SetOngoing(true);
            }
            else
            {
                builder.SetOngoing(false);
            }

            //If 5.0 >= set the controls to be visible on lockscreen
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                builder.SetVisibility(NotificationVisibility.Public);
            }

            //Set SmallIcon (Notification Icon in top bar)
            builder.SetSmallIcon(Android.Resource.Drawable.IcMediaPlay);

            //TODO: Set LargeIcon
            // builder.SetLargeIcon(AlbumArt.jpg);

            //TODO: Open app if tapped
            //Intent resultIntent = new Intent(context, typeof(Application));
            //resultIntent.SetAction(Intent.ActionMain);
            //resultIntent.AddCategory(Intent.CategoryLauncher);
            //PendingIntent resultPendingIntent = PendingIntent.GetActivity(context, 0, resultIntent, 0);
            //builder.SetContentIntent(resultPendingIntent);

            //Controls
            var controlsCount = 0;

            /* Previous  */
            controlsCount++;
            builder.AddAction(previousAction);

            /* Play/Pause */
            if (AndroidMediaManager.SharedInstance.IsPlaying)
            {
                controlsCount++;
                builder.AddAction(pauseAction);
            }
            else
            {
                controlsCount++;
                builder.AddAction(playAction);
            }

            /* Next */
            controlsCount++;
            builder.AddAction(nextAction);

            /* Close */
            //controlsCount++;
            //builder.AddAction(destroyAction);

            //If 5.0 >= use MediaStyle
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                int[] args = new int[controlsCount];
                for (int i = 0; i < controlsCount; ++i)
                {
                    args[i] = i;
                }
                var style = new Notification.MediaStyle();
                style.SetShowActionsInCompactView(args);
                builder.SetStyle(style);
            }

            this.notificationBuilder = builder;
        }
        public override void OnCreate()
        {
            instancia = this;
            IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
            foreach (IPAddress ip in localIPs)
            {
                if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    ipadre = ip.ToString();
                }
            }



            new Thread(() =>
            {
                if (CheckInternetConnection())
                {
                    bool notienenada = false;

                    WebClient cliente = new WebClient();
                    cliente.DownloadDataAsync(new Uri("https://raw.githubusercontent.com/Gr3gorywolf/Multitube.android/master/Updates/version.gr3v"));
                    cliente.DownloadDataCompleted += (aaa, aaaa) =>
                    {
                        string versionsinparsear = Encoding.UTF8.GetString(aaaa.Result);
                        if (!File.Exists(Android.OS.Environment.ExternalStorageDirectory.ToString() + "/.gr3cache/version.gr3v"))
                        {
                            notienenada = true;
                        }
                        if (notienenada)
                        {
                            MultitubeWebHelper.UpdateMultitubeWeb(versionsinparsear);
                        }
                        else
                        {
                            if (versionsinparsear != File.ReadAllText(Android.OS.Environment.ExternalStorageDirectory.ToString() + "/.gr3cache/version.gr3v"))
                            {
                                MultitubeWebHelper.UpdateMultitubeWeb(versionsinparsear);
                            }
                        }
                    };
                    if (Constants.UseFirebase)
                    {
                        meterdata();
                    }
                }
                else
                {
                }
            }).Start();
            if (servidor != null)
            {
                servidor.Stop();
            }

            servidor = new MultitubeWebServer(Android.OS.Environment.ExternalStorageDirectory.ToString(), 12345, ipadre, this);
            var pelo = new Thread(() =>
            {
                checkchange();
            });

            pelo.IsBackground = true;
            pelo.Start();



            var brandom = new Random();

            Intent internado2     = new Intent(this, typeof(serviciointerpreter23));
            Intent internado3     = new Intent(this, typeof(serviciointerpreter234));
            var    pendingIntent3 = PendingIntent.GetService(ApplicationContext, brandom.Next(2000, 50000) + brandom.Next(2000, 50000), internado3, 0);
            var    pendingIntent2 = PendingIntent.GetService(ApplicationContext, brandom.Next(2000, 50000) + brandom.Next(2000, 50000), internado2, 0);

            Notification.Action accion  = new Notification.Action(Resource.Drawable.drwaable, "Parar", pendingIntent2);
            Notification.Action accion2 = new Notification.Action(Resource.Drawable.drwaable, "Conectarse", pendingIntent3);

            Notification.BigTextStyle textoo = new Notification.BigTextStyle();
            textoo.SetBigContentTitle("Stremeando en " + ipadre + ":12345");
            textoo.SetSummaryText("Toque para parar de stremear su media");
            textoo.BigText("Para conectarse introduzca " + ipadre + ":12345  " + "en su navegador o entre a multitubeweb.tk y toque conectar luego escanee el codigo que aparece al presionar el boton de + en multitubeweb.   al tocar parar se cierrar el servicio de streaming");


#pragma warning disable CS0618 // El tipo o el miembro están obsoletos
            Notification.Builder nBuilder = new Notification.Builder(this);
#pragma warning restore CS0618 // El tipo o el miembro están obsoletos
            nBuilder.SetContentTitle("Stremeando en " + ipadre + ":12345");
            nBuilder.SetContentText("Toque para parar de stremear su media");

            nBuilder.SetOngoing(true);
            //  nBuilder.SetContentIntent(pendingIntent2);
            nBuilder.SetStyle(textoo);
            nBuilder.SetSmallIcon(Resource.Drawable.antena);
            nBuilder.SetColor(Android.Graphics.Color.ParseColor("#ce2c2b"));
            nBuilder.AddAction(accion);
            nBuilder.AddAction(accion2);

            Notification notification = nBuilder.Build();
            StartForeground(193423456, notification);
            base.OnCreate();
            //  descargar(intent.GetStringExtra("path"), intent.GetStringExtra("archivo"), intent.GetStringExtra("titulo"), intent.GetStringExtra("link"));
        }
Ejemplo n.º 18
0
        private void StartBot()
        {
            this.RunOnUiThread(() =>
            {
                Toast.MakeText(this, Resource.String.botrun_starting, ToastLength.Short).Show();

                var nb = new Notification.Builder(this);
                nb.SetContentTitle(this.GetString(Resource.String.servicenotif_botrunning));
                nb.SetContentText(this.GetString(Resource.String.servicenotif_botopen));
                nb.SetSmallIcon(Resource.Drawable.Iconmini);
                nb.SetOngoing(true);
                nb.SetAutoCancel(false);

                this.ServiceNotification = nb.Build();

                this.ServiceNotificationIntent = new Intent(this, this.GetType());
                this.ServiceNotificationIntent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
                var intent = PendingIntent.GetActivity(this, 0, this.ServiceNotificationIntent, 0);

                this.ServiceNotification.SetLatestEventInfo(this, this.GetString(Resource.String.servicenotif_botrunning), this.GetString(Resource.String.servicenotif_botopen), intent);
                this.ServiceNotification.Flags |= NotificationFlags.NoClear | NotificationFlags.OngoingEvent;

                this.NotificationManager.Notify(PERMID_NOTIFICATION, this.ServiceNotification);
            });

            var pth = Environment.ExternalStorageDirectory.AbsolutePath;

            pth = Path.Combine(pth, "emzi0767", "companioncube");

            if (!Directory.Exists(pth))
            {
                Directory.CreateDirectory(pth);
            }

            var utf8 = new UTF8Encoding(false);
            var aid  = Settings.System.GetString(this.ContentResolver, Settings.Secure.AndroidId);
            var akey = utf8.GetBytes(aid);
            var aiv  = new byte[16];
            var rng  = new RNGCryptoServiceProvider();
            var cc   = 0ul;

            pth = Path.Combine(pth, "settings.bin");
            if (File.Exists(pth))
            {
                using (var fs = File.OpenRead(pth))
                    using (var br = new BinaryReader(fs))
                        aiv = br.ReadBytes(aiv.Length);
            }
            else
            {
                rng.GetBytes(aiv);
            }

            cc = BitConverter.ToUInt16(aiv, 0);

            using (var sha256 = SHA256Managed.Create())
                for (var i = 0u; i < cc; i++)
                {
                    akey = sha256.ComputeHash(akey);
                }

            var token = "";

            using (var aes = RijndaelManaged.Create())
            {
                if (!File.Exists(pth))
                {
                    this.RunOnUiThread(() =>
                    {
                        var dm = Resources.DisplayMetrics;

                        var et = new EditText(this)
                        {
                            InputType = InputTypes.ClassText | InputTypes.TextVariationPassword
                        };
                        et.Hint             = this.GetString(Resource.String.token_dialog_placeholder);
                        et.LayoutParameters = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);

                        var fl = new FrameLayout(this);
                        fl.SetPadding((int)(20 * dm.Density), 0, (int)(20 * dm.Density), 0);
                        fl.AddView(et);

                        var adb = new AlertDialog.Builder(this);
                        adb.SetTitle(Resource.String.token_dialog_title);
                        adb.SetMessage(Resource.String.token_dialog_message);
                        adb.SetView(fl);
                        adb.SetPositiveButton(Resource.String.token_dialog_confirm, delegate { this.CloseDialog(); token = et.Text; this.ContinueStartup(token, akey, aiv, pth); });
                        adb.SetNegativeButton(Resource.String.token_dialog_cancel, delegate { this.Finish(); });
                        this.Dialog = adb.Create();
                        this.Dialog.Show();
                    });
                }
                else
                {
                    using (var aes_dec = aes.CreateDecryptor(akey, aiv))
                        using (var fs = File.OpenRead(pth))
                            using (var bw = new BinaryReader(fs))
                                using (var cs = new CryptoStream(fs, aes_dec, CryptoStreamMode.Read))
                                {
                                    aiv = bw.ReadBytes(16);
                                    var tkb = new byte[ushort.MaxValue];
                                    var br  = 0;
                                    while ((br = cs.Read(tkb, 0, tkb.Length)) > 0)
                                    {
                                        token = string.Concat(token, utf8.GetString(tkb, 0, br));
                                    }
                                }

                    this.ContinueStartup(token, akey, aiv, pth);
                }
            }
        }
        public void mostrarnotificacion()
        {
            List <PendingIntent> listapending = listapendingintents();

            RemoteViews contentView = new RemoteViews(PackageName, Resource.Layout.layoutminiplayer);

            if (linkactual.Trim().Length > 1)
            {
                try
                {
                    // contentView.SetImageViewBitmap(Resource.Id.imageView1, playeroffline.gettearinstancia().imageneses.First(info => info.GenerationId == playeroffline.gettearinstancia().diccionario[tituloactual]));
                    contentView.SetImageViewBitmap(Resource.Id.fondo1, ImageHelper.CreateBlurredImageFromPortrait(this, 20, linkactual));
                }
                catch (Exception) {
                }

                ///   contentView.SetImageViewBitmap(Resource.Id.fondo1, clasesettings.CreateBlurredImageoffline(this, 20, linkactual));
            }
            contentView.SetTextViewText(Resource.Id.textView1, tituloactual);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView1, listapending[5]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView2, listapending[0]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView4, listapending[1]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView3, listapending[2]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView6, listapending[3]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView5, listapending[4]);



            Notification.Action accion1 = new Notification.Action(Resource.Drawable.playpause, "Playpause", listapending[0]);
            Notification.Action accion2 = new Notification.Action(Resource.Drawable.skipnext, "Siguiente", listapending[1]);
            Notification.Action accion3 = new Notification.Action(Resource.Drawable.skipprevious, "Anterior", listapending[2]);
            Notification.Action accion4 = new Notification.Action(Resource.Drawable.skipforward, "adelantar", listapending[3]);
            Notification.Action accion5 = new Notification.Action(Resource.Drawable.skipbackward, "atrazar", listapending[4]);

            /*
             *
             * 1-playpause
             * 2-siguiente
             * 3-anterior
             * 4-adelantar
             * 5-atrazar
             *
             */



            Notification.MediaStyle estilo = new Notification.MediaStyle();
            if (playeroffline.gettearinstancia() != null)
            {
                estilo.SetMediaSession(playeroffline.gettearinstancia().mSession.SessionToken);

                estilo.SetShowActionsInCompactView(1, 2, 3);
            }


#pragma warning disable CS0618 // El tipo o el miembro están obsoletos
            var nBuilder = new Notification.Builder(this);
#pragma warning restore CS0618 // El tipo o el miembro están obsoletos

            if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
            {
#pragma warning disable 414
                try
                {
#pragma warning disable CS0618 // El tipo o el miembro están obsoletos
                    nBuilder.SetContent(contentView);
#pragma warning restore CS0618 // El tipo o el miembro están obsoletos
                }
                catch (Exception) {
                }

#pragma warning restore 414
            }
            else
            {
                nBuilder.SetStyle(estilo);
                nBuilder.SetLargeIcon(GetImageBitmapFromUrl(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/portraits/" + playeroffline.gettearinstancia().linkeses[playeroffline.gettearinstancia().nombreses.IndexOf(tituloactual)].Split('=')[1]));
                nBuilder.SetContentTitle(tituloactual);

                nBuilder.SetContentText(playeroffline.gettearinstancia().linkeses[playeroffline.gettearinstancia().nombreses.IndexOf(tituloactual)]);
                nBuilder.AddAction(accion5);
                nBuilder.AddAction(accion3);
                nBuilder.AddAction(accion1);
                nBuilder.AddAction(accion2);
                nBuilder.AddAction(accion4);
                nBuilder.SetContentIntent(listapending[5]);
                nBuilder.SetColor(Android.Graphics.Color.ParseColor("#ce2c2b"));

                //  nBuilder.AddAction()
            }

            nBuilder.SetOngoing(true);
            nBuilder.SetSmallIcon(Resource.Drawable.play);
            Notification notification = nBuilder.Build();
            StartForeground(19248736, notification);
            listapending.Clear();
        }
        public void mostrarnotificacion()
        {
            var listapending = listapendingintents();


            RemoteViews contentView = new RemoteViews(PackageName, Resource.Layout.layoutminiplayeronline);

            if (linkactual.Trim().Length > 1)
            {
                try
                {
                    contentView.SetImageViewBitmap(Resource.Id.imageView1, ImageHelper.GetRoundedShape(GetImageBitmapFromUrl(linkactual)));
                    contentView.SetImageViewBitmap(Resource.Id.fondo1, ImageHelper.CreateBlurredImageFromUrl(this, 20, linkactual));
                }
                catch (Exception)
                {
                }
            }
            contentView.SetOnClickPendingIntent(Resource.Id.imageView1, listapending[5]);
            contentView.SetTextViewText(Resource.Id.textView1, tituloactual);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView2, listapending[0]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView4, listapending[1]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView3, listapending[2]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView6, listapending[3]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView5, listapending[4]);


            /*
             *
             * 1-playpause
             * 2-siguiente
             * 3-anterior
             * 4-adelantar
             * 5-atrazar
             *
             */

            Notification.Action accion1 = new Notification.Action(Resource.Drawable.playpause, "Playpause", listapending[0]);
            Notification.Action accion2 = new Notification.Action(Resource.Drawable.skipnext, "Siguiente", listapending[1]);
            Notification.Action accion3 = new Notification.Action(Resource.Drawable.skipprevious, "Anterior", listapending[2]);
            Notification.Action accion4 = new Notification.Action(Resource.Drawable.skipforward, "adelantar", listapending[3]);
            Notification.Action accion5 = new Notification.Action(Resource.Drawable.skipbackward, "atrazar", listapending[4]);

#pragma warning disable CS0618 // El tipo o el miembro están obsoletos
            var nBuilder = new Notification.Builder(this);
#pragma warning restore CS0618 // El tipo o el miembro están obsoletos
            Notification.MediaStyle estilo = new Notification.MediaStyle();
            if (Mainmenu.gettearinstancia() != null)
            {
                //  estilo.SetMediaSession(mainmenu.gettearinstancia().mSession.SessionToken);

                estilo.SetShowActionsInCompactView(1, 2, 3);
            }
            if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
            {
#pragma warning disable 414
                try {
#pragma warning disable CS0618 // El tipo o el miembro están obsoletos
                    nBuilder.SetContent(contentView);
#pragma warning restore CS0618 // El tipo o el miembro están obsoletos
                }
                catch (Exception) {
                }

#pragma warning restore 414
            }
            else
            {
                nBuilder.SetStyle(estilo);
                nBuilder.SetLargeIcon(ImageHelper.GetImageBitmapFromUrl(linkactual));
                nBuilder.SetContentTitle(tituloactual);
                nBuilder.SetContentText("Desde: " + Mainmenu.gettearinstancia().devicename);
                nBuilder.AddAction(accion5);
                nBuilder.AddAction(accion3);
                nBuilder.AddAction(accion1);
                nBuilder.AddAction(accion2);
                nBuilder.AddAction(accion4);
                nBuilder.SetContentIntent(listapending[5]);
                nBuilder.SetColor(Android.Graphics.Color.ParseColor("#ce2c2b"));
            }
            nBuilder.SetOngoing(true);

            nBuilder.SetSmallIcon(Resource.Drawable.play);

            Notification notification = nBuilder.Build();
            StartForeground(19248736, notification);
        }
        /// <summary>
        /// Update the notification.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The updated notification.
        /// </returns>
        public Notification UpdateNotification(Context context)
        {
            var builder = new Notification.Builder(context);
            if (!string.IsNullOrEmpty(this.PausedText))
            {
                builder.SetContentTitle(this.PausedText);
                builder.SetContentText(string.Empty);
                builder.SetContentInfo(string.Empty);
            }
            else
            {
                builder.SetContentTitle(this.Title);
                if (this.TotalBytes > 0 && this.CurrentBytes != -1)
                {
                    builder.SetProgress((int)(this.TotalBytes >> 8), (int)(this.CurrentBytes >> 8), false);
                }
                else
                {
                    builder.SetProgress(0, 0, true);
                }

                builder.SetContentText(Helpers.GetDownloadProgressString(this.CurrentBytes, this.TotalBytes));
                builder.SetContentInfo(string.Format("{0}s left", Helpers.GetTimeRemaining(this.TimeRemaining)));
            }

            builder.SetSmallIcon(this.Icon != 0 ? this.Icon : Android.Resource.Drawable.StatSysDownload);
            builder.SetOngoing(true);
            builder.SetTicker(this.Ticker);
            builder.SetContentIntent(this.PendingIntent);

            return builder.Notification;
        }
        private void CreateBuilder(IMediaItem mediaItem)
        {
            var builder = new Notification.Builder(Application.Context, channelId);

            builder.SetChannelId(channelId);

            //Configure builder
            builder.SetContentTitle(mediaItem.Title);
            builder.SetContentText(mediaItem.Artist);
            builder.SetWhen(0);

            if (AndroidAudioPlayer.SharedInstance.IsPlaying)
            {
                builder.SetOngoing(true);
                builder.SetSmallIcon(Android.Resource.Drawable.IcMediaPlay);
            }
            else
            {
                builder.SetOngoing(false);
                Intent        dismissIntent        = new Intent(ButtonEvents.AudioControlsDestroy);
                PendingIntent dismissPendingIntent = PendingIntent.GetBroadcast(Application.Context, 1, dismissIntent, 0);
                builder.SetDeleteIntent(dismissPendingIntent);
                builder.SetSmallIcon(Android.Resource.Drawable.IcMediaPause);
            }

            //If 5.0 >= set the controls to be visible on lockscreen
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                builder.SetVisibility(NotificationVisibility.Public);
            }

            if (!string.IsNullOrWhiteSpace(mediaItem.AlbumArtUrl))
            {
                try
                {
                    var bitmap = new AsyncImageDownloader().Execute(new string[] { mediaItem.AlbumArtUrl });
                    builder.SetLargeIcon(bitmap.GetResult());
                }
                catch (Java.Lang.Exception exc)
                {
                    Console.WriteLine($"Unable to find Album Art URL for {mediaItem.AlbumArtUrl}");
                    Console.WriteLine(exc.ToString());
                }
            }

            Intent resultIntent = new Intent(Application.Context, typeof(Activity));

            resultIntent.SetAction(Intent.ActionMain);
            resultIntent.AddCategory(Intent.CategoryLauncher);
            PendingIntent resultPendingIntent = PendingIntent.GetActivity(Application.Context, 0, resultIntent, PendingIntentFlags.UpdateCurrent);

            builder.SetContentIntent(resultPendingIntent);

            //Controls
            var controlsCount = 0;

            // Previous
            controlsCount++;
            builder.AddAction(previousAction);

            // Play/Pause
            builder.AddAction(pauseAction);

            // Next
            controlsCount++;
            builder.AddAction(nextAction);

            // Close
            //controlsCount++;
            //builder.AddAction(destroyAction);

            // If 5.0 >= use MediaStyle
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                int[] args = new int[controlsCount];
                for (int i = 0; i < controlsCount; ++i)
                {
                    args[i] = i;
                }
                var style = new Notification.MediaStyle();
                style.SetShowActionsInCompactView(args);
                builder.SetStyle(style);
            }
            notificationBuilder = builder;
        }
Ejemplo n.º 23
0
        public static async void ShowLocalNot(LocalNot not, Context context = null)
        {
            var cc      = context ?? Application.Context;
            var builder = new Notification.Builder(cc);

            builder.SetContentTitle(not.title);

            bool containsMultiLine = not.body.Contains("\n");

            if (Build.VERSION.SdkInt < BuildVersionCodes.O || !containsMultiLine)
            {
                builder.SetContentText(not.body);
            }
            builder.SetSmallIcon(not.smallIcon);
            builder.SetAutoCancel(not.autoCancel);
            builder.SetOngoing(not.onGoing);

            if (not.progress != -1)
            {
                builder.SetProgress(100, not.progress, false);
            }

            builder.SetVisibility(NotificationVisibility.Public);
            builder.SetOnlyAlertOnce(true);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                var channelId = $"{cc.PackageName}.general";
                var channel   = new NotificationChannel(channelId, "General", (NotificationImportance)not.notificationImportance);
                NotManager.CreateNotificationChannel(channel);

                builder.SetChannelId(channelId);

                if (not.bigIcon != null)
                {
                    if (not.bigIcon != "")
                    {
                        var bitmap = await GetImageBitmapFromUrl(not.bigIcon);

                        if (bitmap != null)
                        {
                            builder.SetLargeIcon(bitmap);
                            if (not.mediaStyle)
                            {
                                builder.SetStyle(new Notification.MediaStyle());                                 // NICER IMAGE
                            }
                        }
                    }
                }

                if (containsMultiLine)
                {
                    var b = new Notification.BigTextStyle();
                    b.BigText(not.body);
                    builder.SetStyle(b);
                }

                if (not.actions.Count > 0)
                {
                    List <Notification.Action> actions = new List <Notification.Action>();

                    for (int i = 0; i < not.actions.Count; i++)
                    {
                        var _resultIntent = new Intent(context, typeof(MainIntentService));
                        _resultIntent.PutExtra("data", not.actions[i].action);
                        var pending = PendingIntent.GetService(context, 3337 + i + not.id,
                                                               _resultIntent,
                                                               PendingIntentFlags.UpdateCurrent
                                                               );
                        actions.Add(new Notification.Action(not.actions[i].sprite, not.actions[i].name, pending));
                    }

                    builder.SetActions(actions.ToArray());
                }
            }

            builder.SetShowWhen(not.showWhen);
            if (not.when != null)
            {
                builder.SetWhen(CurrentTimeMillis((DateTime)not.when));
            }
            var stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(cc);

            var resultIntent = GetLauncherActivity(cc);

            if (not.data != "")
            {
                resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
                var _data = Android.Net.Uri.Parse(not.data);                //"cloudstreamforms:tt0371746Name=Iron man=EndAll");
                resultIntent.SetData(_data);
                stackBuilder.AddNextIntent(resultIntent);
                var resultPendingIntent =
                    stackBuilder.GetPendingIntent(not.id, (int)PendingIntentFlags.UpdateCurrent);
                builder.SetContentIntent(resultPendingIntent);
            }
            else
            {
                stackBuilder.AddNextIntent(resultIntent);

                builder.SetContentIntent(GetCurrentPending());
            }

            try {
                NotManager.Notify(not.id, builder.Build());
            }
            catch { }
        }