I can't manage to set my own default complications on my own watchface (same app, same package). I'v used DefaultComplicationDataSourcePolicy for the complicationSlotManager :
sealed class ComplicationConfig(val id: Int, val supportedTypes: List<ComplicationType>) {
object Left : ComplicationConfig(
LEFT_COMPLICATION_ID,
listOf(
ComplicationType.SMALL_IMAGE,
ComplicationType.SHORT_TEXT
)
)
...
}
// Utility function that initializes default complication slots (left and right).
fun createComplicationSlotManager(
context: Context,
currentUserStyleRepository: CurrentUserStyleRepository,
drawableId: Int = DEFAULT_COMPLICATION_STYLE_DRAWABLE_ID
): ComplicationSlotsManager {
val defaultCanvasComplicationFactory =
CanvasComplicationFactory { watchState, listener ->
CanvasComplicationDrawable(
ComplicationDrawable.getDrawable(context, drawableId)!!,
watchState,
listener
)
}
val protectionComplicationComponentName = ComponentName(
context,
ProtectionStatusComplicationService::class.java
)
Log.d("ComplicationUtils",protectionComplicationComponentName.flattenToString())
...
val leftComplication = ComplicationSlot.createRoundRectComplicationSlotBuilder(
id = ComplicationConfig.Left.id,
canvasComplicationFactory = defaultCanvasComplicationFactory,
supportedTypes = ComplicationConfig.Left.supportedTypes,
defaultDataSourcePolicy = DefaultComplicationDataSourcePolicy(
protectionComplicationComponentName,
ComplicationType.SMALL_IMAGE,
SystemDataSources.DATA_SOURCE_STEP_COUNT,
ComplicationType.SHORT_TEXT
),
bounds = ComplicationSlotBounds(
RectF(
LEFT_COMPLICATION_LEFT_BOUND,
LEFT_AND_RIGHT_COMPLICATIONS_TOP_BOUND,
LEFT_COMPLICATION_RIGHT_BOUND,
LEFT_AND_RIGHT_COMPLICATIONS_BOTTOM_BOUND
)
)
).build()
...
return ComplicationSlotsManager(
listOf(leftComplication, rightComplication,topComplication,bottomComplication),
currentUserStyleRepository
)
}
And I set my watchface as safe in the manifest :
<!-- Required to act as a custom watch face. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.permission.PROVIDE_BACKGROUND" />
<!-- Required for complications to receive complication data and open the provider chooser. -->
<uses-permission android:name="com.google.android.wearable.permission.RECEIVE_COMPLICATION_DATA" />
<uses-permission android:name="com.google.android.wearable.permission.RECEIVE_COMPLICATION_DATA_PRIVILEGED" />
...
<application
...
<service
android:name=".complications.ProtectionStatusComplicationService"
android:exported="true"
android:icon="@drawable/shield_black_24dp"
android:label="Protection complication"
android:permission="com.google.android.wearable.permission.BIND_COMPLICATION_PROVIDER">
<intent-filter>
<action android:name="android.support.wearable.complications.ACTION_COMPLICATION_UPDATE_REQUEST" />
</intent-filter>
<meta-data
android:name="android.support.wearable.complications.UPDATE_PERIOD_SECONDS"
android:value="300" />
<meta-data
android:name="android.support.wearable.complications.SAFE_WATCH_FACES"
android:value="com.waryme.wearos/com.waryme.wearos.watchface.WaryMeWatchFaceService"/>
<meta-data
android:name="android.support.wearable.complications.SUPPORTED_TYPES"
android:value="SMALL_IMAGE" />
</service>
...
</application>
The step count is working as expected as fallback. I've logged the flattenToString() of the componentName and everything is good. According to the documentation, there could be 3 origins to this problem :
Am I missing something ? There is not much documentation on new androidx wearos libraries.
Thanks
EDIT : I know there is already an answer to this question, but it deals with the android.support.wearable library which is now deprecated.
After further reading of the documentation :
"primaryDataSourceDefaultType - The default ComplicationType if primaryDataSource is selected. Note Pre-R this will be ignored in favour of systemDataSourceFallbackDefaultType."
Assuming that Pre-R is Pre-Rendering, the default type of the system complication should be the same as the primary data source default type. So i changed it and this works :)
val leftComplication = ComplicationSlot.createRoundRectComplicationSlotBuilder(
id = ComplicationConfig.Left.id,
canvasComplicationFactory = defaultCanvasComplicationFactory,
supportedTypes = ComplicationConfig.Left.supportedTypes,
defaultDataSourcePolicy = DefaultComplicationDataSourcePolicy(
protectionComplicationComponentName,
ComplicationType.SMALL_IMAGE,
SystemDataSources.DATA_SOURCE_APP_SHORTCUT,
ComplicationType.SMALL_IMAGE
),
bounds = ComplicationSlotBounds(
RectF(
LEFT_COMPLICATION_LEFT_BOUND,
LEFT_AND_RIGHT_COMPLICATIONS_TOP_BOUND,
LEFT_COMPLICATION_RIGHT_BOUND,
LEFT_AND_RIGHT_COMPLICATIONS_BOTTOM_BOUND
)
)
).build()