SlideShare a Scribd company logo
1 of 31
Download to read offline
Notificationで通知しよう 
ThreeColors 
赤井忠昭
自己紹介 
• 赤井忠昭(@akai_t)! 
• Androidに興味をもったためにThree Colorsという屋 
号で独立! 
• 元はWeb系のエンジニア(PHPを得意としていた)! 
• Androidは2009年から少しずつやりはじめていて、 
2010年にはじめてのアプリを公開! 
• Androidのために独立したが、現在は仕事で 
Androidアプリケーション開発は少なめ
AndroidWearの基本的な仕組み 
• Android 4.3以上の端末と接続が可能! 
• 端末のAndroid Wearアプリを利用して接続! 
• 実際の接続はBluetooth(接続時にペアリングが必要) 
Bluetooth接続
Android Wear通知概要 
• Android端末のNotificationをAndroidWearに表示! 
• AndroidWearのタップ、スワイプ、音声による入力 
をAndroid端末に表示 
Notificationを通知 
入力を通知
Notification表示の仕組み 
Android Wearアプリで 
NotificationListenerServiceを利用して 
Notificationの情報を取得 
Notificationで表示できる情報は 
AndroidWearで表示できるものが多い
Android のNotification 
1.Content title 
2.Large icon 
3.Content text 
4.Content info 
5.Small icon 
6.Time that the notification was issued. 
7.the details area. 
Big picture style 
Big text style 
Inbox style
Android のNotification 
NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
builder.setSmallIcon(android.R.drawable.ic_menu_info_details ); 
builder.setContentTitle("ContentTitle"); 
builder.setContentText("ContentText"); 
builder.setContentInfo("info"); 
builder.setLargeIcon(BitmapFactory.decodeResource( 
getResources(), R.drawable.ic_launcher)); 
builder.setWhen(System.currentTimeMillis()); 
! 
NotificationManagerCompat notificationManager = 
NotificationManagerCompat.from(this); 
notificationManager.notify(1, builder.build());
Android のNotification 
NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
builder.setSmallIcon(android.R.drawable.ic_menu_info_details ); 
builder.setContentTitle("ContentTitle"); 
builder.setContentText("ContentText"); 
builder.setContentInfo("info"); 
builder.setWhen(System.currentTimeMillis()); 
! 
NotificationManagerCompat notificationManager = 
NotificationManagerCompat.from(this); 
notificationManager.notify(1, builder.build());
Android のNotification Style 
Big picture style 
NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
builder.setSmallIcon(android.R.drawable.ic_menu_info_details ); 
builder.setContentTitle("ContentTitle"); 
builder.setContentText("ContentText"); 
builder.setContentInfo("info"); 
builder.setStyle(new NotificationCompat 
.BigPictureStyle() 
.setBigContentTitle("BigContentTitle") 
.bigPicture(BitmapFactory.decodeResource( 
getResources(), R.drawable.sea)) 
.setSummaryText("summary")); 
! 
NotificationManagerCompat notificationManager = 
NotificationManagerCompat.from(this); 
notificationManager.notify(1, builder.build());
Android のNotification Style 
Big text style 
NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
builder.setSmallIcon(android.R.drawable.ic_menu_info_details ); 
builder.setContentTitle("ContentTitle"); 
builder.setContentText("ContentText"); 
builder.setContentInfo("info"); 
builder.setStyle(new NotificationCompat 
.BigTextStyle() 
.setBigContentTitle("BigContentTitle") 
.bigText(“テストテスト ~(略)~ テストテスト”) 
.setSummaryText("summary")); 
! 
NotificationManagerCompat notificationManager = 
NotificationManagerCompat.from(this); 
notificationManager.notify(1, builder.build());
Android のNotification Style 
Inbox style 
NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
builder.setSmallIcon(android.R.drawable.ic_menu_info_details ); 
builder.setContentTitle("ContentTitle"); 
builder.setContentText("ContentText"); 
builder.setContentInfo("info"); 
builder.setStyle(new NotificationCompat 
.InboxStyle() 
.setBigContentTitle("BigContentTitle") 
.addLine("Line 1") 
.addLine("Line 2") 
.setSummaryText("summary")); 
! 
NotificationManagerCompat notificationManager = 
NotificationManagerCompat.from(this); 
notificationManager.notify(1, builder.build());
Android のNotification 
Intent の発行とAction追加 
Intent viewIntent = new Intent(this, MyActivity.class); 
PendingIntent viewPendingIntent = 
PendingIntent.getActivity(this,0,viewIntent,0); 
! 
Intent mapIntent = new Intent(Intent.ACTION_VIEW); 
Uri geoUri = Uri.parse("geo:0,0?q=" + Uri.encode("大阪")); 
mapIntent.setData(geoUri); 
PendingIntent mapPendingIntent = 
PendingIntent.getActivity(this,0,mapIntent,0); 
! 
builder = new NotificationCompat.Builder(this); 
builder.setSmallIcon(R.drawable.ic_launcher); 
builder.setContentTitle("ContentTitle"); 
builder.setContentText("ContentText"); 
builder.setContentIntent(viewPendingIntent); 
builder.addAction(android.R.drawable.ic_menu_mapmode, 
"map",mapPendingIntent);
Android のNotification 
Intent の発行とAction追加
Notificationまとめ 
• 通常のNotificationと変わらない作りでAndroidWearに 
表示が可能 
NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
builder.setSmallIcon(R.drawable.ic_launcher ); 
builder.setContentTitle("ContentTitle"); 
builder.setContentText("ContentText"); 
! 
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); 
notificationManager.notify(1, builder.build()); 
• AndroidWearを意識しないとAndroidWear側が予期せ 
ぬデザインになり得る 
setLargeIconによる背景表示 
Actionアイコンがぼやける
AndroidWearを意識する設定 
• AndroidWearに表示しない! 
• AndroidWearのみ表示する! 
• AndroidWearのみで行うAction! 
• 音声返信! 
• 選択返信! 
• Pages! 
• Stacking Notifications
AndroidWearに表示しない通知 
• setLocalOnlyにtrueをセットする 
NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
builder.setSmallIcon(R.drawable.ic_launcher ); 
builder.setContentTitle("ContentTitle"); 
builder.setContentText("ContentText"); 
builder.setLocalOnly(true); 
! 
NotificationManagerCompat notificationManager = 
NotificationManagerCompat.from(this); 
notificationManager.notify(1, builder.build()); 
• setOngoingにtrueをセットする 
NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
builder.setSmallIcon(R.drawable.ic_launcher ); 
builder.setContentTitle("ContentTitle"); 
builder.setContentText("ContentText"); 
builder.setOngoing(true); 
! 
NotificationManagerCompat notificationManager = 
NotificationManagerCompat.from(this); 
notificationManager.notify(1, builder.build());
AndroidWearのみに通知を表示 
• setGroupでグループ指定をする 
NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
builder.setSmallIcon(R.drawable.ic_launcher ); 
builder.setContentTitle("ContentTitle"); 
builder.setContentText("ContentText"); 
builder.setGroup(getString(R.string.app_name)); 
! 
NotificationManagerCompat notificationManager = 
NotificationManagerCompat.from(this); 
notificationManager.notify(1, builder.build());
通知の組み合わせ 
// 携帯側通知 
NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
builder.setSmallIcon(R.drawable.ic_launcher ); 
builder.setOngoing(true); 
builder.setContentTitle("ContentTitle"); 
builder.setContentText("ContentText"); 
! 
//AndroidWear側通知 
NotificationCompat.Builder wearBuilder = new NotificationCompat.Builder(this); 
wearBuilder.setSmallIcon(R.drawable.ic_launcher ); 
wearBuilder.setContentTitle(“Wear ContentTitle"); 
wearBuilder.setContentText("Wear ContentText"); 
wearBuilder.setGroup(getString(R.string.app_name)); 
! 
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); 
notificationManager.notify(1, builder.build()); 
notificationManager.notify(2, wearBuilder.build());
本来のGroupの利用方法 
• Stacking Notifications
本来のGroupの利用方法
WearableExtenderの利用 
• NotificationCompat.WearableExtenderを利用することで 
AndroidWear用に色々と拡張が可能 
• Group以外はこのWearableExtenderを利用する
WearableExtenderの利用 
• Android WearのみのAction
WearableExtenderの利用
WearableExtenderの利用 
• 音声返信
WearableExtenderの利用
WearableExtenderの利用 
• 音声返信の受け取り
WearableExtenderの利用 
• 音声 or 選択返信 
strings.xml
WearableExtenderの利用 
• Pages
WearableExtenderの利用
まとめ 
• 通知をメインとするAndroidWearはNotificationを作 
成するだけで通知されるので特別な対応は必要ない! 
• しかしAndroidWearを意識しないとAndroidWear側 
で思わぬ表示になることがある! 
• 拡張はすごく簡単なのでNotificationを作成するとき 
はAndroidWearを意識した作りにすること
ご清聴ありがとうございました 
ThreeColors 赤井 忠昭 
@akai_t

