「Xamarin.Androidで通知を表示する」の版間の差分
ナビゲーションに移動
検索に移動
(ページの作成:「== 準備 == NuGetから以下のパッケージを入れる * Xamarin.Android.Support.v4 == 実装 == 以下の名前空間をいれる。<syntaxhighlight lang="csharp…」) |
(相違点なし)
|
2019年1月25日 (金) 07:25時点における版
準備
NuGetから以下のパッケージを入れる
- Xamarin.Android.Support.v4
実装
以下の名前空間をいれる。
using Android.Content;
using Android.Support.V4.App;
必要最小限でかけばこんな感じ。
// 通知を生成
var message = "Hello, World!";
var notification = new NotificationCompat.Builder(context)
.SetSmallIcon(Android.Resource.Drawable.StarBigOn)
.SetContentTitle("Boop!")
.SetStyle(new NotificationCompat.BigTextStyle().BigText(message))
.SetContentText(message)
// 通知タップ時にインテントを発動させる場合
//.SetContentIntent(pendingIntent)
.builder.Build();
// 通知マネージャーを取得
var manager = (NotificationManager)this.GetSystemService(Context.NotificationService);
// 通知を発射
manager.Notify(1, notification);