【问题标题】:Recognize notifications from particular handheld app on wear device识别来自穿戴设备上特定手持应用程序的通知
【发布时间】:2014-11-19 00:57:28
【问题描述】:

我想知道是否可以对可穿戴设备上的特定手持应用程序的通知表单进行特殊行为。

我想要实现的是来自手持设备的通知,该通知连接到可穿戴设备以启动我的自定义应用程序(在穿戴设备上),而穿戴设备本身没有通知。问题是,这必须是一个通知(来自手机),并且它来自特定的应用程序(来自手机应用程序)。

这可能吗,或者您有更好的想法来解决这个问题?

【问题讨论】:

    标签: android notifications wear-os


    【解决方案1】:
    1. 使用 MessageApi 方法 Wearable.MessageApi.sendMessage() 从 Handheld 中的任何活动或服务向 Wear 发送消息(以提示 Wear 设备启动活动或服务)

      Wearable.MessageApi.sendMessage(googleApiClient, nodeId, SOME_UNIQUE_MESSAGE_PATH, MY_MESSAGE);
      
    2. 通过覆盖 Wear 设备中 WearableListenerService 类中的 onMessageReceived 函数来接收消息

      @Override
      public void onMessageReceived(MessageEvent messageEvent) {
      
      if (messageEvent.getPath().equals(SOME_UNIQUE_MESSAGE_PATH)) {
        final String message = new String(messageEvent.getData());
        Log.v(TAG, "From Phone - message path : " + messageEvent.getPath());
        Log.v(TAG, "From Phone - message : " + message);
        if(message == MY_MESSAGE){
            //call your activity or service here
      }
      }
      else {
        super.onMessageReceived(messageEvent);
      }
      

      }

    3. 通过onMessageReceived函数在Wear设备中启动所需的Activity或Service

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多