0

我的问题是因为我在我的 Android Wear 模拟器中看不到背景,我用经过验证的图像声明 .setBackgroung 但是当我运行应用程序并向我发送通知时,背景没有显示。

有什么帮助吗?

public class NotificationService extends FirebaseMessagingService {
    public static final String TAG = "FIREBASE";
    public static final int NOTIFICATION_ID = 001;
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        //super.onMessageReceived(remoteMessage);
        Log.d(TAG, "From: " + remoteMessage.getFrom());
        Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
        enviarNotificacion(remoteMessage);
    }

    public void enviarNotificacion(RemoteMessage remoteMessage){
        Intent i = new Intent();
        i.setAction("TOQUE_ANIMAL");
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
        Uri sonido = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        NotificationCompat.Action action =
                new NotificationCompat.Action.Builder(R.drawable.ic_full_poke,
                        getString(R.string.texto_accion_toque), pendingIntent)
                .build();

        NotificationCompat.WearableExtender wearableExtender =
                new NotificationCompat.WearableExtender()
                .setHintHideIcon(true)
                .setBackground(BitmapFactory.decodeResource(getResources(),
                        R.drawable.bk_androidwear_notification))
                .setGravity(Gravity.CENTER_VERTICAL);

        NotificationCompat.Builder notificacion = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.notificacion)
                .setContentTitle("Notificacion")
                .setContentText(remoteMessage.getNotification().getBody())
                .setAutoCancel(true)
                .setSound(sonido)
                .setContentIntent(pendingIntent)
                .extend(wearableExtender.addAction(action))
                //.addAction(R.drawable.ic_full_poke, getString(R.string.texto_accion_toque), pendingIntent)
                ;

        NotificationManagerCompat notificationManager =
                NotificationManagerCompat.from(this);
        notificationManager.notify(NOTIFICATION_ID, notificacion.build());
    }
}
4

1 回答 1

0

您可以参考这篇SO 帖子。尝试使用setBackground(Bitmap)方法 fromWearableExtender而不是setLargeIcon(Bitmap). 您还可以查看本教程,了解如何为 Android Wear 创建表盘。

为 Android Wear 通知设置背景图片的附加参考:Android Wear 通知的背景图片

目前方形表盘的分辨率为 280x280,而圆形表盘的分辨率为 320x320(尽管其中一些显然会被截断)。

但是,Android Wear 默认为较大的图像实现了一种视差滚动,因此它可以非常轻松地处理较大的图像,甚至建议您这样做(请参阅this previous answer)。所以你真的不应该担心图像的大小,除非你试图创建一个具有特定交互区域的静态全屏图像来替代自定义 UI 元素(你可以这样做,我可能会补充说,虽然Google 建议您在手表上的每个屏幕上只有一个交互区域,以保持简单)。

如果你想看到一个很好的例子,将多个图像用于具有视差滚动的背景,我建议你查看 GridViewPager 示例项目,它可以在 API 级别 20 的可穿戴子文件夹中的 SDK 示例中找到。

希望这可以帮助!

于 2017-11-04T15:46:21.670 回答