AndroidWear勉強会

31
Notificationで通知しよう ThreeColors 赤井忠昭

description

大阪で2014/8/30に行われたAndroidWear勉強会の資料です。 Notification周りについて発表しました

Transcript of AndroidWear勉強会

Page 1: AndroidWear勉強会

Notificationで通知しようThreeColors 赤井忠昭

Page 2: AndroidWear勉強会

自己紹介• 赤井忠昭(@akai_t)!• Androidに興味をもったためにThree Colorsという屋号で独立!

• 元はWeb系のエンジニア(PHPを得意としていた)!• Androidは2009年から少しずつやりはじめていて、

2010年にはじめてのアプリを公開!• Androidのために独立したが、現在は仕事で

Androidアプリケーション開発は少なめ

Page 3: AndroidWear勉強会

AndroidWearの基本的な仕組み

• Android 4.3以上の端末と接続が可能!• 端末のAndroid Wearアプリを利用して接続!• 実際の接続はBluetooth(接続時にペアリングが必要)

Bluetooth接続

Page 4: AndroidWear勉強会

Android Wear通知概要

• Android端末のNotificationをAndroidWearに表示!• AndroidWearのタップ、スワイプ、音声による入力をAndroid端末に表示

Notificationを通知

入力を通知

Page 5: AndroidWear勉強会

Notification表示の仕組み

Android WearアプリでNotificationListenerServiceを利用してNotificationの情報を取得

Notificationで表示できる情報はAndroidWearで表示できるものが多い

Page 6: 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

Page 7: AndroidWear勉強会

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());

Page 8: AndroidWear勉強会

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());

Page 9: AndroidWear勉強会

Android のNotification StyleBig 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());

Page 10: AndroidWear勉強会

Android のNotification StyleBig 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());

Page 11: AndroidWear勉強会

Android のNotification StyleInbox 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());

Page 12: AndroidWear勉強会

Android のNotification

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);

Intent の発行とAction追加

Page 13: AndroidWear勉強会

Android のNotificationIntent の発行とAction追加

Page 14: AndroidWear勉強会

Notificationまとめ

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());

• 通常のNotificationと変わらない作りでAndroidWearに表示が可能

• AndroidWearを意識しないとAndroidWear側が予期せぬデザインになり得る

setLargeIconによる背景表示

Actionアイコンがぼやける

Page 15: AndroidWear勉強会

AndroidWearを意識する設定

• AndroidWearに表示しない!• AndroidWearのみ表示する!• AndroidWearのみで行うAction!• 音声返信!• 選択返信!• Pages!• Stacking Notifications

Page 16: AndroidWear勉強会

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());

Page 17: AndroidWear勉強会

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());

Page 18: AndroidWear勉強会

通知の組み合わせ// 携帯側通知

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());

Page 19: AndroidWear勉強会

本来のGroupの利用方法• Stacking Notifications

Page 20: AndroidWear勉強会

本来のGroupの利用方法

Page 21: AndroidWear勉強会

WearableExtenderの利用

• NotificationCompat.WearableExtenderを利用することでAndroidWear用に色々と拡張が可能

• Group以外はこのWearableExtenderを利用する

Page 22: AndroidWear勉強会

WearableExtenderの利用• Android WearのみのAction

Page 23: AndroidWear勉強会

WearableExtenderの利用

Page 24: AndroidWear勉強会

WearableExtenderの利用• 音声返信

Page 25: AndroidWear勉強会

WearableExtenderの利用

Page 26: AndroidWear勉強会

WearableExtenderの利用• 音声返信の受け取り

Page 27: AndroidWear勉強会

WearableExtenderの利用• 音声 or 選択返信

strings.xml

Page 28: AndroidWear勉強会

WearableExtenderの利用• Pages

Page 29: AndroidWear勉強会

WearableExtenderの利用

Page 30: AndroidWear勉強会

まとめ• 通知をメインとするAndroidWearはNotificationを作成するだけで通知されるので特別な対応は必要ない!

• しかしAndroidWearを意識しないとAndroidWear側で思わぬ表示になることがある!

• 拡張はすごく簡単なのでNotificationを作成するときはAndroidWearを意識した作りにすること

Page 31: AndroidWear勉強会

ご清聴ありがとうございましたThreeColors 赤井 忠昭

@akai_t