Search code examples
androidandroid-widgetandroid-pendingintentandroid-appwidget

Android - How to perform additional action on app widget click


I have an app widget which when clicked opens a fragment.

val pendingIntent = NavDeepLinkBuilder(context)
        .setGraph(R.navigation.my_nav_graph)
        .setDestination(R.id.my_fragment)
        .createPendingIntent()
views.setOnClickPendingIntent(R.id.my_view, pendingIntent)

When the widget is clicked, along with opening the fragment, I need to send an analytics event.

I would like to avoid passing arguments to the pending intent and handling the sending of the analytics event inside my_fragment but rather do it in the widget somehow. Is this possible?


Solution

  • Is this possible?

    No. You have no means of having an app widget take action, other than via a PendingIntent.