Yes, see an example:
Improve your manifest.xml
<receiver android:name=".AppWidget" android:label="Caller" android:icon="@drawable/ic_launcher" > <intent-filter > <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> <action android:name="com.app.example.MyWidget.ACTION_WIDGET_CLICK_RECEIVER"/> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_provider" /> </receiver> <service android:name=".AppWidget$ToggleService" />
and update the AppWidgetProvider app :
public class MyWidget extends AppWidgetProvider { public static String ACTION_WIDGET_CLICK_RECEIVER = "ActionReceiverWidget"; public static int appid[]; public static RemoteViews rview; @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds){ updateWidgetState(context, ""); } @Override public void onReceive(Context paramContext, Intent paramIntent) { String str = paramIntent.getAction(); if (paramIntent.getAction().equals(ACTION_WIDGET_CLICK_RECEIVER)) { updateWidgetState(paramContext, str); } else { if ("android.appwidget.action.APPWIDGET_DELETED".equals(str)) { int i = paramIntent.getExtras().getInt("appWidgetId", 0); if (i == 0) { } else { int[] arrayOfInt = new int[1]; arrayOfInt[0] = i; onDeleted(paramContext, arrayOfInt); } } super.onReceive(paramContext, paramIntent); } } static void updateWidgetState(Context paramContext, String paramString) { RemoteViews localRemoteViews = buildUpdate(paramContext, paramString); ComponentName localComponentName = new ComponentName(paramContext, MyWidget.class); AppWidgetManager.getInstance(paramContext).updateAppWidget(localComponentName, localRemoteViews); } private static RemoteViews buildUpdate(Context paramContext, String paramString) {
source share