More Related Content

What's hot

Realm meetup LT大会(Androidアプリへの適用経験談)
Realm meetup LT大会(Androidアプリへの適用経験談)Realm meetup LT大会(Androidアプリへの適用経験談)
Realm meetup LT大会(Androidアプリへの適用経験談)Kenichi Kambara
 
Android Wearアプリ プレビュー版→正式版への移植ガイド
Android Wearアプリ プレビュー版→正式版への移植ガイドAndroid Wearアプリ プレビュー版→正式版への移植ガイド
Android Wearアプリ プレビュー版→正式版への移植ガイドKenichi Kambara
 
Android Wearアプリ開発経験談
Android Wearアプリ開発経験談Android Wearアプリ開発経験談
Android Wearアプリ開発経験談Kenichi Kambara
 
Android Wear & Android M 最新トピック
Android Wear & Android M 最新トピックAndroid Wear & Android M 最新トピック
Android Wear & Android M 最新トピックKenichi Kambara
 
24時間でiOSアプリ-Twitterクライアント-の作成にチャレンジ
24時間でiOSアプリ-Twitterクライアント-の作成にチャレンジ24時間でiOSアプリ-Twitterクライアント-の作成にチャレンジ
24時間でiOSアプリ-Twitterクライアント-の作成にチャレンジ聡 中川
 
