I am writing my first application and am trying to get my widget to
load a different image when it is added to the home screen based on
the state of the notification volume. It is detecting the
notification state fine and the proper Toast messages appear when I
add the widget, but I'm not getting any icon. I just get an empty
button. I'm using the same code to change the icon in my onReceive()
method to do other things and that works fine. Is this the proper way
to accomplish that? Any suggestions as to what I'm doing wrong would
be appreciated!
@Override
public void onEnabled(Context context)
{
AudioManager aManager = (AudioManager)
context.getSystemService(Context.AUDIO_SERVICE);
RemoteViews remoteViews = new
RemoteViews(context.getPackageName(),
R.layout.widget);
if (aManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION)
==
0)
{
Toast.makeText(context, "Off",
Toast.LENGTH_SHORT).show();
remoteViews.setImageViewResource(R.id.button,
R.drawable.off);
ComponentName cn = new ComponentName(context,
SilenceWidget.class);
AppWidgetManager.getInstance(context).updateAppWidget(cn,
remoteViews);
}
else
{
Toast.makeText(context, "On",
Toast.LENGTH_SHORT).show();
remoteViews.setImageViewResource(R.id.button,
R.drawable.on);
ComponentName cn = new ComponentName(context,
SilenceWidget.class);
AppWidgetManager.getInstance(context).updateAppWidget(cn,
remoteViews);
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en