2017-07-08 7 views
0

Ich habe die Xamarin Walkthrough gefolgt, und es funktioniert nicht für mich. Der Code fällt sauber durch, aber es sendet nie die Benachrichtigung. Es erscheint nie auf meinem Emulator oder Gerät.Xamarin.Forms Android Lokale Benachrichtigung nicht senden

Ich habe keine Ahnung was los ist.

public override void OnReceive(Context context, Intent intent) 
    { 

     string message = intent.GetStringExtra("message"); 
     string title = intent.GetStringExtra("title"); 
     int id = int.Parse(intent.GetStringExtra("id")); 

     //Generate a notification with just short text and small icon 
     NotificationCompat.Builder builder = new NotificationCompat.Builder(context) 
         .SetAutoCancel(true)     // Dismiss from the notif. area when clicked 
         .SetContentTitle(title)  // Set its title 
         .SetContentText(message); // The message to display. 


     NotificationManager notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService); 
     notificationManager.Notify(id, builder.Build()); 

Jede Hilfe oder Links wäre sehr hilfreich. Ich bin einfach völlig verloren. Ich arbeite seit ungefähr 14 Stunden daran und kann keine Hilfe bei Google finden.

Antwort auf meine Anfrage: Sie müssen ein Icon-Set haben, damit Benachrichtigungen korrekt erstellt und gesendet werden. Allerdings wird kein Fehler gesendet, wenn Sie keinen Fehler haben.

Kurzversion: Benötigte

.SetSmallIcon(Resource.Drawable.icon); 

Antwort

0

ein Symbol hinzufügen Benachrichtigung hinzufügen.

Notification.Builder builder = new Notification.Builder (this) 
.SetContentTitle ("Title") 
.SetContentText ("Message") 
.SetSmallIcon (Resource.Drawable.ic_notification); 

Notification notification = builder.Build(); 

NotificationManager notificationManager = 
     GetSystemService (Context.NotificationService) as NotificationManager; 

const int notificationId = 0; 
notificationManager.Notify (notificationId, notification); 
+0

Ah! Ich sehe, Sie müssen ein Icon haben. Daran hatte ich nicht gedacht. Es war nur ein Funktionstest. – Hyren123

Verwandte Themen