0

Hello i have a small problem i need some help with. I have a clock widget that can be placed on the phone which works fine. The problem i am having is when on click i want it to open the alarm clock fucnction within the phone.

I have this code which seems to work fine on the emulator but when i test it on my HTC the on click function seems to do nothing.

 public class Widget extends AppWidgetProvider {
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {

        RemoteViews views = new RemoteViews(context.getPackageName(),
                R.layout.widget);

        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.Widget, pendingIntent);

        AppWidgetManager.getInstance(context).updateAppWidget(intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS), views);
    }
}
 }
Matt
  • 1,747
  • 8
  • 33
  • 58

1 Answers1

0

There doesn't seem to be a standard alarm clock widget in android. I've seen code on the web that distinguishes between various manufacturers to do exactly what you want.

A search on SO turns up this for example: Intent to launch the clock application on android

Community
  • 1
  • 1
Thorsten Dittmar
  • 55,956
  • 8
  • 91
  • 139
  • I have tried using that but cannot seem where to add it into my code without throwing erros out? – Matt Nov 28 '11 at 10:21