私は単純な通知を送信しようとしています。私はそれの依存関係にするために、このラインを持っている私の実装の名前空間定義の前にXamarin NotificationManager.notify(..)メソッドでローカル通知を送信できないのはなぜですか
class PlatformNotifier :INotifier
{
public void LocalNotify(string title, string message)
{
NotificationManager notificationManager = Android.App.Application.Context.GetSystemService(Context.NotificationService) as NotificationManager;
Notification.Builder builder = new Notification.Builder(Android.App.Application.Context)
.SetContentTitle(title)
.SetContentText(message)
.SetAutoCancel(true);
Notification notification = builder.Build();
notificationManager.Notify(1, notification);
}
}
:このような.droidプロジェクトのインターフェイスを実装する次に
public interface INotifier
{
void LocalNotify(string title, string message);
}
:私はこのシンプルなインターフェイスで出始めますサービス
[assembly: Dependency(typeof(PlatformNotifier))]
は最後に、私は次のコード
でサービスを呼び出しますデバッグを介して私はプラットフォームノーティファイアのコードに到達し、Notify(...)
が呼び出されることを確認しましたが、通知は表示されません。
どのAndroidバージョンをターゲットにしていますか? –
私はターゲットを絞っています5.1私は信じる – scuz888
それは 'NotificationCompat.Builder'を必要としないようにしてください。あなたのアプローチが[Xamarinの推薦方法](https://developer.xamarin.com/guides/cross-platform/application_fundamentals/notifications/android/local_notifications_in_android/)のように思われるので、代わりに現在のアクティビティを試すことをお勧めしますコンテキストのためのアプリケーションの。 –