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>
@ Freiza1991,有什麼問題嗎? –
是的,這是問題!非常感謝您的幫助。我剛添加了一個圖標,它就開始了。 – Freiza1991