可能重复:
Intent to launch the clock application on android如何启动android版本依赖闹钟?
我有一个显示的时间,如果一个就可以了水龙头,其与PendingIntent
启动com.android.alarmclock/.AlarmClock活动部件。这在Froyo之前效果很好,但使用Froyo时,我必须启动com.android.deskclock/.AlarmClock。所以我想要加入代码来检查班级是否存在并启动适当的活动/意图。这是我试过的,但它不起作用。
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);
它总是认为它是“Eclair”,因此在Froyo上失败。这是最好的方法,还是应该检查应用程序级别?我喜欢和班级生活一起工作。
我的语法正确吗? – mobibob 2010-08-11 22:41:15