2017-07-08 9 views
0

私はXamarinウォークスルーに従っており、それは私のためには機能しません。 コードはこれを正常に処理しますが、通知は送信されません。 エミュレータまたはデバイスに表示されることはありません。Xamarin.Forms Androidローカル通知が送信されない

私は何が起こっているのか分かりません。

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()); 

ヘルプやリンクは非常に役に立ちます。私はちょうど完全に失われている。これについて約14時間ほど作業しており、Googleでヘルプを見つけることはできません。

私の質問への回答:通知を正しく作成して送信するためのアイコンが必要です。しかし、持っていないというエラーは出ません。

ショートバージョン:通知にアイコンを追加

.SetSmallIcon(Resource.Drawable.icon); 

答えて

0

を追加する必要がありました。

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!あなたがアイコンを持っていることが必要です。私はそれについて考えなかった。機能テストだった。 – Hyren123

関連する問題