Cordova利用アプリ開発経験談
Cordova利用アプリ開発経験談Cordova利用アプリ開発経験談
Cordova利用アプリ開発経験談Kenichi Kambara
 
[Potatotips]クロスプラットフォーム開発Tips
[Potatotips]クロスプラットフォーム開発Tips[Potatotips]クロスプラットフォーム開発Tips
[Potatotips]クロスプラットフォーム開発TipsKenichi Kambara
 

What's hot (8)

Realm meetup LT大会(Androidアプリへの適用経験談)
Realm meetup LT大会(Androidアプリへの適用経験談)Realm meetup LT大会(Androidアプリへの適用経験談)
Realm meetup LT大会(Androidアプリへの適用経験談)
 
Android Wearアプリ プレビュー版→正式版への移植ガイド
Android Wearアプリ プレビュー版→正式版への移植ガイドAndroid Wearアプリ プレビュー版→正式版への移植ガイド
Android Wearアプリ プレビュー版→正式版への移植ガイド
 
Android Wearアプリ開発経験談
Android Wearアプリ開発経験談Android Wearアプリ開発経験談
Android Wearアプリ開発経験談
 
H29 4班
H29 4班H29 4班
H29 4班
 
Android Wear & Android M 最新トピック
Android Wear & Android M 最新トピックAndroid Wear & Android M 最新トピック
Android Wear & Android M 最新トピック
 
