【问题标题】:I can't see the background of my Android Wear Emulator我看不到我的 Android Wear 模拟器的背景
【发布时间】:2017-11-03 14:49:36
【问题描述】:

我的问题是我在我的 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());
    }
}

【问题讨论】:

    标签: android android-studio android-emulator wear-os wearables


    【解决方案1】:

    您可以参考这个SO post。尝试使用WearableExtender 中的setBackground(Bitmap) 方法而不是setLargeIcon(Bitmap)。您也可以查看tutorial,了解如何为 Android Wear 创建表盘。

    为 Android Wear 通知设置背景图片的其他参考:Background image for android wear notification

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

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

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

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多