I'm trying to develop a widget which is a big miss on the samsung galaxy note 10.1: an S-pen note widget.
So far, i've just got the interface, and just one action (which is showing and hiding some buttons). on the emulator it shows everything just fine, but on my note10.1 it just sits on the screen, doing nothing. No crashes, but no functionality either. (nor does it show my toaster messages, which the emulator shows fine as well)
the receiver is mentioned in my manifest like so:
<receiver android:name="WidgetProvider">
<intent-filter >
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
<action android:name="org.Note.Widget.ACTION_widgetClick"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/note_widget"/>
</receiver>
i've tried many examples as guidelines for my Java code. This is what i have now:
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(CLK))
{
ToggleRibbon(context);
}
else
{
Toast.makeText(context, "action is: "+intent.getAction(), Toast.LENGTH_LONG).show();
super.onReceive(context, intent);
}
}
static void ToggleRibbon(Context context)
{
RemoteViews localRemoteViews = BuildUpdate(context);
ComponentName localComponentName = new ComponentName(context, WidgetProvider.class);
AppWidgetManager.getInstance(context).updateAppWidget(localComponentName, localRemoteViews);
}
private static RemoteViews BuildUpdate(Context context)
{
RemoteViews rv = new RemoteViews(context.getPackageName(),R.layout.widget_layout);
Intent active = new Intent(context, WidgetProvider.class);
active.setAction(CLK);
PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);
rv.setOnClickPendingIntent(R.id.note_ribbon, actionPendingIntent);
if(ShowRibbon)
{
ShowRibbon = false;
rv.setViewVisibility(R.id.note_ribbon, View.INVISIBLE);
Toast.makeText(context, "You clicked the Note!! (ribbon invisible)", Toast.LENGTH_LONG).show();
}
else
{
ShowRibbon = true;
rv.setViewVisibility(R.id.note_ribbon, View.VISIBLE);
Toast.makeText(context, "You clicked the Note!! (ribbon visible)", Toast.LENGTH_LONG).show();
}
return rv;
}
protected PendingIntent getPendingSelfIntent(Context context, String action)
{
Intent intent = new Intent(context, getClass());
intent.setAction(action);
return PendingIntent.getBroadcast(context, 0, intent, 0);
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for (int i = 0; i < appWidgetIds.length; ++i)
{
int appWidgetId = appWidgetIds[i];
//Intent intent = new Intent(context, WidgetProvider.class);
//intent.setAction("click");
//PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
remoteViews.setOnClickPendingIntent(R.id.widget_root, getPendingSelfIntent(context, CLK));
remoteViews.setOnClickPendingIntent(R.id.menu_btn, getPendingSelfIntent(context, "menu click"));
//remoteViews.setOnClickPendingIntent(R.id.widget_root, pendingIntent);
//remoteViews.setOnClickPendingIntent(R.id.menu_btn, pendingIntent);
// update widget
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
My guess is that it will be something stupid i forgot, but i realy hope someone can help me get my widget to do something more than just sit there :P (toaster messages only would help a lot already!)
Thanks in advance ;)