El Manejo de notificaciones locales en Android es diferente que en iOS, por lo que el código no es multiplataforma. En MvvmCross me gusta manejar ese tipo de escenarios en un Plugin propio , pero esta vez , para mantener el post breve voy a dejar el código en la Activity que generó la notificación (puedes leer la entrada en inglés aquí: http://jmgomez.me/mvvmcross-handling-notification-clicks).

 

Digamos que queremos mostrar una notificación cuando algo sucede en nuestra aplicación y, a continuación , redirigir al usuario a un ViewModel personalizado.

 


void SetBackgroundAlert(Route route) {
            var intent = GetRouteViewIntent(route);
            var pendingItent = 
                PendingIntent.GetActivity(this, 0,intent, PendingIntentFlags.UpdateCurrent);

            var notificationManager = (NotificationManager)this.GetSystemService(Context.NotificationService);
            var notification = new Notification.Builder(this)
                .SetContentTitle(«Alarm«).SetContentText(RouteView.offRouteMessage)
                .SetContentIntent(pendingItent)
                .SetSmallIcon(Resource.Drawable.notification_icon).Notification;

            notificationManager.Notify(1, notification);
        
        }

Nada nuevo por ahora, acabamos de crear una notificación desde NotificationBuilder , la clave es el método GetRouteViewIntent . Hemos recuperado un Intent específico que se pasa al PendingIntent, a continuación, cuando el usuario hace clic en la notificación , se redirige a nuestro ViewModel . El método GetRouteViewIntent es el siguiente :


static Intent GetRouteViewIntent(Route route) {
            var request = new MvxViewModelRequest();
            request.ParameterValues = new System.Collections.Generic.Dictionary<stringstring>();                        
            request.ParameterValues.Add(«idRoute«, route.IdRoute.ToString());
            request.ParameterValues.Add(«fromRating«false.ToString());
            request.ViewModelType = typeof(RouteViewModel);
            var requestTranslator = Mvx.Resolve<IMvxAndroidViewModelRequestTranslator>();
            return requestTranslator.GetIntentFor(request);
        }

Acabamos de crear un Request ( con sus parámetros ) y luego creamos nuestro Intent como MvvmCross hace internamente.