Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Throw a local notification from shared code project that goes to another view when clicked.

$
0
0

I have defined a service interface that allows throwing a local UI notification with the following interface:

    public interface ILocalNotificationService
    {
        void CreateLocalNotification();
    }

This service is being implemented in both Android and iOS projects. The Android implementation that works is this one:

[assembly: Dependency(typeof(LocalNotificationService)) ]
namespace LocalNotification.Droid
{
    public class LocalNotificationService:Java.Lang.Object, ILocalNotificationService
    {
        public void CreateLocalNotification()
        {
             Context ctx = Forms.Context;
             NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx)
                            .SetAutoCancel(true)
                            .SetSmallIcon(Resource.Drawable.Icon)
                            .SetContentTitle("Button Clicked") 
                            .SetContentText(String.Format("The button has been clicked"));
              NotificationManager notificationManager = 
            (NotificationManager)ctx.GetSystemService(Context.NotificationService);
              notificationManager.Notify(1000,builder.Build());
        }
    }
}

Given this, I need to set the content Intent ( .SetContentIntent(PendingIntent pendingIntent) ) so the user will be sent to another view, and to use this I need the ACTIVITY that the user should be redirected to when tapping on the Notification.

Since in Xamarin Forms we are not using Activities but Pages made in the shared project , ¿How could I get the Activity from a Page or a ContentPage?

Is there any Xamarin Forms component that helps using local Notifications?

Thanks!


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>