0

我出于一些充分的理由在可穿戴设备上创建通知。由于我在移动设备上也显示了相同的内容,因此我需要同步删除通知。我观察到删除可穿戴设备和移动设备上的通知之间需要很长时间。起初我以为这与我使用的 DataAPI 有关,但我错了。删除意图的调用延迟很大,我不知道为什么。

在这里检查我的(清理过的)logcat 输出:

-- Wearable --
09:31:45.007 D/FitnessWatchface﹕ onVisibilityChanged : false
09:31:48.008 D/FitnessWatchface﹕ onVisibilityChanged : true
09:31:52.929 D/NotificationHelper﹕ Got action my.package.name.NOTIFICATION_DISCARDED
09:31:52.963 D/DataAPI﹕ Discard message send out to mobile
09:31:53.052 I/art﹕ WaitForGcToComplete blocked for 10.697ms for cause DisableMovingGc
09:31:53.071 D/DataAPI﹕ Wrote successful wear://1d8...5d7/notification/discard/2
09:31:53.073 D/DataLayerListener﹕ onDataChanged invoked

-- Smartphone --
09:31:53.075 D/DataLayerListener﹕ onMessageReceived: /notification/discard/2
09:31:53.075 D/DataLayerListener﹕ Forwarding DISCARD event to receiver...
09:31:53.075 D/Broadcast﹕ Got DISCARD for type 
09:31:53.075 D/NotificationHelper﹕ removeNotification()
09:31:53.165 D/DataLayerListener﹕ onDataChanged: wear://1d8...5d7/notification/discard/2
09:31:53.165 D/DataLayerListener﹕ Forwarding DISCARD event to receiver...
09:31:53.165 D/Broadcast﹕ Got DISCARD for type 
09:31:53.165 D/NotificationHelper﹕ removeNotification()

如您所见,表盘变得可见,大约需要 5 秒才能写入下一个 logcat 输出。

这是我为删除创建待处理意图的代码:

Intent intent = new Intent(context, NotificationHelper.class);
intent.setAction(NOTIFICATION_DISCARDED);
intent.putExtra(NOTIFICATION_INPUT_TYPE, type);
// prevents that the intent is overridden by the system with similar ones
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
return PendingIntent.getBroadcast(context, 6434, intent, PendingIntent.FLAG_ONE_SHOT);

你看到解释延迟的东西了吗?如果您想查看更多代码,请发表评论。

在提交这个问题之前,我只是对时间进行了比较,例如 WhatsApp。延迟也有,但似乎要快一点(但我没有测量它)。

4

1 回答 1

0

在 Android Wear 中关闭通知后,用户有 5 秒时间撤消该操作。如果您在关闭通知后向下滑动,它应该会显示一个撤消按钮。

于 2015-07-07T00:12:58.603 回答