【问题标题】:Restrict wearable app to receive mobile app notification?限制可穿戴应用接收移动应用通知?
【发布时间】:2014-08-12 06:23:15
【问题描述】:

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

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

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,而不是移动应用程序。

【问题讨论】:

    标签: android android-notifications wear-os


    【解决方案1】:

    据我所知,无法在手持设备上创建的通知上设置 Wear-side 活动。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多