void CreateAccountDialog_onSignUpEventComplete(object sender, OnSignUpEventsArgs e) { //Notificacion de la cuenta creada //deberia ser un metodo? // // Instantiate the builder and set notification elements: Notification.Builder builder = new Notification.Builder(this) .SetAutoCancel(true) // dismiss the notification from the notification area when the user clicks on it .SetContentTitle("Hermes App") // Set the title .SetSmallIcon(Resource.Drawable.Icon) // This is the icon to display .SetContentText("Su cuenta ha sido creada con éxito!") // the message to display. .SetDefaults(NotificationDefaults.Vibrate); //Notificacion con el sonido del sistema builder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Ringtone)); // Build the notification: Notification notification = builder.Build(); // Turn on vibrate: notification.Defaults |= NotificationDefaults.Vibrate; // Finally publish the notification NotificationManager notificationManager = (NotificationManager)GetSystemService(Context.NotificationService); // Publish the notification: const int notificationId = 0; notificationManager.Notify(notificationId, notification); //Se inicia la aplicacion var intent = new Intent(this, typeof(HermesActivity)); intent.PutExtra("email", e.Email); intent.PutExtra("name", e.Name); StartActivity(intent); }
void SendNotification(string message, string userId, string token, string userName) { var intent = new Intent(this, typeof(MainActivity)); intent.PutExtra("userId", userId); intent.PutExtra("token", token); intent.PutExtra("userName", userName); intent.AddFlags(ActivityFlags.ClearTop); var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent); var notificationBuilder = new Notification.Builder(this) .SetSmallIcon(Resource.Drawable.Icon) .SetContentText(message) .SetStyle(new Notification.BigTextStyle().BigText(message)) .SetAutoCancel(true) .SetContentIntent(pendingIntent); var isSound = prefs.GetBoolean("IsSoundEnable", true); var isVibrate = prefs.GetBoolean("IsVibrateEnable", true); if (isSound) { notificationBuilder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)); } if (isVibrate) { notificationBuilder.SetVibrate(new long[] { 100, 400, 100, 500 }); } var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService); notificationManager.Notify(1, notificationBuilder.Build()); }
public void SendNotification(string title, string text, bool sound = false, bool progress = false, int total = 0, int partial = 0, int percentMax = 100) { // Instantiate the builder and set notification elements: Notification.Builder builder = new Notification.Builder(Application.Context) .SetContentTitle(title).SetContentText(text) .SetSmallIcon(Resource.Drawable.icon);//.SetTicker(""); // Build the notification: //Notification notification = builder.Build(); // Get the notification manager: NotificationManager notificationManager = Application.Context.GetSystemService(Context.NotificationService) as NotificationManager; // Publish the notification: const int notificationId = 2468; if (progress) { builder.SetProgress(percentMax, percentMax * partial / total, false); } if (sound) { builder.SetSound(Android.Media.RingtoneManager.GetDefaultUri(Android.Media.RingtoneType.Notification)); } notificationManager.Notify(notificationId, builder.Build()); builder.SetWhen(DateTime.Now.Millisecond); }
private void Button_Click(object sender, EventArgs e) { notyBuilder = new Notification.Builder(this); notyBuilder.SetContentTitle("عنوان پیام"); notyBuilder.SetContentText("متن پیام در اینجا قرار میگیرد"); notyBuilder.SetSmallIcon(Resource.Drawable.noty_small_icon); notyBuilder.SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.noty_large_icon)); notyBuilder.SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()); notyBuilder.SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate); notyBuilder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)); notyBuilder.SetAutoCancel(true); notyBuilder.SetPriority((int)NotificationPriority.High); if ((int)Android.OS.Build.VERSION.SdkInt >= 21) { notyBuilder.SetVisibility(NotificationVisibility.Public); notyBuilder.SetCategory(Notification.CategoryEmail); } #region BigTextStyle Notification.BigTextStyle textStyle = new Notification.BigTextStyle(); string longTextMessage = "I went up one pair of stairs."; longTextMessage += " / Just like me. "; textStyle.BigText(longTextMessage); textStyle.SetSummaryText("The summary text goes here."); //notyBuilder.SetStyle(textStyle); #endregion #region InboxStyle var inboxStyle = new Notification.InboxStyle(); inboxStyle.AddLine("Cheeta: Bananas on sale"); inboxStyle.AddLine("George: Curious about your blog post"); inboxStyle.AddLine("Nikko: Need a ride to Evolve?"); inboxStyle.SetSummaryText("+2 more"); notyBuilder.SetStyle(inboxStyle); #endregion #region imageStyle var imageStyle = new Notification.BigPictureStyle(); imageStyle.BigPicture(BitmapFactory.DecodeResource(Resources, Resource.Drawable.facebook)); imageStyle.SetSummaryText("+2 more"); //notyBuilder.SetStyle(imageStyle); #endregion var notification = notyBuilder.Build(); var notyManager = GetSystemService(Context.NotificationService) as NotificationManager; notyManager.Notify(notyId, notification); }
private void notifyUser(String title, String message) { Notification.Builder builder = new Notification.Builder(this) .SetContentTitle(title) .SetContentText(message); builder.SetSmallIcon(Resource.Drawable.green_button); builder.SetSound(Android.Media.RingtoneManager.GetDefaultUri(Android.Media.RingtoneType.Notification)); Notification notification = builder.Build(); NotificationManager notificationManager = GetSystemService(Context.NotificationService) as NotificationManager; const int notificationId = 0; notificationManager.Notify(notificationId, notification); }
//Notifications: private void notifyUser(String title, String message) { Notification.Builder builder = new Notification.Builder (activity) .SetContentTitle (title) .SetSubText (message) .SetContentText ("You will not be notified of leaving a region."); builder.SetSmallIcon (Resource.Drawable.green_button); builder.SetSound (Android.Media.RingtoneManager.GetDefaultUri (Android.Media.RingtoneType.Notification)); Notification notification = builder.Build(); NotificationManager notificationManager = activity.GetSystemService (Context.NotificationService) as NotificationManager; const int notificationId = 0; notificationManager.Notify (notificationId, notification); }
Notification.Builder CreateBaseNotificationBuilder() { if (AGNotificationManager.AreNotificationChannelsSupported) { CreateNotificationChannel(); CreateNotificationChannelGroup(); } var channelId = AGNotificationManager.AreNotificationChannelsSupported ? _lastChannelId : null; var groupId = AGNotificationManager.AreNotificationChannelsSupported ? _lastGroupId : null; #pragma warning disable 0618 var builder = new Notification.Builder(channelId, new Dictionary <string, string> { { ParamKeyId, "id: " + _notificationId }, { ParamKeyDate, "date: " + DateTime.Now } }) .SetGroup(groupId) .SetGroupAlertBehavior(Notification.GroupAlert.All) .SetChannelId(channelId) .SetSmallIcon("notify_icon_small") .SetLocalOnly(true) .SetBadgeIconType(Notification.BadgeIcon.Small) .SetContentTitle("Android Goodies") .SetContentInfo("Content info") .SetContentText("Test notification") .SetPriority(Notification.Priority.High) .SetVibrate(new long[] { 1000, 100, 1000, 100, 100 }) .SetLights(Color.yellow, 1000, 1000) .SetColor(new Color(Random.value, Random.value, Random.value)) .SetColorized(true) .SetDefaults(Notification.Default.All) .SetWhen(DateTime.Now.ToMillisSinceEpoch()) .SetShowWhen(true) .SetSortKey("xyz") .SetAutoCancel(true) .SetVisibility(Notification.Visibility.Public); #pragma warning restore 0618 if (_soundFilePath != null) { builder.SetSound(_soundFilePath); } return(builder); }
public static void ShowNotification(Activity contexto, string titulo, string mensaje, string link, int codigo) { contexto.RunOnUiThread(() => { #pragma warning disable CS0618 // El tipo o el miembro están obsoletos var nBuilder = new Notification.Builder(contexto); #pragma warning restore CS0618 // El tipo o el miembro están obsoletos nBuilder.SetLargeIcon(ImageHelper.GetImageBitmapFromUrl("http://i.ytimg.com/vi/" + link.Split('=')[1] + "/mqdefault.jpg")); nBuilder.SetContentTitle(titulo); nBuilder.SetContentText(mensaje); nBuilder.SetColor(Android.Graphics.Color.ParseColor("#ce2c2b")); nBuilder.SetSmallIcon(Resource.Drawable.list); #pragma warning disable CS0618 // El tipo o el miembro están obsoletos nBuilder.SetSound(Android.Media.RingtoneManager.GetDefaultUri(Android.Media.RingtoneType.Notification)); #pragma warning restore CS0618 // El tipo o el miembro están obsoletos Notification notification = nBuilder.Build(); NotificationManager notificationManager = (NotificationManager)contexto.GetSystemService(Context.NotificationService); notificationManager.Notify(5126768, notification); }); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById <Button>(Resource.Id.myButton); button.Click += (object sender, System.EventArgs e) => { // Instantiate the builder and set notification elements: Notification.Builder builder = new Notification.Builder(this) .SetContentTitle("Xin chao cac ban!! Hello") .SetContentText("Hello World! This is my first notification!") .SetSmallIcon(Resource.Drawable.Alarm); //The timestamp is set automatically, but you can override this setting by calling the SetWhen method of the notification builder. //For example, the following code example sets the timestamp to the current time: builder.SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()); /* * This call to SetDefaults will cause the device to play a sound when the notification is published. * If you want the device to vibrate rather than play a sound, you can pass NotificationDefaults.Vibrate to SetDefaults. * If you want the device to play a sound and vibrate the device, you can pass both flags to SetDefaults: */ builder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Ringtone)); // Build the notification: Notification notification = builder.Build(); // Get the notification manager: NotificationManager notificationManager = GetSystemService(Context.NotificationService) as NotificationManager; // Publish the notification: const int notificationId = 0; notificationManager.Notify(notificationId, notification); };; }
void SendNotification(MessaggioNotifica m) { var intent = new Intent (this, typeof(MainActivity)); intent.AddFlags (ActivityFlags.ClearTop); var notifica = new Notification.Builder (this); switch (m.Tipo) { case "1": notifica.SetSmallIcon (Resource.Drawable.alert_1); break; case "2": notifica.SetSmallIcon (Resource.Drawable.alert_2); break; case "3": notifica.SetSmallIcon (Resource.Drawable.alert_3); break; default: notifica.SetSmallIcon (Resource.Drawable.InvioDoc); break; } if (m.Tipo == "4") { Messaggio mess = new Messaggio (m.Titolo, m.Messaggio); intent.PutExtra ("messaggio", JsonConvert.SerializeObject(mess)); } else { intent.PutExtra ("commessanum", m.Commessa); } var pendingIntent = PendingIntent.GetActivity (this, 0, intent, PendingIntentFlags.OneShot); notifica.SetContentTitle (m.Titolo); notifica.SetContentText (m.Messaggio); notifica.SetAutoCancel (true); notifica.SetContentInfo (m.Commessa); notifica.SetSubText ("Commessa " + m.Commessa); notifica.SetVibrate (new long[] {100,200,100}); notifica.SetSound (RingtoneManager.GetDefaultUri(RingtoneType.Notification)); notifica.SetContentIntent (pendingIntent); var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService); notificationManager.Notify (0, notifica.Build()); }
private void GetNotificationForFriendRequest(NotificationModel notificationmodel) { Intent intent = new Intent(this, typeof(MainActivity)); intent.PutExtra("ToNotification", "ToNotification"); intent.AddFlags(ActivityFlags.ClearTop); var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot | PendingIntentFlags.UpdateCurrent); var notificationBuilder = new Notification.Builder(this) .SetSmallIcon(Resource.Drawable.icon) .SetContentTitle(notificationmodel.NotificationFor) .SetContentText("Friend Request From " + notificationmodel.SenderName) .SetAutoCancel(true) .SetContentIntent(pendingIntent); Android.Net.Uri alarmSound = RingtoneManager.GetDefaultUri(RingtoneType.Notification); notificationBuilder.SetSound(alarmSound); var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService); notificationManager.Notify(0, notificationBuilder.Build()); }
/// <summary> /// Send a notification to the user's notification bar /// </summary> /// <param name="message">The message text</param> /// <param name="username">The user who sent the message</param> void SendNotification(string message, string username) { var intent = new Intent(this, typeof(MainActivity)); intent.AddFlags(ActivityFlags.ClearTop); var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot); //Create the notification var notificationBuilder = new Notification.Builder(this) .SetSmallIcon(Resource.Drawable.ic_stat_ic_notification) .SetContentTitle("Message from: " + username) .SetContentText(message) .SetAutoCancel(true) .SetContentIntent(pendingIntent); //Play a sound and add the notification to the notification bar var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService); notificationBuilder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)); notificationManager.Notify(0, notificationBuilder.Build()); }
public void IssueNotificationAsync(string title, string message, bool autoCancel, bool ongoing, string id, bool playSound, bool vibrate) { if (_notificationManager != null) { new Thread(() => { if (message == null) { _notificationManager.Cancel(id, 0); } else { Intent serviceIntent = new Intent(_service, typeof(AndroidSensusService)); serviceIntent.PutExtra(NOTIFICATION_ID_KEY, id); PendingIntent pendingIntent = PendingIntent.GetService(_service, 0, serviceIntent, PendingIntentFlags.UpdateCurrent); Notification.Builder builder = new Notification.Builder(_service) .SetContentTitle(title) .SetContentText(message) .SetSmallIcon(Resource.Drawable.ic_launcher) .SetContentIntent(pendingIntent) .SetAutoCancel(autoCancel) .SetOngoing(ongoing); if (playSound) { builder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)); } if (vibrate) { builder.SetVibrate(new long[] { 0, 250, 50, 250 }); } _notificationManager.Notify(id, 0, builder.Build()); } }).Start(); } }
/// <summary> /// Issues the notification. /// </summary> /// <param name="title">Title.</param> /// <param name="message">Message.</param> /// <param name="id">Identifier of notification.</param> /// <param name="protocolId">Protocol identifier to check for alert exclusion time windows.</param> /// <param name="alertUser">If set to <c>true</c> alert user.</param> /// <param name="displayPage">Display page.</param> public override void IssueNotificationAsync(string title, string message, string id, string protocolId, bool alertUser, DisplayPage displayPage) { if (_notificationManager == null) { return; } Task.Run(() => { if (message == null) { CancelNotification(id); } else { Intent notificationIntent = new Intent(_service, typeof(AndroidSensusService)); notificationIntent.PutExtra(DISPLAY_PAGE_KEY, displayPage.ToString()); PendingIntent notificationPendingIntent = PendingIntent.GetService(_service, 0, notificationIntent, PendingIntentFlags.UpdateCurrent); Notification.Builder notificationBuilder = new Notification.Builder(_service) .SetContentTitle(title) .SetContentText(message) .SetSmallIcon(Resource.Drawable.ic_launcher) .SetContentIntent(notificationPendingIntent) .SetAutoCancel(true) .SetOngoing(false); if (alertUser && !Protocol.TimeIsWithinAlertExclusionWindow(protocolId, DateTime.Now.TimeOfDay)) { notificationBuilder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)); notificationBuilder.SetVibrate(new long[] { 0, 250, 50, 250 }); } _notificationManager.Notify(id, 0, notificationBuilder.Build()); } }); }
public void noti(Context cont) { Notification.Builder builder = new Notification.Builder(cont); builder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)); ////.SetContentIntent(pendingIntent) builder.SetContentTitle("New Notify"); builder.SetContentText(text); builder.SetSmallIcon(Resource.Drawable.BoketIcon); Notification notification = builder.Build(); NotificationManager notificationManager = cont.GetSystemService(Context.NotificationService) as NotificationManager; //newWS.wsnew sw = new newWS.wsnew(); //if (jsonString == null) //{ // // tvresult.Text = "JsonString is Null"; // Toast.MakeText(cont, "JsonString is Null", ToastLength.Long).Show(); //} //else //{ // jsonArray = JArray.Parse(jsonString); // // List<contactclass> contactItems = new List<contactclass>(); // int count = 0; // while (count < jsonArray.Count) // { // contactclass contact = new contactclass(jsonArray[count]["ID"].ToString(), jsonArray[count]["txtNews"].ToString()); // // Toast.MakeText(this, jsonArray[count]["name"].ToString(), ToastLength.Long).Show(); // // contactItems.Add(contact); // // count++; // notificationManager.Notify(count++, notification); // } // // sw.NewsNotifyAsync(count) //} notificationManager.Notify(MyServices.id, notification); }
public static void ShowNotification(Context context) { // Instantiate the builder and set notification elements: Notification.Builder builder = new Notification.Builder(context) .SetAutoCancel(true) .SetContentTitle("Sample Notification") .SetContentText("Hello World! This is my first notification!") .SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate) .SetSmallIcon(Resource.Drawable.logo) .SetLargeIcon(BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.logo)); builder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Ringtone)); // Setup an intent for SecondActivity: Intent secondIntent = new Intent(context, typeof(UserNotification)); // Pass some information to SecondActivity: secondIntent.PutExtra("message", "Greetings from MainActivity!"); // Create a task stack builder to manage the back stack: TaskStackBuilder stackBuilder = TaskStackBuilder.Create(context); // Add all parents of SecondActivity to the stack: stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(UserNotification))); // Push the intent that starts SecondActivity onto the stack: stackBuilder.AddNextIntent(secondIntent); // Obtain the PendingIntent for launching the task constructed by // stackbuilder. The pending intent can be used only once (one shot): const int pendingIntentId = 0; PendingIntent pendingIntent = stackBuilder.GetPendingIntent(pendingIntentId, PendingIntentFlags.OneShot); int totalunread = 10; if (totalunread > 0) { // Instantiate the Inbox style: Notification.InboxStyle inboxStyle = new Notification.InboxStyle(); // Set the title and text of the notification: builder.SetContentIntent(pendingIntent); builder.SetContentTitle(totalunread + " new messages"); builder.SetContentText("WMS Trips"); //if (dtNotify.Rows.Count > 3) //{ // for (int i = 0; i < dtNotify.Rows.Count; i++) // { // if (i == 3) // { // i = int.MaxValue; // break; // } // else // { // inboxStyle.AddLine(string.Format("{0}: {1}", dtNotify.Rows[i]["Title"].ToString(), dtNotify.Rows[i]["Description"].ToString())); // } // } // inboxStyle.SetSummaryText("+"+(dtNotify.Rows.Count - 3) + " more"); //} //else //{ // for (int i = 0; i < dtNotify.Rows.Count; i++) // { // inboxStyle.AddLine(string.Format("{0}: {1}", dtNotify.Rows[i]["Title"].ToString(), dtNotify.Rows[0]["Description"].ToString())); // } //} // Plug this style into the builder: builder.SetStyle(inboxStyle); // Build the notification: Notification notification = builder.Build(); // Get the notification manager: NotificationManager notificationManager = context.GetSystemService(Context.NotificationService) as NotificationManager; // Publish the notification: const int notificationId = 0; notificationManager.Notify(notificationId, notification); } }
private void Process(HttpListenerContext context) { context.Response.AddHeader("Access-Control-Allow-Origin", "*"); context.Response.AddHeader("Access-Control-Allow-Credentials", "true"); context.Response.AddHeader("Access-Control-Allow-Methods", "*"); context.Response.AddHeader("Access-Control-Allow-Headers", "*"); if (context.Request.Url.ToString().Contains("&&querry&&")) { if (context.Request.Url.ToString().Contains("meconecte")) { context.Response.StatusCode = (int)HttpStatusCode.OK; context.Response.Close(); #pragma warning disable CS0618 // El tipo o el miembro están obsoletos Notification.Builder nBuilder = new Notification.Builder(conteto); #pragma warning restore CS0618 // El tipo o el miembro están obsoletos nBuilder.SetContentTitle("Nuevo dispositivo conectado"); nBuilder.SetContentText("Un nuevo dispositivo está stremeando su media"); #pragma warning disable CS0618 // El tipo o el miembro están obsoletos nBuilder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)); #pragma warning restore CS0618 // El tipo o el miembro están obsoletos nBuilder.SetSmallIcon(Resource.Drawable.antena); Notification notification = nBuilder.Build(); NotificationManager notificationManager = (NotificationManager)conteto.GetSystemService(Context.NotificationService); notificationManager.Notify(5126768, notification); } } //////////////cuando son archivos else { bool esindice = false; string filename = context.Request.Url.AbsolutePath; Console.WriteLine(filename); filename = filename.Substring(1); filename = System.Net.WebUtility.UrlDecode(filename); if (string.IsNullOrEmpty(filename)) { foreach (string indexFile in _indexFiles) { if (File.Exists(Path.Combine(_rootDirectory + "/.gr3cache", indexFile))) { filename = indexFile; esindice = true; break; } } } var nomesinpath = filename; if (!esindice) { if (!filename.Contains(".mp3") && !filename.Contains(".mp4")) { filename = Path.Combine(_rootDirectory, filename); } } else { filename = Path.Combine(_rootDirectory + "/.gr3cache", filename); } if (File.Exists(filename)) { context.Response.StatusCode = (int)HttpStatusCode.OK; //Adding permanent http response headers string mime; string mimo = ""; if (filename.EndsWith("mp3")) { mimo = "audio/*"; } else if (filename.EndsWith("mp4")) { mimo = "video/mp4"; } if (!filename.Contains("downloaded.gr3d")) { using (var stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { context.Response.ContentType = _mimeTypeMappings.TryGetValue(Path.GetExtension(filename), out mime) ? mime : mimo; context.Response.ContentLength64 = stream.Length; context.Response.AddHeader("Accept-Ranges", "bytes"); context.Response.AddHeader("Date", DateTime.Now.ToString("r")); context.Response.AddHeader("Last-Modified", System.IO.File.GetLastWriteTime(filename).ToString("r")); context.Response.AddHeader("Content-Range", string.Format("bytes {0}-{1}/{2}", 0, Convert.ToInt32(stream.Length) - 1, Convert.ToInt32(stream.Length))); context.Response.ContentLength64 = stream.Length; stream.CopyTo(context.Response.OutputStream); stream.Flush(); } } else { refreshregistry(); byte[] bytesitosdestring; if (filename.EndsWith("2")) { bytesitosdestring = System.Text.Encoding.UTF8.GetBytes(verifiedmp4); } else { bytesitosdestring = System.Text.Encoding.UTF8.GetBytes(verifiedmp3); } using (MemoryStream streamm = new MemoryStream(bytesitosdestring, 0, bytesitosdestring.Length)) { context.Response.ContentType = _mimeTypeMappings.TryGetValue(filename.Split('.')[1], out mime) ? mime : mimo; context.Response.ContentLength64 = streamm.Length; context.Response.SendChunked = true; context.Response.AddHeader("Date", DateTime.Now.ToString("r")); context.Response.AddHeader("Last-Modified", System.IO.File.GetLastWriteTime(filename).ToString("r")); streamm.CopyTo(context.Response.OutputStream); streamm.Flush(); } MultiHelper.ExecuteGarbageCollection(); } context.Response.OutputStream.Flush(); context.Response.OutputStream.Close(); context.Response.Close(); } else { context.Response.StatusCode = (int)HttpStatusCode.NotFound; context.Response.Close(); } } }
/// <summary> /// Send a notification to the user's notification bar /// </summary> /// <param name="message">The message text</param> /// <param name="username">The user who sent the message</param> void SendNotification(string message, string username) { var intent = new Intent(this, typeof(MainActivity)); intent.AddFlags(ActivityFlags.ClearTop); var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot); //Create the notification var notificationBuilder = new Notification.Builder(this) .SetSmallIcon(Resource.Drawable.ic_stat_ic_notification) .SetContentTitle("Message from: " + username) .SetContentText(message) .SetAutoCancel(true) .SetContentIntent(pendingIntent); //Play a sound and add the notification to the notification bar var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService); notificationBuilder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)); notificationManager.Notify(0, notificationBuilder.Build()); }
public void Show(int id, string title, string body, SoundType?soundType) { var appIcon = BitmapFactory.DecodeResource(Application.Context.Resources, Resource.Drawable.appIcon); Bitmap bm = Bitmap.CreateScaledBitmap(appIcon, 48, 48, true); bool hasSound = soundType.HasValue; var soundProvider = Xamarin.Forms.DependencyService.Get <INotificationSoundProvider>(); if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { var generalChannel = new NotificationChannel(GeneralChannelId, "Notifications", NotificationImportance.Default) { LightColor = Resource.Color.colorAccent, Description = "App notifications with sound" }; var lowChannel = new NotificationChannel(LowChannelId, "General", NotificationImportance.Low) { LightColor = Resource.Color.colorAccent, Description = "App notifications without sound", }; generalChannel.EnableLights(true); lowChannel.EnableLights(true); lowChannel.SetSound(null, null); NotifManager.CreateNotificationChannel(generalChannel); NotifManager.CreateNotificationChannel(lowChannel); // play sound if (hasSound) { soundProvider.Play(soundType.Value); } } var soundUri = hasSound ? Android.Net.Uri.Parse(soundProvider.GetSoundPath(soundType.Value)) : RingtoneManager.GetDefaultUri(RingtoneType.Notification); var audioAttributes = new AudioAttributes.Builder() .SetContentType(AudioContentType.Sonification) .SetUsage(AudioUsageKind.Alarm) .SetLegacyStreamType(Stream.Alarm) .Build(); //we use the main because we dont want to show the splash again.. //and because the splash produces a bug where the timer gets paused xd var resultIntent = new Intent(Application.Context, typeof(MainActivity)); //resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop | ActivityFlags.SingleTop); //resultIntent.SetAction(Intent.ActionMain); //resultIntent.AddCategory(Intent.CategoryLauncher); //resultIntent.SetFlags(ActivityFlags.SingleTop); //resultIntent.SetFlags(ActivityFlags.NewTask); //var pendingIntent = PendingIntent.GetActivity(Application.Context, 1, resultIntent, PendingIntentFlags.UpdateCurrent); var bundle = new Bundle(); bundle.PutString(nameof(NotificationService), $"{id}"); var pendingIntent = Android.Support.V4.App.TaskStackBuilder.Create(Application.Context) .AddNextIntent(resultIntent) .GetPendingIntent(1, (int)PendingIntentFlags.UpdateCurrent, bundle); string channelId = hasSound ? LowChannelId : GeneralChannelId; var builder = new Notification.Builder(Application.Context, channelId) .SetContentTitle(title) .SetContentText(body) .SetAutoCancel(true) .SetSmallIcon(Resource.Drawable.appIcon) .SetColor(Color.Red.ToArgb()) .SetLargeIcon(bm) .SetContentIntent(pendingIntent); if (hasSound && Build.VERSION.SdkInt < BuildVersionCodes.O) { //This are deprecated for android O + #pragma warning disable CS0618 // Type or member is obsolete builder.SetSound(soundUri, audioAttributes); builder.SetPriority(NotificationCompat.PriorityDefault); #pragma warning restore CS0618 // Type or member is obsolete } var notification = builder.Build(); NotifManager.Notify(id, notification); }
//protected override void OnError(Context context, string errorId) //{ // Log.Error(ApplicationSettings.AzureTag, "GCM Error: " + errorId); //} // protected override void OnRegistered(Context context, string registrationId) // { //PushNotificationImplementation.registerRequest.deviceToken = registrationId; //ApplicationSettings.DeviceToken = registrationId; ////added on 1/25/17 by aditmer to unregister the device if the registrationId has changed //CheckInstallationID.CheckNewInstallationID(registrationId); //Webservices.RegisterPush(PushNotificationImplementation.registerRequest); ////commented out on 11/29/16 by aditmer so we can register on the server // //RegistrationID = registrationId; // //Hub = new NotificationHub(NightscoutMobileHybrid.Constants.NotificationHubPath, NightscoutMobileHybrid.Constants.ConnectionString, context); // //try // //{ // // Hub.UnregisterAll(registrationId); // //} // //catch (Exception ex) // //{ // // Log.Error(ApplicationSettings.AzureTag, ex.Message); // //} // //var tags = new List<string>() { ApplicationSettings.AzureTag }; // //try // //{ // // const string templateBodyGCM = "{\"data\":{\"message\":\"$(message)\",\"eventName\":\"$(eventName)\",\"group\":\"$(group)\",\"key\":\"$(key)\",\"level\":\"$(level)\",\"sound\":\"$(sound)\",\"title\":\"$(title)\"}}"; // // var hubRegistration = Hub.RegisterTemplate(registrationId, "nightscout", templateBodyGCM, tags.ToArray()); // //} // //catch (Exception ex) // //{ // // Log.Error(ApplicationSettings.AzureTag, ex.Message); // //} //} //protected override void OnUnRegistered(Context context, string registrationId) //{ // createNotification("0", "GCM Unregistered...", "The device has been unregistered!", 0,"0","0"); //} void createNotification(string key, string title, string desc, int sound, string group, string level) { var intent = new Intent(this, typeof(MainActivity)); intent.AddFlags(ActivityFlags.SingleTop); var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent); //addd on 12/5/16 by aditmer to add actions to the push notifications AckRequest ack = new AckRequest(); ack.group = group; ack.key = key; ack.level = level; ack.time = ApplicationSettings.AlarmUrgentMins1; var notificationIntent = new Intent(this, typeof(NotificationActionService)); notificationIntent.PutExtra("ack", JsonConvert.SerializeObject(ack)); var snoozeIntent1 = PendingIntent.GetService(this, 0, notificationIntent, PendingIntentFlags.OneShot); //adds 2nd action that snoozes the alarm for the ApplicationSettings.AlarmUrgentMins[1] amount of time var notificationIntent2 = new Intent(this, typeof(NotificationActionService)); AckRequest ack2 = new AckRequest(); ack2.group = group; ack2.key = key; ack2.level = level; ack2.time = ApplicationSettings.AlarmUrgentMins2; notificationIntent2.PutExtra("ack", JsonConvert.SerializeObject(ack2)); var snoozeIntent2 = PendingIntent.GetService(this, 0, notificationIntent2, PendingIntentFlags.OneShot); //Notification.Action notificationAction = new Notification.Action(0, "Snooze", snoozeIntent); var notificationBuilder = new Notification.Builder(this); if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { notificationBuilder.SetChannelId("nightscout"); } notificationBuilder.SetSmallIcon(NightscoutMobileHybrid.Droid.Resource.Drawable.icon); notificationBuilder.SetContentTitle(title); notificationBuilder.SetContentText(desc); notificationBuilder.SetAutoCancel(true); notificationBuilder.SetPriority((int)NotificationPriority.Max); notificationBuilder.SetContentIntent(pendingIntent); notificationBuilder.AddAction(0, $"Snooze {ack.time} min", snoozeIntent1); notificationBuilder.AddAction(0, $"Snooze {ack2.time} min", snoozeIntent2); if (sound == 0) { notificationBuilder.SetDefaults(NotificationDefaults.Vibrate | NotificationDefaults.Lights | NotificationDefaults.Sound); } else { notificationBuilder.SetDefaults(NotificationDefaults.Vibrate | NotificationDefaults.Lights); notificationBuilder.SetSound(Android.Net.Uri.Parse(ContentResolver.SchemeAndroidResource + "://" + PackageName + "/Raw/" + sound)); } var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService); var notification = notificationBuilder.Build(); if (sound != 0) { notification.Flags = NotificationFlags.Insistent; } notificationManager.Notify(key, 1, notification); //Not using in-app notifications (Nightscout handles all of that for us) //dialogNotify(title, desc); }
public override void OnReceive(Context context, Intent intent) { var message = intent.GetStringExtra("message"); var title = intent.GetStringExtra("title"); var id = intent.GetStringExtra("id"); if (title == "Um Minuto de Presença") { id = id.Remove(id.Length - 1); var notIntent = new Intent(context, typeof(MainActivity)); var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent); var manager = NotificationManagerCompat.From(context); SQLite_Android sqlite = new SQLite_Android(); PlatformNotifier pf = new PlatformNotifier(); NotificacaoDAO dao = new NotificacaoDAO(sqlite.GetConnection(), pf); ObservableCollection <Notificacao> notificacoes = dao.Notificacoes; var numero = Convert.ToInt32(id); var notificacao = (from not in notificacoes where not.ID == numero select not).FirstOrDefault <Notificacao>(); if (!notificacao.Repetir) { dao.DesativarNotificacao(notificacao); } //gerando notificacao para disparo var builder = new Notification.Builder(context) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.ic_notification) .SetContentTitle(title) .SetContentText(message) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true); if (notificacao.Vibrar) { builder.SetDefaults(NotificationDefaults.Vibrate); } if (notificacao.Som) { builder.SetSound(Android.Net.Uri.Parse("android.resource://" + context.ApplicationContext.PackageName + "/Raw/" + Resource.Raw.som_notificacao)); } var notification = builder.Build(); manager.Notify(0, notification); } else { SQLite_Android sqlite = new SQLite_Android(); PlatformNotifier pf = new PlatformNotifier(); NotificacaoDAO dao = new NotificacaoDAO(sqlite.GetConnection(), pf); ObservableCollection <Notificacao> notificacoes = dao.Notificacoes; for (int i = 0; i < notificacoes.Count; i++) { if (notificacoes[i].Ativado) { dao.AtivarNotificacao(notificacoes[i]); } } } }
public Notification.Builder CreateNotificationBuilder(SensusNotificationChannel channel) { global::Android.Net.Uri notificationSoundURI = RingtoneManager.GetDefaultUri(RingtoneType.Notification); AudioAttributes notificationAudioAttributes = new AudioAttributes.Builder() .SetContentType(AudioContentType.Unknown) .SetUsage(AudioUsageKind.NotificationEvent).Build(); long[] vibrationPattern = { 0, 250, 50, 250 }; bool silent = GetChannelSilent(channel); Notification.Builder builder; // see the Backwards Compatibility article for more information #if __ANDROID_26__ if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { NotificationManager notificationManager = Application.Context.GetSystemService(global::Android.Content.Context.NotificationService) as NotificationManager; string channelId = channel.ToString(); if (notificationManager.GetNotificationChannel(channelId) == null) { NotificationChannel notificationChannel = new NotificationChannel(channelId, GetChannelName(channel), GetChannelImportance(channel)) { Description = GetChannelDescription(channel) }; if (silent) { notificationChannel.SetSound(null, null); notificationChannel.EnableVibration(false); } else { notificationChannel.SetSound(notificationSoundURI, notificationAudioAttributes); notificationChannel.EnableVibration(true); notificationChannel.SetVibrationPattern(vibrationPattern); } notificationManager.CreateNotificationChannel(notificationChannel); } builder = new Notification.Builder(Application.Context, channelId); } else #endif { #pragma warning disable 618 builder = new Notification.Builder(Application.Context); if (silent) { builder.SetSound(null); builder.SetVibrate(null); } else { builder.SetSound(notificationSoundURI, notificationAudioAttributes); builder.SetVibrate(vibrationPattern); } #pragma warning restore 618 } return(builder); }
public override void OnReceive(Context context, Intent intent)//הפעולה מעפילה את הברוקדקאסט בשביל שישלח התראה בעת קבלת שיחה { // ensure there is information if (intent.Extras != null) { // מקבל את מצב השיחה string state = intent.GetStringExtra(TelephonyManager.ExtraState); // check the current state בדיקה של המצב if (state == TelephonyManager.ExtraStateRinging) { // read the incoming call telephone number... פרטי המתקשר string chanel_id = "chanel_id"; string chanel_name = "chanel-name"; if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { NotificationChannel notificationChannel = new NotificationChannel(chanel_id, chanel_name, NotificationImportance.Default); //מפעיל את האור בהתרעה notificationChannel.EnableLights(true); //מפעיל את הרטט notificationChannel.EnableVibration(true); //צבע ההתרעה notificationChannel.LightColor = Color.White; // קצב הרטט // with the format {delay,play,sleep,play,sleep...}פורמט הרטט notificationChannel.SetVibrationPattern(new long[] { 500, 500, 500, 500, 500 }); //מגדיר אם הודעות מהערוץ הזה צריכות להיות גלויות על מסך הנעילה ובמקרה הזה כן notificationChannel.LockscreenVisibility = NotificationVisibility.Public; NotificationManager manager = (NotificationManager)context.GetSystemService(Context.NotificationService); manager.CreateNotificationChannel(notificationChannel); } string telephone = intent.GetStringExtra(TelephonyManager.ExtraIncomingNumber); Toast.MakeText(Android.App.Application.Context, telephone, ToastLength.Short).Show();//יוצר טוסט // בדוק את הטלפון מחדש if (string.IsNullOrEmpty(telephone)) { telephone = string.Empty; } Notification.Builder builder = new Notification.Builder(context, chanel_id);//יצירת ההתראה ופרטיה builder.SetContentTitle(telephone); builder.SetContentText("you got an incoming phone call from" + telephone); builder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)); builder.SetSmallIcon(Android.Resource.Drawable.StarOn); Notification notification = builder.Build(); //בנייתו const int not_id = 101; //האידי NotificationManager notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService); NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.From(context); notificationManager.Notify(not_id, notification);//הנוטיפרישין עצמו } else if (state == TelephonyManager.ExtraStateOffhook) { // incoming call answer Toast.MakeText(Android.App.Application.Context, "you answerd the pohne", ToastLength.Short).Show(); } else if (state == TelephonyManager.ExtraStateIdle)//השיחה הסתיימה { Toast.MakeText(Android.App.Application.Context, "call as ended continue to play", ToastLength.Long).Show(); } } }