限制可穿戴应用以接收移动应用通知?

时间:2014-08-12 06:23:16

标签: android android-notifications wear-os

我正在努力开发一款手机和手机可穿戴的应用程序。

对于此应用程序,我想在通知中添加一些操作。 E.g., Delete & Reply

Intent intent = new Intent(MyActivity.this,MyActivity.class);                 PendingIntent pendingIntent = PendingIntent.getActivity(MyActivity.this,0,intent,0);

            Intent nextIntent = new Intent(MyActivity.this,NextActivity.class);
            PendingIntent pendingIntent1 = PendingIntent.getActivity(MyActivity.this,0,nextIntent,1);

            NotificationCompat.Builder notifyCompat = new NotificationCompat.Builder(MyActivity.this).addAction(R.drawable.ic_launcher,"Reply",pendingIntent)
                    .addAction(R.drawable.ic_launcher,"Delete",pendingIntent1)
                    .setContentText("Content Text")
                    .setContentTitle("Title")
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentIntent(pendingIntent);

            Notification notification =notifyCompat.build();
            NotificationManager notifyManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
            notifyManager.notify(0,notification);

这就是我通过行动展示通知所做的。但是,我的问题是,当我点击移动通知中的ReplyDelete时,它启动的移动应用活动很好。但是,如果我点击Delete上的通知上的ReplyAndroid Wear按钮,则必须启动Wearable Activity而不是启动Mobile App Activity

有人可以帮我解决这个问题吗?如果我点击Android Wearable device上的操作,则必须启动Wearable App,但不能启动移动应用。

1 个答案:

答案 0 :(得分:1)

据我所知,无法在掌上电脑上创建的通知上设置磨损面活动。

但是,您可以通过以下方式获得相同的效果:

  1. 仅使用NotificationCompat.Builder.setLocalOnly
  2. 在掌上电脑上显示手持通知
  3. 创建掌上电脑通知时,还会使用Messaging API
  4. 向Wear发送消息
  5. 在您的Wear端代码中,当您收到此类消息时,请创建通知(使用您在掌上电脑中使用的相同通知API) - 这将在Wear设备上发出通知
  6. 与磨损面通知相关的任何操作都将在Wear设备上启动