24時間でiOSアプリ-Twitterクライアント-の作成にチャレンジ
24時間でiOSアプリ-Twitterクライアント-の作成にチャレンジ24時間でiOSアプリ-Twitterクライアント-の作成にチャレンジ
24時間でiOSアプリ-Twitterクライアント-の作成にチャレンジ
 
Cordova利用アプリ開発経験談
Cordova利用アプリ開発経験談Cordova利用アプリ開発経験談
Cordova利用アプリ開発経験談
 
[Potatotips]クロスプラットフォーム開発Tips
[Potatotips]クロスプラットフォーム開発Tips[Potatotips]クロスプラットフォーム開発Tips
[Potatotips]クロスプラットフォーム開発Tips
 

Similar to AndroidWear勉強会

もう怖くないモバイルアプリ開発!
もう怖くないモバイルアプリ開発!もう怖くないモバイルアプリ開発!
もう怖くないモバイルアプリ開発!Toshiki Iga
 
20111031 MobileWeb at TDC
20111031 MobileWeb at TDC20111031 MobileWeb at TDC
20111031 MobileWeb at TDCNobuhiro Sue
 
Android Lecture #01 @PRO&BSC Inc.
Android Lecture #01 @PRO&BSC Inc.Android Lecture #01 @PRO&BSC Inc.
Android Lecture #01 @PRO&BSC Inc.Yuki Higuchi
 
androidのgpsアプリってどうよ|株式会社コンテンツワン
androidのgpsアプリってどうよ|株式会社コンテンツワンandroidのgpsアプリってどうよ|株式会社コンテンツワン
androidのgpsアプリってどうよ|株式会社コンテンツワンKatsuaki Sato
 
ARコンテンツ作成勉強会:使ってみようSmartAR 基礎から支援ツール活用まで
ARコンテンツ作成勉強会:使ってみようSmartAR  基礎から支援ツール活用までARコンテンツ作成勉強会:使ってみようSmartAR  基礎から支援ツール活用まで
ARコンテンツ作成勉強会:使ってみようSmartAR 基礎から支援ツール活用までTakashi Yoshinaga
 
Appc schoo 0219
Appc schoo 0219Appc schoo 0219
Appc schoo 0219caytosales
 
アンドロイド勉強会第二回 080525 3
アンドロイド勉強会第二回  080525 3アンドロイド勉強会第二回  080525 3
アンドロイド勉強会第二回 080525 3shimay
 
Android Lecture #02 @PRO&BSC Inc.
Android Lecture #02 @PRO&BSC Inc.Android Lecture #02 @PRO&BSC Inc.
Android Lecture #02 @PRO&BSC Inc.Yuki Higuchi
 
事例で解説するハイブリッドアプリ開発のポイント
事例で解説するハイブリッドアプリ開発のポイント 事例で解説するハイブリッドアプリ開発のポイント
事例で解説するハイブリッドアプリ開発のポイント Monaca
 
Android wearを触ってみた
Android wearを触ってみたAndroid wearを触ってみた
Android wearを触ってみたYoichi Toyota
 
みゆっき☆Think#3 「androidに触ってみるよ!」
みゆっき☆Think#3 「androidに触ってみるよ!」みゆっき☆Think#3 「androidに触ってみるよ!」
みゆっき☆Think#3 「androidに触ってみるよ!」techtalkdwango
 
Windows IoT Core and Robot Arm
Windows IoT Core and Robot ArmWindows IoT Core and Robot Arm
Windows IoT Core and Robot ArmMasuda Tomoaki
 
IoT 入門 ~ .NET Gadgeteer で簡単プログラミング
IoT 入門 ~ .NET Gadgeteer で簡単プログラミングIoT 入門 ~ .NET Gadgeteer で簡単プログラミング
IoT 入門 ~ .NET Gadgeteer で簡単プログラミングYoshitaka Seo
 
