重複の可能性:
Android で時計アプリケーションを起動する意図
時間を表示するウィジェットがあり、それをタップすると、com.android.alarmclock/.AlarmClock アクティビティがPendingIntent
. これは 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);
常に「エクレア」だと思っているため、Froyo で失敗します。これが最善のアプローチですか、それともアプリケーション レベルを確認する必要がありますか? 私はクラスの存在を扱うことを好みます。