【问题标题】:Dismiss Android Wear notification after action and no small icon操作后关闭 Android Wear 通知且没有小图标
【发布时间】: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


【解决方案1】:

关闭通知

notificationManager.cancel(notificationId)

在 Android Wear 中,通知图标是显示您的 APP 图标

AndroidManifest.xml

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"  <--- change this
    android:label="@string/app_name"
    android:theme="@style/AppTheme">

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-01
  • 1970-01-01
  • 2011-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多