6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

qnoteAdvent Calendar 2015

Day 6

Android Wear でNotificationを表示する

Posted at

検証環境

XperiaZ1 (Android 4.4.2)
Sony SmartWatch3 (Android Wear 1.3.0.2160025, Android OS 5.1.1)

Notificationを投げてみた

適当にNotificationを作成し投げる

Intent intent = new Intent(getActivity(), MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(getActivity(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

Notification notification = new NotificationCompat.Builder(getActivity())
         .setContentTitle("新着メッセージがあります")
         .setContentText("xxさんからメッセージが届いています")
         .setSmallIcon(R.mipmap.ic_launcher)
         .setContentIntent(pendingIntent)
         .addAction(R.mipmap.ic_launcher, "返信", pendingIntent)
         .addAction(R.mipmap.ic_launcher, "転送", pendingIntent)
         .build();

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getActivity());
notificationManager.notify(0, notification);

すると母艦のスマホでは以下のようになります。
Screenshot_2015-12-03-13-39-08.png

ではAndroid Wearの方ではどうなっているかというと
device-2015-12-03-133959.png
device-2015-12-03-134036.png
device-2015-12-03-134055.png
device-2015-12-03-134103.png
device-2015-12-03-134118.png

addActionで設定したものがそのまま表示されます。
当然といえば当然ですが、Notificationに関してはAndroid Wear向けに処理を追加する必要はないようです。

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?