繁体   English   中英

Xamarin.forms上的本地通知

[英]Local Notifications on Xamarin.forms

美好的一天,我需要在xamarin.forms上构建本地通知,所以我从android开始:1.在core项目中,我创建了一个接口:

 public interface INotification
    {
        void CreateNotification();
    }

2.在Droid我实现了通知:

[assembly: Xamarin.Forms.Dependency(typeof(Notification))]
namespace Test.Droid
{

    class Notification : Interfaces.INotification
    {
        public void CreateNotification()
        {
            string content = @"Here is the text";
            int messageId = 999;

            NotificationCompat.Builder builder = new NotificationCompat.Builder(Application.Context)
                .SetAutoCancel(true)
                .SetContentTitle("My Notifications")
                .SetSmallIcon(Resource.Drawable.icon)
                .SetContentText("Click here to next Activity")
                .SetStyle(new NotificationCompat.BigTextStyle().BigText(content))
                ;

            NotificationManager notificationManager = (NotificationManager)Application.Context.GetSystemService(Context.NotificationService);
            notificationManager.Notify(messageId, builder.Build());


        }
    }
}
  1. 最后,我将依赖项服务放在核心项目的主页上

     public MainPage() { InitializeComponent(); DependencyService.Get<INotification>().CreateNotification(); 

    }

但是我没有收到通知! PS它在xamarin.android应用程序上正常工作。

错误在于疲倦的依赖:

[assembly: Xamarin.Forms.Dependency(typeof(Test.Droid.Notification))]

解决了

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM