• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to pass extras informations with setOnClickPendingIntent ?

kujaff

Lurker
Jul 18, 2010
4
0
Hi

I have a widget, with a provider :

PHP:
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        final int N = appWidgetIds.length;
        for (int i=0; i<N; i++) {
            int appWidgetId = appWidgetIds[i];
            Intent intent = new Intent(context, RingModeService.class);
            intent.putExtra("RingModeAppWidgetConfig." + AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);
            
            // THIS IS FOR TESTING EXTRAS
            try {
                pendingIntent.send(context, 0, intent);
            } catch (CanceledException e) {
                
            }

            RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.ringmode_widget);
            views.setOnClickPendingIntent(R.id.ringmode_widget_icon, pendingIntent);
            appWidgetManager.updateAppWidget(appWidgetId, views);
        }
}
and the onStart of my service :

PHP:
public void onStart(Intent intent, int startId) {
     intent.getIntExtra("RingModeAppWidgetConfig." + AppWidgetManager.EXTRA_APPWIDGET_ID, 0)
}
Problem :

when i call pendingIntent.send(context, 0, intent); in onUpdate, getIntExtra in the service return the good ID. but when service is called by a click on my widget, extras of the intent are empty, i don't have anything :thinking:
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones