public async void Validate(string device, string correo, string contrasena) { string Result; var ValidationResultTextView = FindViewById <TextView>(Resource.Id.ValidationResultTextView); var Builder = new Notification.Builder(this); var ServiceClient = new SALLab07.ServiceClient(); Console.WriteLine($"{correo} | {contrasena}"); var SvcResult = await ServiceClient.ValidateAsync( correo, contrasena, device); Result = $"{SvcResult.Status}\n{SvcResult.Fullname}\n{SvcResult.Token}"; if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { Builder.SetContentTitle("Resultado de la Validación"); Builder.SetContentText(Result); Builder.SetSmallIcon(Resource.Drawable.Icon); Builder.SetCategory(Notification.CategoryMessage); var ObjectNotification = Builder.Build(); var Manager = GetSystemService( Android.Content.Context.NotificationService) as NotificationManager; Manager.Notify(0, ObjectNotification); } else { ValidationResultTextView.Text = Result; } }
private async void Validar() { var client = new SALLab07.ServiceClient(); var EmailText = FindViewById <EditText>(Resource.Id.EmailText); var PasswordText = FindViewById <EditText>(Resource.Id.PasswordText); var myDevice = Android.Provider.Settings.Secure.GetString(ContentResolver, Android.Provider.Settings.Secure.AndroidId); var result = await client.ValidateAsync(EmailText.Text, PasswordText.Text, myDevice); if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { var notificationText = $"{result.Status} {result.Fullname} {result.Token}"; var builder = new Notification.Builder(this) .SetContentTitle("Validacion de la Actividad") .SetContentText(notificationText) .SetSmallIcon(Resource.Drawable.Icon); builder.SetCategory(Notification.CategoryMessage); var ObjectNotifcation = builder.Build(); var Manager = GetSystemService(Android.Content.Context.NotificationService) as NotificationManager; Manager.Notify(0, ObjectNotifcation); } else { var message = $"{result.Status}\n{result.Fullname}\n{result.Token}"; var resultText = FindViewById <TextView>(Resource.Id.ResultText); resultText.Text = message; } }
private async void Validate(String Correo, string Clave) { var TextValidator = FindViewById <TextView>(Resource.Id.TextValidator); SALLab07.ServiceClient ServiceClient = new SALLab07.ServiceClient(); string myDevice = Android.Provider .Settings.Secure.GetString(ContentResolver, Android.Provider.Settings.Secure.AndroidId); SALLab07.ResultInfo Result = await ServiceClient.ValidateAsync(Correo, Clave, myDevice); string mensaje = ($"{Result.Status} \n{Result.Fullname}\n {Result.Token}"); var Builder = new Notification.Builder(this).SetContentTitle("Validacion de la Actividad"). SetContentText(mensaje).SetSmallIcon(Resource.Drawable.Icon); if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { Builder.SetCategory(Notification.CategoryMessage); var ObjectNotification = Builder.Build(); var Manager = GetSystemService(Android.Content.Context.NotificationService) as NotificationManager; Manager.Notify(0, ObjectNotification); } else { TextValidator.Text = mensaje; } }
async Task Validate(string correo, string pass) { SALLab07.ServiceClient ServiceClient = new SALLab07.ServiceClient(); string StudentMail = correo; string Password = pass; string myDevice = Android.Provider.Settings.Secure.GetString(ContentResolver, Android.Provider.Settings.Secure.AndroidId); var Result = await ServiceClient.ValidateAsync(StudentMail, Password, myDevice); var TextViewValidacion = FindViewById <TextView>(Resource.Id.ValidacionTextView); var texto = $"{Result.Status}\n{Result.Fullname}\n{Result.Token}"; if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { var Builder = new Notification.Builder(this) .SetContentTitle("Validación de actividad") .SetContentText(texto) .SetSmallIcon(Resource.Drawable.Icon); Builder.SetCategory(Notification.CategoryMessage); var ObjectNotification = Builder.Build(); var Manager = GetSystemService(NotificationService) as NotificationManager; Manager.Notify(0, ObjectNotification); } else { TextViewValidacion.Text = texto; } }
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); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); var ValidateButton = FindViewById <Button>(Resource.Id.ValidateButton); var ResultView = FindViewById <TextView>(Resource.Id.ResultView); var EmailText = FindViewById <EditText>(Resource.Id.EmailText); var PasswordText = FindViewById <EditText>(Resource.Id.PasswordText); string EMail; string Password; string Device = Android.Provider.Settings.Secure.GetString( ContentResolver, Android.Provider.Settings.Secure.AndroidId); ValidateButton.Click += (sender, e) => { EMail = EmailText.Text; Password = PasswordText.Text; Validate(); }; async void Validate() { string Result; var ServiceClient = new SALLab07.ServiceClient(); var SvcResult = await ServiceClient.ValidateAsync(EMail, Password, Device); Result = $"{SvcResult.Status}\n{SvcResult.Fullname}\n{SvcResult.Token}"; if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop) { var Builder = new Notification.Builder(this) .SetContentTitle("Validación de actividad") .SetContentText(Result) .SetSmallIcon(Resource.Drawable.Icon); Builder.SetCategory(Notification.CategoryMessage); var ObjectNotification = Builder.Build(); var Manager = GetSystemService( Android.Content.Context.NotificationService) as NotificationManager; Manager.Notify(0, ObjectNotification); } else { ResultView.Text = Result; } } }
void CreateNotification(PushNoticationMessage pushMessage) { try { // Get the notifications manager: NotificationManager notificationManager = GetSystemService(Context.NotificationService) as NotificationManager; // Instantiate the notification builder: //TODO: Get the Name of the App from Manifest Notification.Builder builder = new Notification.Builder(this) .SetContentTitle("Quick Task") .SetContentText(pushMessage.Title) .SetAutoCancel(true) .SetSmallIcon(Resource.Drawable.icon) .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.icon)); builder.SetVisibility(NotificationVisibility.Public); builder.SetPriority((int)NotificationPriority.High); builder.SetCategory(Notification.CategoryMessage); //Setup an intent for the Main Activity: Intent secondIntent = new Intent(this, typeof(MainActivity)); secondIntent.PutExtra("recdMessage", Settings.Current.LastMessage); // Pressing the Back button in SecondActivity exits the app: Android.App.TaskStackBuilder stackBuilder = Android.App.TaskStackBuilder.Create(this); // Add the back stack for the intent: stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity))); // Push the intent (that starts SecondActivity) onto the stack. The // pending intent can be used only once (one shot): stackBuilder.AddNextIntent(secondIntent); const int pendingIntentId = 0; PendingIntent pendingIntent = stackBuilder.GetPendingIntent(pendingIntentId, PendingIntentFlags.OneShot); builder.SetContentIntent(pendingIntent); // Build the notification: Notification notification = builder.Build(); notification.Defaults |= NotificationDefaults.Sound; // Notification ID used for all notifications in this app. // Reusing the notification ID prevents the creation of // numerous different notifications as the user experiments // with different notification settings -- each launch reuses // and updates the same notification. const int notificationId = 6; // Launch notification: notificationManager.Notify(notificationId, notification); Log.Info(AppConstants.TAG, "Local Notification Sent"); } catch (Exception ex) { Log.Info(AppConstants.TAG, "Local Notify Failed with " + ex.Message); } }
protected override void OnCreate(Bundle bundle) { int i = 1; base.OnCreate(bundle); SetContentView(Resource.Layout.PaymentPage); Button paymentbtn = FindViewById <Button>(Resource.Id.paymentbtn); paymentbtn.Click += (o, e) => { Toast.MakeText(this, "Confirmed", ToastLength.Short).Show(); Notification.BigTextStyle textStyle = new Notification.BigTextStyle(); textStyle.BigText("Your Code is 1234"); // Set the summary text: textStyle.SetSummaryText("Enjoy :)"); var notificationBuilder = new Notification.Builder(this) .SetContentTitle("Smarty's Notification") .SetContentText("Body goes here...........This is a big Notificaiton in Notification Tray") .SetAutoCancel(true) .SetPriority((int)NotificationPriority.Max) .SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate | NotificationDefaults.Lights) .SetStyle(textStyle); if ((int)Android.OS.Build.VERSION.SdkInt >= 21) { notificationBuilder.SetVisibility(NotificationVisibility.Public); notificationBuilder.SetCategory(Notification.CategoryAlarm); //notificationBuilder.SetSmallIcon(Resource.Drawable.transparentNotification); notificationBuilder.SetSmallIcon(Resource.Drawable.logo); //notificationBuilder.SetColor(Resources.GetColor(Resource)); notificationBuilder.SetVibrate(new long[] { 100, 200, 300 }); } else { notificationBuilder.SetSmallIcon(Resource.Drawable.logo); } var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService); notificationManager.Notify(i++, notificationBuilder.Build()); }; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); var textEmail = FindViewById <EditText>(Resource.Id.textEmail); var textPass = FindViewById <EditText>(Resource.Id.textPass); var btnValidar = FindViewById <Button>(Resource.Id.btnValidar); var textVValidar = FindViewById <TextView>(Resource.Id.textVValidar); btnValidar.Click += async(sender, e) => { var ServiceClient = new SALLab07.ServiceClient(); string StudentEmail = textEmail.Text; string Password = textPass.Text; string myDevice = Android.Provider.Settings.Secure.GetString(ContentResolver, Android.Provider.Settings.Secure.AndroidId); var Result = await ServiceClient.ValidateAsync(StudentEmail, Password, myDevice); if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { try { var Builder = new Notification.Builder(this); Builder.SetContentTitle("Validación de actividad"); Builder.SetContentText($"{Result.Status} {Result.Fullname} {Result.Token}"); Builder.SetSmallIcon(Resource.Drawable.Icon); Builder.SetCategory(Notification.CategoryMessage); var ObjectNotification = Builder.Build(); var Manager = GetSystemService(Android.Content.Context.NotificationService) as NotificationManager; Manager.Notify(0, ObjectNotification); } catch { } } else { textVValidar.Text = $"{Result.Status}\n{Result.Fullname}\n{Result.Token}"; } }; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here // Set our view from the "main" layout resource SetContentView(Resource.Layout.layout1); var Mail = FindViewById <EditText>(Resource.Id.Mail); var Password = FindViewById <EditText>(Resource.Id.Password); var Validar = FindViewById <Button>(Resource.Id.Validar); var ResultText = FindViewById <EditText>(Resource.Id.TextResult); Validar.Click += (sender, e) => { validate(); }; async void validate() { SALLab07.ServiceClient ServiceClient = new SALLab07.ServiceClient(); string StudentEmail = Mail.Text; // correo de registro xamarin 3.0 string Password1 = Password.Text; // password de registro string myDevice = Android.Provider.Settings.Secure.GetString(ContentResolver, Android.Provider.Settings.Secure.AndroidId); SALLab07.ResultInfo Result = await ServiceClient.ValidateAsync(StudentEmail, Password1, myDevice); if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { string Mensaje = ($"{Result.Status}\n{Result.Fullname}\n{Result.Token}"); var Builder = new Notification.Builder(this) .SetContentTitle("́Validación de la actividad") .SetContentText(Mensaje) .SetSmallIcon(Resource.Drawable.Icon); Builder.SetCategory(Notification.CategoryMessage); var ObjectNotification = Builder.Build(); var Manager = GetSystemService( Android.Content.Context.NotificationService) as NotificationManager; Manager.Notify(0, ObjectNotification); } else { Android.App.AlertDialog.Builder Builder = new AlertDialog.Builder(this); ResultText.Text = ($"{Result.Status}\n{Result.Fullname}\n{Result.Token}"); } } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); //Controles de UI: tvValidacion = FindViewById <TextView>(Resource.Id.tvValidacion); var btnValidar = FindViewById <Button>(Resource.Id.btnValidar); var etEmail = FindViewById <EditText>(Resource.Id.etEmail); var etPassword = FindViewById <EditText>(Resource.Id.etPassword); //Evento al dar click al botón: btnValidar.Click += (sender, e) => { var Email = etEmail.Text; var Password = etPassword.Text; var Device = Android.Provider.Settings.Secure.GetString(ContentResolver, Android.Provider.Settings.Secure.AndroidId); Validar(Email, Password, Device); //Detectar nivel de API del dispositivo: //API >= 21 -> Notificación; API < 21 -> Resultado en pantalla. if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { var Builder = new Notification.Builder(this) .SetContentTitle("Validacion de actividad") .SetContentText(txtResultB) .SetSmallIcon(Resource.Drawable.Icon); Builder.SetCategory(Notification.CategoryMessage); var ObjectNotification = Builder.Build(); var Manager = GetSystemService(Android.Content.Context.NotificationService) as NotificationManager; Manager.Notify(0, ObjectNotification); } else { tvValidacion.Text = txtResult; } }; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); var btnValidade = FindViewById <Button>(Resource.Id.btnValidar); var txtEmail = FindViewById <EditText>(Resource.Id.txtEmail); var txtPassword = FindViewById <EditText>(Resource.Id.txtPassword); var lblResponse = FindViewById <TextView>(Resource.Id.lblResult); btnValidade.Click += async delegate { if (string.IsNullOrWhiteSpace(txtEmail.Text) || string.IsNullOrWhiteSpace(txtPassword.Text)) { return; } SALLab07.ServiceClient client = new SALLab07.ServiceClient(); var response = await client.ValidateAsync(txtEmail.Text, txtPassword.Text, Android.Provider.Settings.Secure.GetString(ContentResolver, Android.Provider.Settings.Secure.AndroidId)); if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { var builder = new Notification.Builder(this) .SetContentTitle("Validación de actividad") .SetContentText( $"{response.Status} {response.Fullname} {response.Token}") .SetSmallIcon(Resource.Drawable.Icon); builder.SetCategory(Notification.CategoryMessage); var objectNotification = builder.Build(); var manager = GetSystemService(NotificationService) as NotificationManager; manager.Notify(0, objectNotification); } else { lblResponse.Text = $"{response.Status} \n{response.Fullname} \n{response.Token}"; } }; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); Button btnValidarActividad = FindViewById <Button>(Resource.Id.ValidarButton); EditText correoText = FindViewById <EditText>(Resource.Id.CorreoEditText); EditText passwordText = FindViewById <EditText>(Resource.Id.PasswordEditText); btnValidarActividad.Click += async(sender, e) => { ServiceClient service = new ServiceClient(); ResultInfo result = await service.ValidateAsync(correoText.Text, passwordText.Text, Android.Provider.Settings.Secure.GetString(ContentResolver, Android.Provider.Settings.Secure.AndroidId)); // detectando version de android if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { var notifBuilder = new Notification.Builder(this); notifBuilder.SetContentTitle("Phone App"); notifBuilder.SetContentText($"{result.Status}\n{result.Fullname}\n{result.Token}"); notifBuilder.SetSmallIcon(Resource.Drawable.Icon); notifBuilder.SetCategory(Notification.CategoryMessage); var ObjectNotif = notifBuilder.Build(); var Manager = GetSystemService(NotificationService) as NotificationManager; Manager.Notify(0, ObjectNotif); } else { // version menor a lollipop RunOnUiThread(() => { FindViewById <TextView>(Resource.Id.EvidenciaTextView1).Text = $"{result.Status}\n{result.Fullname}\n{result.Token}"; }); } }; }
void CreateNotification(PushNoticationMessage pushedMessage) { // Get the notifications manager: NotificationManager notificationManager = GetSystemService(Context.NotificationService) as NotificationManager; // Instantiate the notification builder: Notification.Builder builder = new Notification.Builder(this) .SetContentTitle("WK Authenticator") .SetContentText(pushedMessage.Title) .SetAutoCancel(true) .SetSmallIcon(Resource.Drawable.icon) .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.icon)); builder.SetVisibility(NotificationVisibility.Public); builder.SetPriority((int)NotificationPriority.High); builder.SetCategory(Notification.CategoryMessage); //Add Message Information to the Main Activity Intent - This will be shown on Tap Of the Notified Message Intent secondIntent = new Intent(this, typeof(MainActivity)); // Pass the current notification string value to SecondActivity secondIntent.PutExtra("recdMessage", Common.Helpers.Settings.LastMessage); // Pressing the Back button in SecondActivity exits the app: Android.App.TaskStackBuilder stackBuilder = Android.App.TaskStackBuilder.Create(this); // Add the back stack for the intent: stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity))); // Push the intent (that starts SecondActivity) onto the stack. The // pending intent can be used only once (one shot): stackBuilder.AddNextIntent(secondIntent); const int pendingIntentId = 0; PendingIntent pendingIntent = stackBuilder.GetPendingIntent(pendingIntentId, PendingIntentFlags.OneShot); builder.SetContentIntent(pendingIntent); // Build the notification: Notification notification = builder.Build(); notification.Defaults |= NotificationDefaults.Sound; // Notification ID used for all notifications in this app. // Reusing the notification ID prevents the creation of numerous different notifications as the user experiments with different notification settings -- each launch reuses // and updates the same notification. const int notificationId = 0; // Launch notification: notificationManager.Notify(notificationId, notification); }
protected async override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetContentView(Resource.Layout.UserDataLayout); //Lab06A var MessageView = FindViewById <TextView>(Resource.Id.ResultValidationTextView); var EmailEntry = FindViewById <TextView>(Resource.Id.emailEntry); var PasswordEntry = FindViewById <TextView>(Resource.Id.passwordEntry); var ValidateButton = FindViewById <Button>(Resource.Id.ValidateButton); var ServiceClient = new SALLab07.ServiceClient(); ValidateButton.Click += async(object sender, System.EventArgs e) => { string myDevice = Android.Provider.Settings.Secure.GetString(ContentResolver, Android.Provider.Settings.Secure.AndroidId); var Result = await ServiceClient.ValidateAsync(EmailEntry.Text, PasswordEntry.Text, myDevice); string result = $"{ Result.Status} { Result.Fullname} { Result.Token}"; string title = $"Validación de la actividad"; if (Android.OS.Build.VERSION.SdkInt <= BuildVersionCodes.Lollipop) { var Builder = new Notification.Builder(this) .SetContentTitle(title) .SetContentText(result) .SetSmallIcon(Resource.Drawable.Icon); Builder.SetCategory(Notification.CategoryMessage); var ObjectNotification = Builder.Build(); var Manager = GetSystemService(Android.Content.Context.NotificationService) as NotificationManager; Manager.Notify(0, ObjectNotification); } else { MessageView.Text = $"{ Result.Status}\n{ Result.Fullname}\n{ Result.Token}"; } }; }
private async void ValidateJC() { var miCorreo = FindViewById <EditText>(Resource.Id.txtEmail); var miPassword = FindViewById <EditText>(Resource.Id.txtPassword); var miResultado = FindViewById <TextView>(Resource.Id.lbValidateResult); string StudentEmail = miCorreo.Text.Trim(); string PasswordStudent = miPassword.Text.Trim(); string resultadoFin = ""; string myDevice = Android.Provider.Settings.Secure.GetString( ContentResolver, Android.Provider.Settings.Secure.AndroidId); var ServiceClient = new SALLab07.ServiceClient(); var Result = await ServiceClient.ValidateAsync(StudentEmail, PasswordStudent, myDevice); resultadoFin = $"{Result.Status}\n{Result.Fullname}\n{Result.Token}"; //resultadoFin = "prueba"; miResultado.Text = ""; if ((Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)) { var Builder = new Notification.Builder(this) .SetContentTitle("Validacion de Actividad") .SetContentText(resultadoFin) //resultadoFin .SetSmallIcon(Resource.Drawable.Icon); Builder.SetCategory(Notification.CategoryMessage); var ObjectNotification = Builder.Build(); var Manager = GetSystemService( Android.Content.Context.NotificationService) as NotificationManager; Manager.Notify(0, ObjectNotification); } else { miResultado.Text = resultadoFin; } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); Button ValidarButton = FindViewById <Button>(Resource.Id.ValidarButton); EditText CorreoText = FindViewById <EditText>(Resource.Id.CorreoText); EditText PasswordText = FindViewById <EditText>(Resource.Id.PasswordText); TextView ResultadoText = FindViewById <TextView>(Resource.Id.ResultadoTextView); ValidarButton.Click += async(s, ev) => { string deviceID = Android.Provider.Settings.Secure.GetString(ContentResolver, Android.Provider.Settings.Secure.AndroidId); ServiceClient serviceClient = new ServiceClient(); ResultInfo Resultado = await serviceClient.ValidateAsync(CorreoText.Text, PasswordText.Text, deviceID); if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { string resultado = $"{Resultado.Status} {Resultado.Fullname} {Resultado.Token}"; var Builder = new Notification.Builder(this).SetContentTitle("Validación de actividad") .SetContentText(resultado).SetSmallIcon(Resource.Drawable.Icon); Builder.SetCategory(Notification.CategoryMessage); var ObjectNotification = Builder.Build(); var Manager = GetSystemService(Android.Content.Context.NotificationService) as NotificationManager; Manager.Notify(0, ObjectNotification); } else { string resultado = $"{Resultado.Status}\n{Resultado.Fullname}\n{Resultado.Token}"; ResultadoText.Text = resultado; } }; }
private void SetMetadata(Notification.Builder builder) { if ((int)Build.VERSION.SdkInt >= 16) { builder.SetPriority(highPriority.Checked ? (int)NotificationPriority.High : (int)NotificationPriority.Default); } if ((int)Build.VERSION.SdkInt >= (int)BuildVersionCodes.Lollipop) { builder.SetCategory(Notification.CategoryMessage); var visibility = NotificationVisibility.Public; if (spinner.SelectedItemPosition == 1) { visibility = NotificationVisibility.Private; } else if (spinner.SelectedItemPosition == 2) { visibility = NotificationVisibility.Secret; } builder.SetVisibility(visibility); } }
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.btn); TextView txview = FindViewById <TextView>(Resource.Id.txview); button.Click += async(sender, e) => { not = await Validate(); if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { var Builder = new Notification.Builder(this) .SetContentTitle("Validacion de actividad") .SetSmallIcon(Resource.Drawable.bugermenu) .SetContentText("" + not); Builder.SetCategory(Notification.CategoryMessage); var ObjectNotification = Builder.Build(); var Manager = GetSystemService( Android.Content.Context.NotificationService) as NotificationManager; Manager.Notify(0, ObjectNotification); } else { txview.Text = not; } }; }
protected override void OnCreate(Bundle bundle) { TabLayoutResource = Resource.Layout.tabs; ToolbarResource = Resource.Layout.toolbar; base.OnCreate(bundle); notificationManager = GetSystemService(Context.NotificationService) as NotificationManager; global::Xamarin.Forms.Forms.Init(this, bundle); var fooApp = new App(new AndroidInitializer()); #region 檢查是否是由通知開啟 App,並且依據通知,切換到適當頁面 //自訂通知被點擊後的動作 //當通知出現在通知欄之後,在習慣的趨使下,有很大的機率會被使用者點擊。 //所以應該要實作出通知被點擊後的動作,好比開啟哪個Activity之類的。 //通知被點擊後的動作可以使用PendingIntent來實作,PendingIntent並不是一個Intent,它是一個Intent的容器, // 可以傳入context物件,並以這個context的身份來做一些事情,例如開啟Activity、開啟Service,或是發送Broadcast。 // 如果要使通知可以在被點擊之後做點什麼事,可以使用Notification.Builder的setContentIntent方法來替通知加入PendingIntent fooLocalNotificationPayload = null; if (Intent.Extras != null) { if (Intent.Extras.ContainsKey("NotificationObject")) { string fooNotificationObject = Intent.Extras.GetString("NotificationObject", ""); fooLocalNotificationPayload = JsonConvert.DeserializeObject <LocalNotificationPayload>(fooNotificationObject); } } #endregion XFLocalNotificationDroid.App.fooLocalNotificationPayload = fooLocalNotificationPayload; LoadApplication(new App(new AndroidInitializer())); #region 訂閱要發送本地通知的事件 // 取得 Xamarin.Forms 中的 Prism 注入物件管理容器 IUnityContainer myContainer = (App.Current as PrismApplication).Container; var fooEvent = myContainer.Resolve <IEventAggregator>().GetEvent <LocalNotificationEvent>().Subscribe(x => { #region 建立本地訊息通知物件 Notification.Builder builder = new Notification.Builder(this) .SetContentTitle(x.ContentTitle) .SetContentText(x.ContentText) .SetSmallIcon(Resource.Drawable.ic_notification) .SetAutoCancel(true); // 決定是否要顯示大圖示 if (x.LargeIcon) { builder.SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.monkey_icon)); } #region 針對不同通知類型作出設定 switch (x.Style) { case LocalNotificationStyleEnum.Normal: break; case LocalNotificationStyleEnum.BigText: //builder.SetContentText(x.ContentText); var textStyle = new Notification.BigTextStyle(); textStyle.BigText(x.ContentText); textStyle.SetSummaryText(x.SummaryText); builder.SetStyle(textStyle); break; case LocalNotificationStyleEnum.Inbox: var inboxStyle = new Notification.InboxStyle(); foreach (var item in x.InboxStyleList) { inboxStyle.AddLine(item); } inboxStyle.SetSummaryText(x.SummaryText); builder.SetStyle(inboxStyle); break; case LocalNotificationStyleEnum.Image: var picStyle = new Notification.BigPictureStyle(); picStyle.BigPicture(BitmapFactory.DecodeResource(Resources, Resource.Drawable.x_bldg)); picStyle.SetSummaryText(x.SummaryText); builder.SetStyle(picStyle); break; default: break; } #endregion #region 設定 visibility switch (x.Visibility) { case LocalNotificationVisibilityEnum.Public: builder.SetVisibility(NotificationVisibility.Public); break; case LocalNotificationVisibilityEnum.Private: builder.SetVisibility(NotificationVisibility.Private); break; case LocalNotificationVisibilityEnum.Secret: builder.SetVisibility(NotificationVisibility.Secret); break; default: break; } #endregion #region 設定 priority switch (x.Priority) { case LocalNotificationPriorityEnum.Default: builder.SetPriority((int)NotificationPriority.Default); break; case LocalNotificationPriorityEnum.High: builder.SetPriority((int)NotificationPriority.High); break; case LocalNotificationPriorityEnum.Low: builder.SetPriority((int)NotificationPriority.Low); break; case LocalNotificationPriorityEnum.Maximum: builder.SetPriority((int)NotificationPriority.Max); break; case LocalNotificationPriorityEnum.Minimum: builder.SetPriority((int)NotificationPriority.Min); break; default: break; } #endregion #region 設定 category switch (x.Category) { case LocalNotificationCategoryEnum.Call: builder.SetCategory(LocalNotificationCategoryEnum.Call.ToString()); break; case LocalNotificationCategoryEnum.Message: builder.SetCategory(LocalNotificationCategoryEnum.Message.ToString()); break; case LocalNotificationCategoryEnum.Alarm: builder.SetCategory(LocalNotificationCategoryEnum.Alarm.ToString()); break; case LocalNotificationCategoryEnum.Email: builder.SetCategory(LocalNotificationCategoryEnum.Email.ToString()); break; case LocalNotificationCategoryEnum.Event: builder.SetCategory(LocalNotificationCategoryEnum.Event.ToString()); break; case LocalNotificationCategoryEnum.Promo: builder.SetCategory(LocalNotificationCategoryEnum.Promo.ToString()); break; case LocalNotificationCategoryEnum.Progress: builder.SetCategory(LocalNotificationCategoryEnum.Progress.ToString()); break; case LocalNotificationCategoryEnum.Social: builder.SetCategory(LocalNotificationCategoryEnum.Social.ToString()); break; case LocalNotificationCategoryEnum.Error: builder.SetCategory(LocalNotificationCategoryEnum.Error.ToString()); break; case LocalNotificationCategoryEnum.Transport: builder.SetCategory(LocalNotificationCategoryEnum.Transport.ToString()); break; case LocalNotificationCategoryEnum.System: builder.SetCategory(LocalNotificationCategoryEnum.System.ToString()); break; case LocalNotificationCategoryEnum.Service: builder.SetCategory(LocalNotificationCategoryEnum.Service.ToString()); break; case LocalNotificationCategoryEnum.Recommendation: builder.SetCategory(LocalNotificationCategoryEnum.Recommendation.ToString()); break; case LocalNotificationCategoryEnum.Status: builder.SetCategory(LocalNotificationCategoryEnum.Status.ToString()); break; default: break; } #endregion #region 準備設定當使用者點選通知之後要做的動作 // Setup an intent for SecondActivity: Intent secondIntent = new Intent(this, typeof(MainActivity)); // 設定當使用點選這個通知之後,要傳遞過去的資料 secondIntent.PutExtra("NotificationObject", JsonConvert.SerializeObject(x)); // 若在首頁且使用者按下回上頁實體按鈕,則會離開這個 App TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this); stackBuilder.AddNextIntent(secondIntent); PendingIntent pendingIntent = stackBuilder.GetPendingIntent(pendingIntentId++, PendingIntentFlags.OneShot); // Uncomment this code to setup an intent so that notifications return to this app: // Intent intent = new Intent (this, typeof(MainActivity)); // const int pendingIntentId = 0; // pendingIntent = PendingIntent.GetActivity (this, pendingIntentId, intent, PendingIntentFlags.OneShot); // builder.SetContentText("Hello World! This is my first action notification!"); // Launch SecondActivity when the users taps the notification: builder.SetContentIntent(pendingIntent); // 產生一個 notification 物件 Notification notification = builder.Build(); #region 決定是否要發出聲音 if (x.Sound) { notification.Defaults |= NotificationDefaults.Sound; } #endregion #region 決定是否要有震動 if (x.Vibrate) { notification.Defaults |= NotificationDefaults.Vibrate; } #endregion // 顯示本地通知: notificationManager.Notify(notificationId++, notification); // 解開底下程式碼註解,將會於五秒鐘之後,才會發生本地通知 // Thread.Sleep(5000); // builder.SetContentTitle("Updated Notification"); // builder.SetContentText("Changed to this message after five seconds."); // notification = builder.Build(); // notificationManager.Notify(notificationId, notification); #endregion #endregion }); #endregion }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set the view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get the notifications manager: NotificationManager notificationManager = GetSystemService(Context.NotificationService) as NotificationManager; //.......................................................................... // Edit box: // Find the notification edit text box in the layout: notifyMsg = FindViewById <EditText>(Resource.Id.notifyText); //.......................................................................... // Selection Spinners: // The spinners in this file use the strings defined in Resources/values/arrays.xml. // Find the Style spinner in the layout and configure its adapter. Spinner styleSpinner = FindViewById <Spinner>(Resource.Id.styleSpinner); var styleAdapter = ArrayAdapter.CreateFromResource(this, Resource.Array.notification_style, Android.Resource.Layout.SimpleSpinnerDropDownItem); styleSpinner.Adapter = styleAdapter; // Handler for Style spinner, changes the text in the text box: styleSpinner.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs> (styleSpinnerSelected); // Find the Visibility spinner in the layout and configure its adapter: Spinner visibilitySpinner = FindViewById <Spinner>(Resource.Id.visibilitySpinner); var visibilityAdapter = ArrayAdapter.CreateFromResource(this, Resource.Array.notification_visibility, Android.Resource.Layout.SimpleSpinnerDropDownItem); visibilitySpinner.Adapter = visibilityAdapter; // Find the Priority spinner in the layout and configure its adapter: Spinner prioritySpinner = FindViewById <Spinner>(Resource.Id.prioritySpinner); var priorityAdapter = ArrayAdapter.CreateFromResource(this, Resource.Array.notification_priority, Android.Resource.Layout.SimpleSpinnerDropDownItem); prioritySpinner.Adapter = priorityAdapter; // Find the Category spinner in the layout and configure its adapter: Spinner categorySpinner = FindViewById <Spinner>(Resource.Id.categorySpinner); var categoryAdapter = ArrayAdapter.CreateFromResource(this, Resource.Array.notification_category, Android.Resource.Layout.SimpleSpinnerDropDownItem); categorySpinner.Adapter = categoryAdapter; // Handler for Style spinner: changes the text in the text box: styleSpinner.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs> (styleSpinnerSelected); //.......................................................................... // Option Switches: // Get large-icon, sound, and vibrate switches from the layout: Switch largeIconSw = FindViewById <Switch>(Resource.Id.largeIconSwitch); Switch soundSw = FindViewById <Switch>(Resource.Id.soundSwitch); Switch vibrateSw = FindViewById <Switch>(Resource.Id.vibrateSwitch); //.......................................................................... // Notification Launch button: // Get notification launch button from the layout: Button launchBtn = FindViewById <Button>(Resource.Id.launchButton); // Handler for the notification launch button. When this button is clicked, this // handler code takes the following steps, in order: // // 1. Instantiates the builder. // 2. Calls methods on the builder to optionally plug in the large icon, extend // the style (if called for by a spinner selection), set the visibility, set // the priority, and set the category. // 3. Uses the builder to instantiate the notification. // 4. Turns on sound and vibrate (if selected). // 5. Uses the Notification Manager to launch the notification. launchBtn.Click += delegate { // Instantiate the notification builder: Notification.Builder builder = new Notification.Builder(this) .SetContentTitle("Sample Notification") .SetContentText(notifyMsg.Text) .SetSmallIcon(Resource.Drawable.ic_notification) .SetAutoCancel(true); // Add large icon if selected: if (largeIconSw.Checked) { builder.SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.monkey_icon)); } // Extend style based on Style spinner selection. switch (styleSpinner.SelectedItem.ToString()) { case "Big Text": // Extend the message with the big text format style. This will // use a larger screen area to display the notification text. // Set the title for demo purposes: builder.SetContentTitle("Big Text Notification"); // Using the Big Text style: var textStyle = new Notification.BigTextStyle(); // Use the text in the edit box at the top of the screen. textStyle.BigText(notifyMsg.Text); textStyle.SetSummaryText("The summary text goes here."); // Plug this style into the builder: builder.SetStyle(textStyle); break; case "Inbox": // Present the notification in inbox format instead of normal text style. // Note that this does not display the notification message entered // in the edit text box; instead, it displays the fake email inbox // summary constructed below. // Using the inbox style: var inboxStyle = new Notification.InboxStyle(); // Set the title of the notification: builder.SetContentTitle("5 new messages"); builder.SetContentText("*****@*****.**"); // Generate inbox notification text: 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"); // Plug this style into the builder: builder.SetStyle(inboxStyle); break; case "Image": // Extend the message with image (big picture) format style. This displays // the Resources/drawables/x_bldg.jpg image in the notification body. // Set the title for demo purposes: builder.SetContentTitle("Image Notification"); // Using the Big Picture style: var picStyle = new Notification.BigPictureStyle(); // Convert the image file to a bitmap before passing it into the style // (there is no exception handler since we know the size of the image): picStyle.BigPicture(BitmapFactory.DecodeResource(Resources, Resource.Drawable.x_bldg)); picStyle.SetSummaryText("The summary text goes here."); // Alternately, uncomment this code to use an image from the SD card. // (In production code, wrap DecodeFile in an exception handler in case // the image is too large and throws an out of memory exception.): // BitmapFactory.Options options = new BitmapFactory.Options(); // options.InSampleSize = 2; // string imagePath = "/sdcard/Pictures/my-tshirt.jpg"; // picStyle.BigPicture(BitmapFactory.DecodeFile(imagePath, options)); // picStyle.SetSummaryText("Check out my new T-shirt!"); // Plug this style into the builder: builder.SetStyle(picStyle); break; default: // Normal text notification is the default. break; } // Set visibility based on Visibility spinner selection: switch (visibilitySpinner.SelectedItem.ToString()) { case "Public": builder.SetVisibility(NotificationVisibility.Public); break; case "Private": builder.SetVisibility(NotificationVisibility.Private); break; case "Secret": builder.SetVisibility(NotificationVisibility.Secret); break; } // Set priority based on Priority spinner selection: switch (prioritySpinner.SelectedItem.ToString()) { case "High": builder.SetPriority((int)NotificationPriority.High); break; case "Low": builder.SetPriority((int)NotificationPriority.Low); break; case "Maximum": builder.SetPriority((int)NotificationPriority.Max); break; case "Minimum": builder.SetPriority((int)NotificationPriority.Min); break; default: builder.SetPriority((int)NotificationPriority.Default); break; } // Set category based on Category spinner selection: switch (categorySpinner.SelectedItem.ToString()) { case "Call": builder.SetCategory(Notification.CategoryCall); break; case "Message": builder.SetCategory(Notification.CategoryMessage); break; case "Alarm": builder.SetCategory(Notification.CategoryAlarm); break; case "Email": builder.SetCategory(Notification.CategoryEmail); break; case "Event": builder.SetCategory(Notification.CategoryEvent); break; case "Promo": builder.SetCategory(Notification.CategoryPromo); break; case "Progress": builder.SetCategory(Notification.CategoryProgress); break; case "Social": builder.SetCategory(Notification.CategorySocial); break; case "Error": builder.SetCategory(Notification.CategoryError); break; case "Transport": builder.SetCategory(Notification.CategoryTransport); break; case "System": builder.SetCategory(Notification.CategorySystem); break; case "Service": builder.SetCategory(Notification.CategoryService); break; case "Recommendation": builder.SetCategory(Notification.CategoryRecommendation); break; case "Status": builder.SetCategory(Notification.CategoryStatus); break; default: builder.SetCategory(Notification.CategoryStatus); break; } // Setup an intent for SecondActivity: Intent secondIntent = new Intent(this, typeof(SecondActivity)); // Pass the current notification string value to SecondActivity: secondIntent.PutExtra("message", notifyMsg.Text); // Pressing the Back button in SecondActivity exits the app: TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this); // Add the back stack for the intent: stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(SecondActivity))); // Push the intent (that starts SecondActivity) onto the stack. The // pending intent can be used only once (one shot): stackBuilder.AddNextIntent(secondIntent); const int pendingIntentId = 0; PendingIntent pendingIntent = stackBuilder.GetPendingIntent(pendingIntentId, PendingIntentFlags.OneShot); // Uncomment this code to setup an intent so that notifications return to this app: // Intent intent = new Intent (this, typeof(MainActivity)); // const int pendingIntentId = 0; // pendingIntent = PendingIntent.GetActivity (this, pendingIntentId, intent, PendingIntentFlags.OneShot); // builder.SetContentText("Hello World! This is my first action notification!"); // Launch SecondActivity when the users taps the notification: builder.SetContentIntent(pendingIntent); // Build the notification: Notification notification = builder.Build(); // Turn on sound if the sound switch is on: if (soundSw.Checked) { notification.Defaults |= NotificationDefaults.Sound; } // Turn on vibrate if the sound switch is on: if (vibrateSw.Checked) { notification.Defaults |= NotificationDefaults.Vibrate; } // Notification ID used for all notifications in this app. // Reusing the notification ID prevents the creation of // numerous different notifications as the user experiments // with different notification settings -- each launch reuses // and updates the same notification. const int notificationId = 1; // Launch notification: notificationManager.Notify(notificationId, notification); // Uncomment this code to update the notification 5 seconds later: // Thread.Sleep(5000); // builder.SetContentTitle("Updated Notification"); // builder.SetContentText("Changed to this message after five seconds."); // notification = builder.Build(); // notificationManager.Notify(notificationId, notification); }; }
private static void ShowNativeNotification(Common.Message message, string notificationId, ButtonSet buttonSet = null, string alertTextOverride = null) { var nativeNotificationId = new Random().Next(); // Setup intent to launch application var context = Application.Context; // Build the notification var builder = new Notification.Builder(context) .SetContentTitle(message.SenderDisplayName) .SetSmallIcon(Resource.Drawable.donky_notification_small_icon_simple_push) .SetContentText(alertTextOverride ?? message.Body) .SetVibrate(new[] { 0L, 100L }) .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)); var pushMessage = message as SimplePushMessage; if (pushMessage != null && buttonSet != null && buttonSet.ButtonSetActions.Any()) { builder.SetAutoCancel(false); // Jelly Bean + above supports multiple actions if (buttonSet.ButtonSetActions.Count == 2 && Build.VERSION.SdkInt >= BuildVersionCodes.JellyBean) { foreach (var action in buttonSet.ButtonSetActions) { builder.AddAction(0, action.Label, CreateIntentForAction(context, nativeNotificationId, notificationId, action, pushMessage, buttonSet)); } } else { builder.SetContentIntent(CreateIntentForAction(context, nativeNotificationId, notificationId, buttonSet.ButtonSetActions[0], pushMessage, buttonSet)); } } else { var intent = CreateIntentForBasicPush(context, nativeNotificationId, notificationId); builder.SetContentIntent(intent) .SetAutoCancel(true); } // bug if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { builder.SetCategory(Notification.CategoryMessage) .SetPriority((int) NotificationPriority.High) .SetVisibility(NotificationVisibility.Public); // this is for a Heads-Up Notification (Out of App Notification) var push = new Intent(); push.AddFlags(ActivityFlags.NewTask); push.SetClass(context, Java.Lang.Class.FromType(context.GetType())); var fullScreenPendingIntent = PendingIntent.GetActivity(context, 0, push, PendingIntentFlags.CancelCurrent); builder .SetContentText(alertTextOverride ?? message.Body) .SetFullScreenIntent(fullScreenPendingIntent, true); } var notification = builder.Build(); notification.LedARGB = Color.White; notification.Flags |= NotificationFlags.ShowLights; notification.LedOnMS = 200; notification.LedOffMS = 2000; var notificationManager = (NotificationManager) context.GetSystemService(Context.NotificationService); notificationManager.Notify(nativeNotificationId, notification); }