2017-04-04 4 views
0

Guten Tag, ich lokale Benachrichtigungen auf meinem xamarin.forms aufbauen müssen, so begann ich von android: 1. Im core Projekt i eine Schnittstelle erstellt haben:Lokale Benachrichtigungen auf Xamarin.forms

public interface INotification 
    { 
     void CreateNotification(); 
    } 

2. im Droid ich habe implementiert Benachrichtigungen:

[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. Schließlich habe ich einen Abhängigkeitsdienst auf der Hauptseite des Kerns pr oject

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

    }

aber ich nicht eine Benachrichtigung sehen! P.S. Es funktioniert gut auf Xamarin.android App.

Antwort

0

Der Fehler war in einer worng Abhängigkeit:

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

GELÖST

Verwandte Themen