如果FLAG_NO_CLEAR用不显示Android Wear通知 [英] Android Wear Notification is not displayed if FLAG_NO_CLEAR is used

查看:287
本文介绍了如果FLAG_NO_CLEAR用不显示Android Wear通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果标志 FLAG_NO_CLEAR 使用的通知得到的不可以上的Andr​​oid Wear显示出来。

If flag "FLAG_NO_CLEAR" is used the notification gets not displayed on the Android Wear.

有谁知道为什么或什么解决办法?我没有找到的文档中的任何信息。

Does anyone know why or any workaround? I didn't find any information in the documentation.

我需要我通知的标志 FLAG_NO_CLEAR ,并有操作按钮解雇,暂停等。!

I need the flag "FLAG_NO_CLEAR" on my notifications and have Action button for "dismiss", "snooze" etc.!

推荐答案

通知标志 FLAG_NO_CLEAR 基本上使得您的通知正在进行。从发布的手机正在进行的通知将不会显示可穿戴设备上。

Notification flag FLAG_NO_CLEAR basically makes your notification "ongoing". Ongoing notifications posted from phone will NOT be displayed on the wearable device.

您的两个解决方案,您的问题 - 他们都各有利弊。请仔细阅读下面的文字,并决定哪些解决方案,将解决你的情况更好:)

You have two solutions to your problem - both of them have advantages and disadvantages. Please read text below and decide which solution will solve your situation better:)

您可以使用的Andr​​oid Wear框架功能。它基本上创建张贴许多(分组)通知于可穿戴设备和手机一部摘要的通知。但是,使用这种机制还可以发布一个正在的通知您的电话和第二个通知仅在磨损。你会最终有一个正在在手机上的通知,你的穿戴式设备上的一个正常的通知。

You can make use of group feature of Android Wear framework. It's basically created to post many (grouped) notifications on wearable device and one summary notification on phone. But using this mechanism you can also post one ongoing notification on your phone and second notification only on wear. You will end up with one ongoing notification on your phone and one normal notification on your wearable device.

    final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    // This notification will be shown only on phone
    final NotificationCompat.Builder phoneNotificationBuilder = new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.ic_launcher)
        .setContentTitle("Title phone")
        .setContentText("Text phone")
        .setOngoing(true)
        .setOnlyAlertOnce(true)
        .setGroup("GROUP")
        .setGroupSummary(true);

    // This notification will be shown only on watch
    final NotificationCompat.Builder wearableNotificationBuilder = new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.ic_launcher)
        .setContentTitle("Title wearable")
        .setContentText("Text wearable")
        .setOngoing(false)
        .setOnlyAlertOnce(true)
        .setGroup("GROUP")
        .setGroupSummary(false);

    notificationManager.notify(0, phoneNotificationBuilder.build());
    notificationManager.notify(1, wearableNotificationBuilder.build());

此方法将允许你发布一个另类的通知只手表,让你的正在的通知上的电话。但(如前所述)值班通知不能正在 - 它是一个正常的通知。如果你真的想有一个真正的值班正在进行的通知你需要去第二个解决方案。

This method will allow you to post an "alternative" notification for watch only, keeping your ongoing notification on phone. But (as mentioned earlier) the notification on watch cannot be ongoing - it has to be a normal notification. If you really want to have a true ongoing notification on watch you'll need to go for second solution.

请阅读更多关于这里的分组(堆码)通知:
<一href="https://developer.android.com/training/wearables/notifications/stacks.html">https://developer.android.com/training/wearables/notifications/stacks.html

Please read more about grouping (stacking) notifications here:
https://developer.android.com/training/wearables/notifications/stacks.html

从手机正在进行的通知将不会显示在手表,但你可以创建你的Andr​​oid应用程序的可穿戴的一部分,直接在Android Wear发表您的通知。可以很容易地从那里发布一个持续通知,但由于是在电话它不会是相同的通知。您将需要同步他们两个设备之间。

Ongoing notifications from phone won't be shown on watch, but you can create wearable part of your Android application and post your notification directly on Android Wear. You can easily post an ongoing notification from there, but it won't be the same notification as is on phone. You will need to sync them between both devices.

请阅读更多关于 DataApi 这里:
<一href="https://developer.android.com/training/wearables/data-layer/index.html">https://developer.android.com/training/wearables/data-layer/index.html
<一href="https://developer.android.com/training/wearables/data-layer/data-items.html">https://developer.android.com/training/wearables/data-layer/data-items.html

Please read more about DataApi here:
https://developer.android.com/training/wearables/data-layer/index.html
https://developer.android.com/training/wearables/data-layer/data-items.html

您还可以看看我的文章,我已经发布了code演示如何使用一个在实践中 DataApi
<一href="http://stackoverflow.com/a/24896043/3827276">http://stackoverflow.com/a/24896043/3827276

You can also take a look at my post where I've posted a code demonstrating how to use a DataApi in practise:
http://stackoverflow.com/a/24896043/3827276

这篇关于如果FLAG_NO_CLEAR用不显示Android Wear通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