public override void OnReceive(Context context, Intent intent) { // Default notification title/text string notificationTitle = "Pushy"; string notificationText = "Test notification"; // Attempt to extract the "message" property from the payload: {"message":"Hello World!"} if (intent.GetStringExtra("message") != null) { notificationText = intent.GetStringExtra("message"); } // Prepare a notification with vibration, sound and lights var builder = new Notification.Builder(context) .SetAutoCancel(true) .SetSmallIcon(Resource.Mipmap.Notification) .SetContentTitle(notificationTitle) .SetContentText(notificationText) .SetLights(Color.Red, 1000, 1000) .SetVibrate(new long[] { 0, 400, 250, 400 }) .SetColor(context.GetColor(Resource.Color.colorPrimary)) .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)) .SetContentIntent(PendingIntent.GetActivity(context, 0, new Intent(context, typeof(MainActivity)), PendingIntentFlags.UpdateCurrent)); // Automatically configure a Notification Channel for devices running Android O+ Pushy.SetNotificationChannel(builder, context); // Get an instance of the NotificationManager service var notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService); // Build the notification and display it notificationManager.Notify(1, builder.Build()); }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Load Main.axml layout SetContentView(Resource.Layout.Main); // Cache TextView objects DeviceToken = FindViewById <TextView>(Resource.Id.deviceToken); Instructions = FindViewById <TextView>(Resource.Id.instructions); // Restart the socket service, in case the user force-closed the app Pushy.Listen(this); // Register device for push notifications (async) await RegisterForPushNotifications(); }
private async Task <RegistrationResult> RegisterForPushNotificationsAsync() { // Prepare registration result var result = new RegistrationResult(); // Execute Pushy.Register() in a background thread await Task.Run(() => { try { // Register device for push notifications result.DeviceToken = Pushy.Register(this); } catch (PushyException exc) { // Store registration error in result result.Error = exc; } }); // Return registration error / device token return(result); }