【17-A-1】Mobile Future Conference開会のご挨拶/世界へ挑むDeNAの「X-border」「X-device」戦略
【17-A-1】Mobile Future Conference開会のご挨拶/世界へ挑むDeNAの「X-border」「X-device」戦略【17-A-1】Mobile Future Conference開会のご挨拶/世界へ挑むDeNAの「X-border」「X-device」戦略
【17-A-1】Mobile Future Conference開会のご挨拶/世界へ挑むDeNAの「X-border」「X-device」戦略Developers Summit
 
スマートウォッチのプロダクト開発
スマートウォッチのプロダクト開発スマートウォッチのプロダクト開発
スマートウォッチのプロダクト開発KayoOkada
 
iOS 8 Widget ~ 導入から Tips まで
iOS 8 Widget ~ 導入から Tips までiOS 8 Widget ~ 導入から Tips まで
iOS 8 Widget ~ 導入から Tips までYuki Tanabe
 
AIR For Android 勉強会 第1回
AIR For Android 勉強会 第1回AIR For Android 勉強会 第1回
AIR For Android 勉強会 第1回biscuitjam
 

Similar to AndroidWear勉強会 (20)

もう怖くないモバイルアプリ開発!
もう怖くないモバイルアプリ開発!もう怖くないモバイルアプリ開発!
もう怖くないモバイルアプリ開発!
 
20111031 MobileWeb at TDC
20111031 MobileWeb at TDC20111031 MobileWeb at TDC
20111031 MobileWeb at TDC
 
Android Wear
Android WearAndroid Wear
Android Wear
 
Android Lecture #01 @PRO&BSC Inc.
Android Lecture #01 @PRO&BSC Inc.Android Lecture #01 @PRO&BSC Inc.
Android Lecture #01 @PRO&BSC Inc.
 
androidのgpsアプリってどうよ|株式会社コンテンツワン
androidのgpsアプリってどうよ|株式会社コンテンツワンandroidのgpsアプリってどうよ|株式会社コンテンツワン
androidのgpsアプリってどうよ|株式会社コンテンツワン
 
ARコンテンツ作成勉強会:使ってみようSmartAR 基礎から支援ツール活用まで
ARコンテンツ作成勉強会:使ってみようSmartAR  基礎から支援ツール活用までARコンテンツ作成勉強会:使ってみようSmartAR  基礎から支援ツール活用まで
ARコンテンツ作成勉強会:使ってみようSmartAR 基礎から支援ツール活用まで
 
Android Wear Apps
Android Wear AppsAndroid Wear Apps
Android Wear Apps
 
Appc schoo 0219
Appc schoo 0219Appc schoo 0219
Appc schoo 0219
 
アンドロイド勉強会第二回 080525 3
アンドロイド勉強会第二回  080525 3アンドロイド勉強会第二回  080525 3
アンドロイド勉強会第二回 080525 3
 
20111112OITEC
20111112OITEC20111112OITEC
20111112OITEC
 
Android Lecture #02 @PRO&BSC Inc.
Android Lecture #02 @PRO&BSC Inc.Android Lecture #02 @PRO&BSC Inc.
Android Lecture #02 @PRO&BSC Inc.
 
事例で解説するハイブリッドアプリ開発のポイント
事例で解説するハイブリッドアプリ開発のポイント 事例で解説するハイブリッドアプリ開発のポイント
事例で解説するハイブリッドアプリ開発のポイント
 
Android wearを触ってみた
Android wearを触ってみたAndroid wearを触ってみた
Android wearを触ってみた
 
みゆっき☆Think#3 「androidに触ってみるよ!」
みゆっき☆Think#3 「androidに触ってみるよ!」みゆっき☆Think#3 「androidに触ってみるよ!」
みゆっき☆Think#3 「androidに触ってみるよ!」
 
Windows IoT Core and Robot Arm
Windows IoT Core and Robot ArmWindows IoT Core and Robot Arm
Windows IoT Core and Robot Arm
 
