I'm not sure what's wrong with your code and I'm kind of guessing
here...but:

- onEnabled() is only called when the FIRST widget is created. So, if you
try to add a second widget to the homescreen this method will not be called.
Also, maybe, when onEnabled() is called the widget actually does not exist
yet? So your updateAppWidget() is probably doing nothing.

- try moving this piece of code to the onUpdate() method of your widget
provider (which is called whenever the widget requires an update).

- are you setting other RemoteViews objects in your onReceive() method?



Yuvi

On Sat, Oct 16, 2010 at 7:40 PM, Benaiah <benaiahhe...@gmail.com> wrote:

> 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 android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en




-- 
YuviDroid
Check out Launch-X <http://android.yuvalsharon.net/launchx.php> (a widget to
quickly access your favorite apps and contacts!)
http://android.yuvalsharon.net

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to