AndroidWear勉強会
-
Upload
tadaaki-akai -
Category
Software
-
view
1.206 -
download
4
description
Transcript of AndroidWear勉強会
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 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());
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());
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());
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追加
Android のNotificationIntent の発行とAction追加
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アイコンがぼやける
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