Wear OS Complication setTapAction(): No Broadcast

60 views Asked by At

I'm creating a pending intent for complication tap like this:

    override fun onComplicationRequest(request: ComplicationRequest, listener: ComplicationRequestListener )  {

        class ComplicationBroadcastListener : BroadcastReceiver() {
            override fun onReceive(context: Context, intent: Intent) {
                Log.i(tag,"ComplicationBroadcastListener.onReceive()")
            }
        }

        val intent = Intent(this, ComplicationBroadcastListener::class.java)
        complicationPendingIntent = PendingIntent.getBroadcast(this, request.complicationInstanceId, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
        ...

I'm registering it with the complication like this:

    private fun createComplicationData(value: Float, absString: String, sense: String) =
        RangedValueComplicationData.Builder(
           ...
        ).setTapAction(
            complicationPendingIntent
        ).build()

complicationPendingIntent is definitely being initialised before the call to setTapAction, but onReceive is never called.

I know the structure of this code is poor; I'm just trying to simplify things in case this or context mean different things in different places.

Everything else with my project is working; eg, I can get the complication to update on schedule or on receipt of new data.

I'm aware of Exposing data to watch face complications on Wear OS, and my code was originally based on that. I can't get the code in that repo to work either.

1

There are 1 answers

0
Peter McLennan On

The receiver needs to be declared in AndroidManifest.xml.

In my case, the final version is:

<receiver android:name=".complication.ComplicationBroadcastListener" />