I'm trying to write an Android Wear tile in Java. I finished my design using the TileUiClient. Previewing the Tile in an Activity works fine, but as soon as I try to view the tile normally it doesn't show anything anymore. It just displays the Tile Name and Icon. When I try to do the same in Kotlin it works fine. Does anybody know why that could be?
What it should look like:
What it looks like:
Here's my Java code:
package com.example.wear.tiles;
import static androidx.wear.tiles.ColorBuilders.argb;
import static androidx.wear.tiles.DimensionBuilders.degrees;
import static androidx.wear.tiles.DimensionBuilders.dp;
import static androidx.wear.tiles.DimensionBuilders.expand;
import androidx.annotation.NonNull;
import androidx.wear.tiles.ActionBuilders;
import androidx.wear.tiles.DimensionBuilders;
import androidx.wear.tiles.LayoutElementBuilders;
import androidx.wear.tiles.ModifiersBuilders;
import androidx.wear.tiles.RequestBuilders;
import androidx.wear.tiles.ResourceBuilders;
import androidx.wear.tiles.TileBuilders;
import androidx.wear.tiles.TileService;
import androidx.wear.tiles.TimelineBuilders;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
public class Tile extends TileService {
private static final String RESOURCES_VERSION = "1";
@NonNull
@Override
protected ListenableFuture<TileBuilders.Tile> onTileRequest(@NonNull RequestBuilders.TileRequest requestParams) {
return Futures.immediateFuture(new TileBuilders.Tile.Builder()
.setResourcesVersion(RESOURCES_VERSION)
//.setFreshnessIntervalMillis(60*1000*5) // 60 minutes
.setTimeline(new TimelineBuilders.Timeline.Builder()
.addTimelineEntry(new TimelineBuilders.TimelineEntry.Builder()
.setLayout(new LayoutElementBuilders.Layout.Builder()
.setRoot(new LayoutElementBuilders.Text.Builder().setText("Test").setModifiers(new ModifiersBuilders.Modifiers.Builder().setSemantics(new ModifiersBuilders.Semantics.Builder().setContentDescription("lol").build()).build()
).build()
).build()
).build()
).build()
).build()
);
}
@NonNull
@Override
protected ListenableFuture<ResourceBuilders.Resources> onResourcesRequest(@NonNull RequestBuilders.ResourcesRequest requestParams) {
return Futures.immediateFuture(new ResourceBuilders.Resources.Builder()
.setVersion("5")
.build());
}
}
I already found my mistake, I set two different Versions in .setVersion("5") in onResourcesRequest()
and onTileRequest()
. I initially changed them, because it seemed to solve an other problem(My pictures weren't rendered). Always set the same version number.