views:

19

answers:

0

I have used analogclock widget in XML while running the program onUpdate is not called. Is there any way to get control for drawing a bitmap/text on the widget.?

Can I update the widget in onReceive()?

My code goes like this...

public class ClockWidget extends AppWidgetProvider {



@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds)
{

    Log.d("run", "reached onupdate");
    super.onUpdate(context, appWidgetManager, appWidgetIds);
}





@Override
public void onReceive(Context context, Intent intent)
{
    Log.d("run", "reached Receive");
    String action = intent.getAction();
    if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action))
    {
        Log.d("run", "reached Receive");
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);

        Intent AlarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(new ComponentName("com.android.alarmclock", "com.android.alarmclock.AlarmClock"));
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, AlarmClockIntent, 0);
        views.setOnClickPendingIntent(R.id.relLayOut, pendingIntent);

        AppWidgetManager.getInstance(context).updateAppWidget(intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS), views);
    }
}

}

and the XML is like this

<?xml version="1.0" encoding="utf-8"?>

    <AnalogClock android:id="@+id/AnalogClock01"
 android:layout_width="115sp"
 android:dial="@drawable/clockface"
 android:layout_height="160sp" />