Notifications in Moto Display

倖福魔咒の 提交于 2019-12-12 03:28:44

问题


I created a notification and it works but not display in Moto Display when locked. I changed Priority, Category etc with no effects. I want this notification like messages or missed cals: moto display

This runs as a service:

PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.emblem2)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_help_red))
                    .setColor(getResources().getColor(R.color.colorFirst))
                    .setContentTitle(title)
                    .setContentText(location)
                    .setAutoCancel(true)
                    .setSound(defaultSoundUri)
                    .setShowWhen(true)
                    .setCategory(Notification.CATEGORY_ALARM)
                    .setLights(Color.YELLOW, 200, 200)
                    .setContentIntent(pendingIntent);

   notificationBuilder.setVibrate((sharedPreferences.getBoolean("notifications_new_message_vibrate", false) ? new long[]{0, 300, 200, 300} : new long[]{}));
            NotificationManager notificationManager =
                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(requestCode, notificationBuilder.build());

回答1:


As pointed out by Marcin, Moto Display doesn't work with vector drawable in notification small icon. I had the same problem and changing the small icon resolved the issue.

It's sad that such a nice feature as Moto Display doesn't have a documentation pointing that out.




回答2:


Notification notification = new Notification.Builder(context)
    // Show controls on lock screen even when user hides sensitive content.
    .setVisibility(Notification.VISIBILITY_PUBLIC)
    .setSmallIcon(R.drawable.ic_stat_player)
    // Add media control buttons that invoke intents in your media service
    .addAction(R.drawable.ic_prev, "Previous", prevPendingIntent) // #0
    .addAction(R.drawable.ic_pause, "Pause", pausePendingIntent)  // #1
    .addAction(R.drawable.ic_next, "Next", nextPendingIntent)     // #2
    // Apply the media style template
    .setStyle(new Notification.MediaStyle()
    .setShowActionsInCompactView(1 /* #1: pause button */)
    .setMediaSession(mMediaSession.getSessionToken())
    .setContentTitle("Wonderful music")
    .setContentText("My Awesome Band")
    .setLargeIcon(albumArtBitmap)
    .build();

That worked in my Moto Z, maybe only work in Media mode.



来源:https://stackoverflow.com/questions/36890362/notifications-in-moto-display

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