首页 文章

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

提问于
浏览
0

我正在尝试开发一款移动和可穿戴应用 .

对于此应用程序,我想在通知中添加一些操作 . 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 时,它启动移动应用程序活动就可以了 . 但是,如果我在 Android Wear 上的通知上单击 DeleteReply 按钮,则必须启动 Wearable Activity 而不是启动 Mobile App Activity .

有人可以帮助我如何实现这一目标吗?如果我点击 Android Wearable device 上的某个操作,那么它必须启动 Wearable App 但不是移动应用 .

1 回答

  • 1

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

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

    • 仅使用NotificationCompat.Builder.setLocalOnly在掌上电脑上显示手持通知

    • 创建掌上电脑通知时,还要使用Messaging API向Wear发送消息

    • 在您的Wear端代码中,当您收到此类消息时,请创建通知(使用您在掌上电脑中使用的相同通知API) - 这将在Wear设备上发出通知

    • 与磨损侧通知相关的任何操作都将在Wear设备上启动

相关问题