IoT 入門 ~ .NET Gadgeteer で簡単プログラミング
IoT 入門 ~ .NET Gadgeteer で簡単プログラミングIoT 入門 ~ .NET Gadgeteer で簡単プログラミング
IoT 入門 ~ .NET Gadgeteer で簡単プログラミング
 
【17-A-1】Mobile Future Conference開会のご挨拶/世界へ挑むDeNAの「X-border」「X-device」戦略
【17-A-1】Mobile Future Conference開会のご挨拶/世界へ挑むDeNAの「X-border」「X-device」戦略【17-A-1】Mobile Future Conference開会のご挨拶/世界へ挑むDeNAの「X-border」「X-device」戦略
【17-A-1】Mobile Future Conference開会のご挨拶/世界へ挑むDeNAの「X-border」「X-device」戦略
 
スマートウォッチのプロダクト開発
スマートウォッチのプロダクト開発スマートウォッチのプロダクト開発
スマートウォッチのプロダクト開発
 
iOS 8 Widget ~ 導入から Tips まで
iOS 8 Widget ~ 導入から Tips までiOS 8 Widget ~ 導入から Tips まで
iOS 8 Widget ~ 導入から Tips まで
 
AIR For Android 勉強会 第1回
AIR For Android 勉強会 第1回AIR For Android 勉強会 第1回
AIR For Android 勉強会 第1回
 

