简体   繁体   English

前台服务和Android Wear通知

[英]Foreground service and Android Wear notification

I have a Foreground Service that displays a status notification on the phone about the connection and some server data. 我有一个前台服务,该服务在电话上显示有关连接和某些服务器数据的状态通知。
I would like to show this info in the Android Wear device too, but i get one notification on the Wear device and 2 in the Android Phone. 我也想在Android Wear设备上显示此信息,但是我在Wear设备上收到一条通知,在Android Phone中收到2条通知。
This is the code: 这是代码:

public void createNotification(String text)
{
    int notificationId = 001;
    Notification not=null;

    Intent viewIntent = new Intent(this, MainActivity.class);
    PendingIntent viewPendingIntent =
            PendingIntent.getActivity(this, 0, viewIntent, 0);

    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle("Title")
                    .setContentText(text)
                    .setContentIntent(viewPendingIntent);



    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    not=notificationBuilder.build();
    notificationManager.notify(notificationId,not );
    startForeground(NOTIFICATION_ID, not);
}

In order to achieve this you will have to build a wear app which creates and shows the notification on the wearable. 为了实现这一点,您将必须构建一个可穿戴应用程序,该应用程序会在可穿戴设备上创建并显示通知。 Use the Wearable Data Layer API to send the content from your mobile to the wearable. 使用可穿戴数据层API将内容从您的手机发送到可穿戴设备。 Then you can show a notification containing the information directly on the wearable. 然后,您可以直接在可穿戴设备上显示包含信息的通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM