1

So I am trying to update the background image of a Tile when it reloads, the ByteArray seems to get generated and there are no errors, but the background just remains black. If I apply non-dynamic resource directly, like from drawable it works fine. Code below

private const val ID_SONGART = "ic_songart"

 private fun playLayout(....)
.addContent (songImage(deviceParameters))
...


 private fun songImage(deviceParameters: DeviceParameters) = Image.Builder()
        .setResourceId(ID_SONGART)
        .setWidth(expand())
        .setHeight(expand())
        .build()


  override fun onResourcesRequest(...) = serviceScope.future{
.addIdToImageMapping(ID_SONGART, ImageResource.Builder()
                .setInlineResource(InlineImageResource.Builder()
                    .setData(albumImage)
                    .setWidthPx(200)
                    .setHeightPx(200)
                    .setFormat(ResourceBuilders.IMAGE_FORMAT_RGB_565)
                    .build()
                ).build()
            ).build()
    }

val albumImage: ByteArray
        get() {
            var data : ByteArray? = null
            if(mmr!!.embeddedPicture!=null){ data = mmr!!.embeddedPicture!!}

            if (data != null) {
                Log.d("SongIMAGE", data.size.toString())

                return data}
            else {
                var bitmap = BitmapFactory.decodeResource(
                    resources,
                    R.drawable.ic_app
                )
                val stream = ByteArrayOutputStream()
                bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);

                data = stream.toByteArray()
                Log.d("DefaultImage", data.size.toString())
                return data
            }
            }
Vicky P
  • 63
  • 6

1 Answers1

0

Use IMAGE_FORMAT_UNDEFINED.

See the comments on https://developer.android.com/reference/kotlin/androidx/wear/tiles/ResourceBuilders.InlineImageResource.Builder#setFormat(int)

    /**
     * Gets the format of the byte array data representing the image. May be left unspecified or
     * set to IMAGE_FORMAT_UNDEFINED in which case the platform will attempt to extract this
     * from the raw image data. If the platform does not support the format, the image will not
     * be decoded or displayed. Intended for testing purposes only.
     */
Yuri Schimke
  • 12,435
  • 3
  • 35
  • 69
  • So I tried this, I can load a initial image, but not able to update the image, does resource update happen on tile redraw/refresh, or need to be manually inducted ? – Vicky P Mar 08 '22 at 21:36
  • Are you bumping the resource version in both the tileRequest and resourceRequest? They must match and increment at the same time. I am guessing that when your tile service returns a higher version, it forces a request to get that version. – Yuri Schimke Mar 09 '22 at 07:30
  • I did not read this at the top, my bad. Appreciate the response // Updating this version triggers a new call to onResourcesRequest(). This is useful for dynamic // resources, the contents of which change even though their id stays the same (e.g. a graph). // In this sample, our resources are all fixed, so we use a constant value. – Vicky P Mar 09 '22 at 19:30