I have a widget that displays the time and if one taps on it, it launches the com.android.alarmclock/.AlarmClock activity with an PendingIntent
. This works great before-Froyo, but with Froyo, I have to launch the com.android.deskclock/.AlarmClock. So I want to put in code that checks for the class existence and launch the appropriate activity/intent. Here is what I tried, but it does not work.
Intent alarmIntent = new Intent();
try {
if (Class.forName("com.android.deskclock.AlarmClock") != null) {
Log.i(TAG, "setting deskclock alarm -- must be Froyo!");
alarmIntent.setClassName("com.android.deskclock",
"com.android.deskclock.AlarmClock");
}
} catch (ClassNotFoundException e) {
Log.i(TAG, "setting alarmclock alarm -- must be Eclair!");
alarmIntent.setClassName("com.android.alarmclock",
"com.android.alarmclock.AlarmClock");
}
PendingIntent pendingIntent = PendingIntent.getActivity(context, REQUEST_UPDATE_TIME_NOW,
alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.text_timeofday, pendingIntent);
It always thinks it is "Eclair" and therefore fails on Froyo. Is this the best approach, or should I check the application-level? I prefer to work with the class existence.