2017-04-04 79 views
0

美好的一天,我 需要在我的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()); 


     } 
    } 
} 
  • 最后我把一个依赖服务核心PR的主页上oject

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

    }

  • 但我没有看到通知! P.S.它在xamarin.android应用程序上工作得很好。

    回答

    0

    这个错误是一个拨错的依赖性:

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

    解决