简体   繁体   中英

Dismiss Android Wear notification after action and no small icon

Two questions:

  • How can I dismiss notification after user pressed action button
  • Small icon is not display always the green Android logo

My code:

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);

Dismiss notification

notificationManager.cancel(notificationId)

In Android Wear, Notification icon is display your APP icon

AndroidManifest.xml

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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