androidwear-osandroid-wear-2.0android-wear-complication

How do I set the icon in the list of complications?


How do I set the icon that appears in the list of complications? Here's my complications code, and screenshots of my icon showing correctly in the list of apps, the small icon showing correctly at the top of the complications circle on the watch face, but no icon showing in the list of complications.

class MainComplicationService : SuspendingComplicationDataSourceService() {

override fun getPreviewData(type: ComplicationType): ComplicationData? {
    if (type != ComplicationType.SHORT_TEXT) {
        return null
    }
    return createAppShortcutComplication()
}

override suspend fun onComplicationRequest(request: ComplicationRequest): ComplicationData {
    return createAppShortcutComplication()
}

private fun createAppShortcutComplication(): ComplicationData {
    val newsIcon = Icon.createWithResource(this, R.drawable.news)

    val intent = Intent(this, MiniNewsWearActivity::class.java).apply {
        component = ComponentName(this@MainComplicationService, MiniNewsWearActivity::class.java)
    }
    val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)

    return ShortTextComplicationData.Builder(
        text = PlainComplicationText.Builder("NEWS").build(),
        contentDescription = ComplicationText.EMPTY,
    )
        .setMonochromaticImage(
            MonochromaticImage.Builder(
                newsIcon
            ).build()
        )
        .setTitle(PlainComplicationText.Builder("MINI").build())
        .setTapAction(pendingIntent)
        .build()
}

}

icon shows in app list tiny icon shows at top of complication on watch face no icon in list of complications


Solution

  • To set an icon for your complication in the list of complications in Wear OS, add the android:icon attribute in your complication service declaration in the AndroidManifest.xml:

    <service
      android:name=".MainComplicationService"
      android:icon="@drawable/your_icon" <!-- Your icon resource -->
      ...
    </service>
    

    enter image description here