Skip to content Skip to sidebar Skip to footer

Android - Communications Between A Widget And Its App

I have a widget that shows various images with text below, and the same UI set up in the app itself. I want the widget to not only be able to open the app, but to open the app bas

Solution 1:

Let's say there are several images in the ui, you can set different Intent for each image, and these intents each will target a different activity.

This post: http://rxwen.blogspot.com/2012/10/communication-between-android-widget.html may give you some hints.


Solution 2:

Add this code in widget.java file to launch your application. instead of MainActivity.class you can call any activity

static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
                                    int appWidgetId) {

        RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.mywidget_provider);
        Intent openApp = new Intent(context,MainActivity.class);
        PendingIntent pIntent = PendingIntent.getActivity(context,0,openApp,0);

        views.setOnClickPendingIntent(R.id.btnOpenApp,pIntent);
        appWidgetManager.updateAppWidget(appWidgetId,views);
}

Post a Comment for "Android - Communications Between A Widget And Its App"