差分
ページの作成:「== 準備 == NuGetから以下のパッケージを入れる * Xamarin.Android.Support.v4 == 実装 == 以下の名前空間をいれる。<syntaxhighlight lang="csharp…」
== 準備 ==
NuGetから以下のパッケージを入れる
* Xamarin.Android.Support.v4
== 実装 ==
以下の名前空間をいれる。<syntaxhighlight lang="csharp">
using Android.Content;
using Android.Support.V4.App;
</syntaxhighlight>必要最小限でかけばこんな感じ。<syntaxhighlight lang="csharp">
// 通知を生成
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);
</syntaxhighlight>
== 関連項目 ==
* [[Xamarin.Androidで通知を表示しアプリを起動する]]
* [[Xamarin.AndroidでFirebase Cloud Messagingを使う]]
NuGetから以下のパッケージを入れる
* Xamarin.Android.Support.v4
== 実装 ==
以下の名前空間をいれる。<syntaxhighlight lang="csharp">
using Android.Content;
using Android.Support.V4.App;
</syntaxhighlight>必要最小限でかけばこんな感じ。<syntaxhighlight lang="csharp">
// 通知を生成
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);
</syntaxhighlight>
== 関連項目 ==
* [[Xamarin.Androidで通知を表示しアプリを起動する]]
* [[Xamarin.AndroidでFirebase Cloud Messagingを使う]]