I tried to create clickable widget on android. I was looking for solution on this site and I found it, but finally this widget is working only on the emulator - not on real phone. This is my code:
AppWidgetProvider:
public static String WIDGET_BUTTON = "apps.test.widget.WIDGET_BUTTON";
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.main);
Intent clickIntent = new Intent(WIDGET_BUTTON);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.imageView1, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds, views);
}
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if (WIDGET_BUTTON.equals(intent.getAction())) {
Toast.makeText(context, "asdfsdgdasfg", Toast.LENGTH_SHORT).show();
}
}
Manifest:
<application
android:allowBackup="true"
android:icon="@drawable/image"
android:label="@string/app_name" >
<receiver
android:name=".Widget"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="apps.test.widget.WIDGET_BUTTON"/>
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/test_widget_provider" />
</receiver>
</application>
Toast is showing up on the emulator but not on phone.