【发布时间】:2015-05-03 13:44:12
【问题描述】:
两个问题:
- 如何在用户按下操作按钮后关闭通知
- 小图标并不总是显示绿色的 Android 徽标
我的代码:
int notificationId = 001;
// Reply action
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("google.navigation:///?q=48.193479,11.569957&mode=w"));
PendingIntent actionPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// Create the action
Notification.Action action =
new Notification.Action.Builder(R.drawable.map_white,
"Open Navigation", actionPendingIntent)
.build();
Notification notification =
new Notification.Builder(getApplicationContext())
.setPriority(Notification.PRIORITY_HIGH)
.setSmallIcon(R.drawable.map_icon_notification)
.setContentTitle("Navigation Notification")
.setContentText("Please swipe left to start navigation.")
.extend(new Notification.WearableExtender().addAction(action).setBackground(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.background_notification)))
.setAutoCancel(true)
.build();
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(ListenerService.this);
notificationManager.notify(notificationId, notification);
【问题讨论】:
-
一般来说,如果您有两个单独的问题,最好将它们分别发布在 Stack Overflow 上。它可以帮助其他人在未来更轻松地找到它们:-)
-
@stkent 我记住了!谢谢!
标签: android android-notifications wear-os