Android Wear notification not showing

倖福魔咒の 提交于 2020-01-06 21:36:25

问题


Hi I'm writing an Android Wear app that allows the user to control a music player from their watch. I'm trying to do it with a notification with two action buttons. Below is the code that creates/updates the notification when the currently playing song changes, it is from OnDataChanged() from the WearableListenerService. The data arrives on the emulator as expected and the notification builder is constructed correctly, as I can see it in the debugger. Also the final log line is executed and I can see it in logcat, however the notification is not created on the emulator. Also all other notifications from other apps on my phone show up on emulator!

Any help greatly appreciated, thanks James!

for (DataEvent event : events) {
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            String path = event.getDataItem().getUri().getPath();
            if ("/playmusicremotedata".equals(path)) {
                // Get the data out of the event
                DataMapItem dataMapItem =
                        DataMapItem.fromDataItem(event.getDataItem());
                final String songTitle = dataMapItem.getDataMap().getString("songTitle");
                final String artist = dataMapItem.getDataMap().getString("artist");
                final String album = dataMapItem.getDataMap().getString("album");
                Asset asset = dataMapItem.getDataMap().getAsset("albumArt");

                Bitmap albumArt = loadBitmapFromAsset(asset);

                PendingIntent skipForwardPendInt = PendingIntent.getBroadcast(getApplicationContext(), 8, new Intent("net.jamyspex.remoteforgoogleplaymusic.SKIP_FORWARD"), PendingIntent.FLAG_UPDATE_CURRENT);
                PendingIntent playPausePendInt = PendingIntent.getBroadcast(getApplicationContext(), 7, new Intent("net.jamyspex.remoteforgoogleplaymusic.PLAY_PAUSE"), PendingIntent.FLAG_UPDATE_CURRENT);

                Notification.Action playPauseBut = new Notification.Action(R.drawable.play, "Pause/Play", playPausePendInt);
                Notification.Action nextBut = new Notification.Action(R.drawable.skip_forward, "Skip", skipForwardPendInt);

                // Create the ongoing notification
                Notification.Builder notificationBuilder =
                        new Notification.Builder(this)
                                .setSmallIcon(R.drawable.ic_launcher)
                                .setContentTitle(songTitle)
                                .setContentText(artist + " - " + album)
                                .setLargeIcon(albumArt)
                                .setOngoing(true)
                                .addAction(playPauseBut)
                                .addAction(nextBut);

                // Build the notification and show it
                NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
                Log.i(TAG, "Should have created notification");
            } else {
                Log.d(TAG, "Unrecognized path: " + path);
            }
        }
    }

回答1:


To make the solution more visible to users who may be affected with the same issue - i'm posting this as an answer.

REASON:

The reason was simple: app was muted (probably accidentally) on Android Wear device and this was preventing any notifications from appearing on watch.

While posting any ongoing notification from watch, there will be extra action added automatically. It is called "Mute app" and probably it was pressed in some point in time during development by accident.

Muted apps can be managed in the Android Wear companion app on Settings screen. This can be fairly hard to debug because any code is invoked without any error and there is also no logs in the LogCat about the fact that app is muted.

I hope that it will be helpful for other users that will search for the similar issue in the future:)




回答2:


I had the same issue, and sent couple of hours trying to solve it. In my case, I had the debug permanent notification (covering half the screen), and when my notification arrived to the watch, I couldn't see it. Only by swiping up all the notifications, I finally was able to see it, it was simply berried there.



来源:https://stackoverflow.com/questions/25645080/android-wear-notification-not-showing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!