如何在Android Wear上触发意图时解除通知?

时间:2014-07-15 19:39:40

标签: android android-notifications wear-os

我目前正在移动设备上制作通知,并包含启动活动的特定服装意图。我希望一旦用户点击通知上的该按钮,通知就会消失,但我还没有让它工作。这是我的代码

Intent actionIntent = new Intent(context, LauncherService.class);
        PendingIntent pendingIntent = PendingIntent.getService(context, 0, actionIntent, PendingIntent.FLAG_CANCEL_CURRENT);


        // Create the action
        NotificationCompat.Action action =
                new NotificationCompat.Action.Builder(R.drawable.buzz_icon_white,
                        "Respond with Buzz", pendingIntent)
                        .build();

        // Build the notification and add the action with WearableExtender
        Notification notification =
                new NotificationCompat.Builder(context)
                        .setSmallIcon(R.drawable.buzz_icon_white)
                        .setContentTitle("Buzz")
                        .setContentText(name + ": " + message)
                        .extend(new WearableExtender().addAction(action))
                        .setAutoCancel(true)
                        .setPriority(1)
                        .setVibrate(pattern)
                        .build();

        NotificationManagerCompat notificationManager =
                NotificationManagerCompat.from(context);

        // Issue the notification with notification manager.
        notificationManager.notify(notificationId, notification);

0 个答案:

没有答案