AndroidWear勉強会

  • 2. 自己紹介 • 赤井忠昭(@akai_t)! • Androidに興味をもったためにThree Colorsという屋 号で独立! • 元はWeb系のエンジニア(PHPを得意としていた)! • Androidは2009年から少しずつやりはじめていて、 2010年にはじめてのアプリを公開! • Androidのために独立したが、現在は仕事で Androidアプリケーション開発は少なめ
  • 3. AndroidWearの基本的な仕組み • Android 4.3以上の端末と接続が可能! • 端末のAndroid Wearアプリを利用して接続! • 実際の接続はBluetooth(接続時にペアリングが必要) Bluetooth接続
  • 4. Android Wear通知概要 • Android端末のNotificationをAndroidWearに表示! • AndroidWearのタップ、スワイプ、音声による入力 をAndroid端末に表示 Notificationを通知 入力を通知
  • 5. Notification表示の仕組み Android Wearアプリで NotificationListenerServiceを利用して Notificationの情報を取得 Notificationで表示できる情報は AndroidWearで表示できるものが多い
  • 6. Android のNotification 1.Content title 2.Large icon 3.Content text 4.Content info 5.Small icon 6.Time that the notification was issued. 7.the details area. Big picture style Big text style Inbox style
  • 7. Android のNotification NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(android.R.drawable.ic_menu_info_details ); builder.setContentTitle("ContentTitle"); builder.setContentText("ContentText"); builder.setContentInfo("info"); builder.setLargeIcon(BitmapFactory.decodeResource( getResources(), R.drawable.ic_launcher)); builder.setWhen(System.currentTimeMillis()); ! NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(1, builder.build());
  • 8. Android のNotification NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(android.R.drawable.ic_menu_info_details ); builder.setContentTitle("ContentTitle"); builder.setContentText("ContentText"); builder.setContentInfo("info"); builder.setWhen(System.currentTimeMillis()); ! NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(1, builder.build());
  • 9. Android のNotification Style Big picture style NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(android.R.drawable.ic_menu_info_details ); builder.setContentTitle("ContentTitle"); builder.setContentText("ContentText"); builder.setContentInfo("info"); builder.setStyle(new NotificationCompat .BigPictureStyle() .setBigContentTitle("BigContentTitle") .bigPicture(BitmapFactory.decodeResource( getResources(), R.drawable.sea)) .setSummaryText("summary")); ! NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(1, builder.build());
  • 10. Android のNotification Style Big text style NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(android.R.drawable.ic_menu_info_details ); builder.setContentTitle("ContentTitle"); builder.setContentText("ContentText"); builder.setContentInfo("info"); builder.setStyle(new NotificationCompat .BigTextStyle() .setBigContentTitle("BigContentTitle") .bigText(“テストテスト ~(略)~ テストテスト”) .setSummaryText("summary")); ! NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(1, builder.build());
  • 11. Android のNotification Style Inbox style NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(android.R.drawable.ic_menu_info_details ); builder.setContentTitle("ContentTitle"); builder.setContentText("ContentText"); builder.setContentInfo("info"); builder.setStyle(new NotificationCompat .InboxStyle() .setBigContentTitle("BigContentTitle") .addLine("Line 1") .addLine("Line 2") .setSummaryText("summary")); ! NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(1, builder.build());
  • 12. Android のNotification Intent の発行とAction追加 Intent viewIntent = new Intent(this, MyActivity.class); PendingIntent viewPendingIntent = PendingIntent.getActivity(this,0,viewIntent,0); ! Intent mapIntent = new Intent(Intent.ACTION_VIEW); Uri geoUri = Uri.parse("geo:0,0?q=" + Uri.encode("大阪")); mapIntent.setData(geoUri); PendingIntent mapPendingIntent = PendingIntent.getActivity(this,0,mapIntent,0); ! builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_launcher); builder.setContentTitle("ContentTitle"); builder.setContentText("ContentText"); builder.setContentIntent(viewPendingIntent); builder.addAction(android.R.drawable.ic_menu_mapmode, "map",mapPendingIntent);
  • 13. Android のNotification Intent の発行とAction追加
  • 14. Notificationまとめ • 通常のNotificationと変わらない作りでAndroidWearに 表示が可能 NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_launcher ); builder.setContentTitle("ContentTitle"); builder.setContentText("ContentText"); ! NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(1, builder.build()); • AndroidWearを意識しないとAndroidWear側が予期せ ぬデザインになり得る setLargeIconによる背景表示 Actionアイコンがぼやける
  • 15. AndroidWearを意識する設定 • AndroidWearに表示しない! • AndroidWearのみ表示する! • AndroidWearのみで行うAction! • 音声返信! • 選択返信! • Pages! • Stacking Notifications
  • 16. AndroidWearに表示しない通知 • setLocalOnlyにtrueをセットする NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_launcher ); builder.setContentTitle("ContentTitle"); builder.setContentText("ContentText"); builder.setLocalOnly(true); ! NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(1, builder.build()); • setOngoingにtrueをセットする NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_launcher ); builder.setContentTitle("ContentTitle"); builder.setContentText("ContentText"); builder.setOngoing(true); ! NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(1, builder.build());
  • 17. AndroidWearのみに通知を表示 • setGroupでグループ指定をする NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_launcher ); builder.setContentTitle("ContentTitle"); builder.setContentText("ContentText"); builder.setGroup(getString(R.string.app_name)); ! NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(1, builder.build());
  • 18. 通知の組み合わせ // 携帯側通知 NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_launcher ); builder.setOngoing(true); builder.setContentTitle("ContentTitle"); builder.setContentText("ContentText"); ! //AndroidWear側通知 NotificationCompat.Builder wearBuilder = new NotificationCompat.Builder(this); wearBuilder.setSmallIcon(R.drawable.ic_launcher ); wearBuilder.setContentTitle(“Wear ContentTitle"); wearBuilder.setContentText("Wear ContentText"); wearBuilder.setGroup(getString(R.string.app_name)); ! NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(1, builder.build()); notificationManager.notify(2, wearBuilder.build());
  • 21. WearableExtenderの利用 • NotificationCompat.WearableExtenderを利用することで AndroidWear用に色々と拡張が可能 • Group以外はこのWearableExtenderを利用する
  • 27. WearableExtenderの利用 • 音声 or 選択返信 strings.xml
  • 30. まとめ • 通知をメインとするAndroidWearはNotificationを作 成するだけで通知されるので特別な対応は必要ない! • しかしAndroidWearを意識しないとAndroidWear側 で思わぬ表示になることがある! • 拡張はすごく簡単なのでNotificationを作成するとき はAndroidWearを意識した作りにすること