2017-08-05 19 views
0

私は通知を送信するための以下のコードを持っていますが、アプリケーションを起動したときに通知が表示されません。何か不足していますか?Xamarinサービス通知が開始しない

[Service] 
public class MyService : Service 
{ 

    const int NOTIFICATION_ID = 9000; 

    public override IBinder OnBind(Intent intent) 
    { 
     return null; 
    } 

    public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) 
    { 
     // Code omitted for clarity - here is where the service would do something. 

     // Work has finished, now dispatch anotification to let the user know. 
     Notification.Builder notificationBuilder = new Notification.Builder(this) 
      // .SetSmallIcon(Resource.Drawable.ic_notification_small_icon) 
      // .SetContentTitle(Resources.GetString(Resource.String.notification_content_title)) 
      .SetContentTitle("Comic Pull App") 
      //.SetContentText(Resources.GetString(Resource.String.notification_content_text)); 
      .SetContentText("New Comics came out this week. Repull this month if needed."); 
     var notificationManager = (NotificationManager)GetSystemService(NotificationService); 
     notificationManager.Notify(NOTIFICATION_ID, notificationBuilder.Build()); 

     return StartCommandResult.Sticky; 
    } 

私は私のMainActivityに以下があります。

StartService(new Intent(this, typeof(MyService))); 

私は私のマニフェストファイルに以下があります:

<application android:label="ToolbarFun" android:theme="@style/MyTheme"> 
    <service android:name=".MyService" android:exported="false" android:enabled="true"/> 
</application> 

答えて

0

が、私は通知が時に送信され表示されません私は私のアプリケーションを開始します。何か不足していますか?

SetSmallIcon()メソッドを使用しないとできません。 Notificationのアイコンを設定する必要があります。Notificationだけを送信できます。

+0

@ Freiza1991、問題がありますか? –

+0

うん、それは問題でした!助けてくれてありがとう。私はちょうどアイコンを追加し、それは始まりました。 – Freiza1991

関連する問題