• Android Wear预览版——尝鲜


    前两天Google推出了Android Wear的SDK,稍稍的瞧了一眼,发现这个预览版的功能还是比较简单的,只有一个通知转发的功能,不过就这么一个功能,带来的效果却是Very Good~~

    功能:发送Notifications到可穿戴设备

      • 支持通知分页
      • 支持Action响应
      • 支持通知分组

    未来的功能

    • 自定义UI, 实现直接在可穿戴设备上运行Activity
    • 通过API和RPC实现的手机和可穿戴设备间数据传送
    • 控制传感器,实时获取和显示传感器数据
    • 语音操作

    看来Google是等不及了,实现了五分之一的预期功能就抢着发布预览版了,不过能给大家先尝尝鲜确实很happy。在测试中发现,其实可以在Wear系统上安装正常的Android应用——这么。。。是不是可以直接整成手机了。。

    整个效果图ing~

    关于安装参考:http://developer.android.com/wear/preview/start.html

    很容易:

    • 更新SDK Manager
    • 建立Android Wear ARM EABI v7a 的AVD
    • 手机端安装Android Wear Preview App
      •   注:仅支持4.3以上
    • 在App中设置允许Notification access
    • 用USB连接手机到电脑,在终端映射端口5601
      •   adb -d forward tcp:5601 tcp:5601

    PS:手机端为模拟器映射方法

    •   用telnet连接手机端 如:telnet localhost 5556
    •   映射手机端口到本地端口-->redir add tcp:5601:5601

    相关API

    • android.preview.support.v4.app.NotificationManagerCompat (向后兼容的NotificationManager类)
    • android.preview.support.wearable.notifications.*
      •   WearableNotifications (可穿戴设备类型的通知)
        •     Action (支持可穿戴类型通知的Action)
      •   RemoteInput (远程输入类,可穿戴设备输入)
     1 int notificationId = 001; //通知id
     2 Intent replyIntent = new Intent(this, ReplyActivity.class); // 响应Action, 可以启动Activity、Service或者Broadcast
     3 PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, replyIntent, 0);
     4 RemoteInput remoteInput = new RemoteInput.Builder("key")//响应输入,“key”为返回Intent的Extra的Key值
     5                                                               .setLabel("Select") //输入页标题
     6                                    .setChoices(String[])//输入可选项
     7                                    .build();
     8 Action replyAction = new Action.Builder(R.drawable, //WearableNotifications.Action.Builder 对应可穿戴设备的Action类
     9                                     "Reply", pendingIntent) //对应pendingIntent
    10                                     .addRemoteInput(remoteInput)
    11                                     .build();
    12 
    13 NotificationCompat.Builder notificationBuilder =  new NotificationCompat.Builder(mContext) //标准通知创建
    14                 .setContentTitle(title).setContentText(subject).setSmallIcon(R.drawable).setStyle(style)
    15  .setLargeIcon(bitmap) // 设置可穿戴设备显示的背景图
    16  .setContentIntent(pendingIntent) //可穿戴设备左滑,有默认Open操作,对应手机端的点击通知
    17  .addAction(R.drawable, String, pendingIntent); //增加一个操作,可加多个
    18 Notification notification = new WearableNotifications.Builder(notificationBuilder)   //创建可穿戴类通知, 为通知增加可穿戴设备新特性,必须与兼容包里的NotificationManager对应,否则无效
    19                 .setHintHideIcon(true) //隐藏应用图标
    20               .addPages(notificationPages) //增加Notification页
    21               .addAction(replyAction)    //对应上页,pendingIntent可操作项
    22 .addRemoteInputForContentIntent(replyAction) //可为ContentIntent替换默认的Open操作
    23 .setGroup(GROUP_KEY, WearableNotifications.GROUP_ORDER_SUMMARY) //为通知分组
    24 .setLocalOnly(true) //可设置只在本地显示
    25 .setMinPriority() //设置只在可穿戴设备上显示通知
    26               .build();
    27 NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);//获得Manager
    28 notificationManager.notify(notificationId, notificationBuilder.build());//发送通知

    API中拥有的几点特性都在上面代码里了,看不同效果请注释掉相应的设置。

  • 相关阅读:
    mac下webstorm自动编译typescript配置
    [转]Golang 中使用 JSON 的小技巧
    Element-UI 框架 el-scrollbar 组件
    npm读取config配置的优先级(yarn同理)
    win, mac, linux 默认系统缓存目录
    yum离线安装rpm包
    常见网络摄像机(摄像头)的端口及RTSP地址
    sed命令在mac和linux下的区别
    canvas笔记备忘
    shell脚本:批量修改文件名(添加/删除文件名中字符)
  • 原文地址:https://www.cnblogs.com/Pitty/p/3620556.html
Copyright © 2020-2023  润新知