The code below is what I used in one of my recent apps:
private void startAlarmActivity() { PackageManager packageManager = getPackageManager(); Intent alarmClockIntent = new Intent(Intent.ACTION_MAIN) .addCategory(Intent.CATEGORY_LAUNCHER); // Verify clock implementation String clockImpls[][] = { { "HTC", "com.htc.android.worldclock", "com.htc.android.worldclock.WorldClockTabControl" }, { "Standard", "com.android.deskclock", "com.android.deskclock.AlarmClock" }, { "Froyo", "com.google.android.deskclock", "com.android.deskclock.DeskClock" }, { "Motorola", "com.motorola.blur.alarmclock", "com.motorola.blur.alarmclock.AlarmClock" }, { "Sony Ericsson", "com.sonyericsson.alarm", "com.sonyericsson.alarm.Alarm" }, { "Samsung", "com.sec.android.app.clockpackage", "com.sec.android.app.clockpackage.ClockPackage" } }; boolean foundClockImpl = false; for (int i = 0; i < clockImpls.length; i++) { String packageName = clockImpls[i][1]; String className = clockImpls[i][2]; try { ComponentName cn = new ComponentName(packageName, className); packageManager.getActivityInfo(cn, PackageManager.GET_META_DATA); alarmClockIntent.setComponent(cn); foundClockImpl = true; break; } catch (NameNotFoundException e) { Log.d("ADNAN", "Alarm clock "+clockImpls[i][0]+" not found"); } } if (foundClockImpl) { alarmClockIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(alarmClockIntent); } }
No comments:
Post a Comment