How To Launch Alarm Clock Screen Using Intent In Android?
In my application, i want to add alarm using my App. So i want to launch the add alarm screen of the phone directly from my App. So how to launch it using Intent?
Solution 1:
The following code starts an AlarmClock activity:
Intenti=newIntent(AlarmClock.ACTION_SET_ALARM);
i.putExtra(AlarmClock.EXTRA_MESSAGE, "New Alarm");
i.putExtra(AlarmClock.EXTRA_HOUR, 10);
i.putExtra(AlarmClock.EXTRA_MINUTES, 30);
startActivity(i);
You also need to use the following permission:
com.android.alarm.permission.SET_ALARM
See Android documentation here.
Solution 2:
You should make an Intent.
As the clock and alarm intent in android not clearly predefined, I used the following snippet code to do that:
PackageManagerpackageManager= context.getPackageManager();
IntentalarmClockIntent=newIntent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
// Verify clock implementation
String clockImpls[][] = {
{"HTC Alarm Clock", "com.htc.android.worldclock", "com.htc.android.worldclock.WorldClockTabControl" },
{"Standar Alarm Clock", "com.android.deskclock", "com.android.deskclock.AlarmClock"},
{"Froyo Nexus Alarm Clock", "com.google.android.deskclock", "com.android.deskclock.DeskClock"},
{"Moto Blur Alarm Clock", "com.motorola.blur.alarmclock", "com.motorola.blur.alarmclock.AlarmClock"},
{"Samsung Galaxy Clock", "com.sec.android.app.clockpackage","com.sec.android.app.clockpackage.ClockPackage"} ,
{"Sony Ericsson Xperia Z", "com.sonyericsson.organizer", "com.sonyericsson.organizer.Organizer_WorldClock" },
{"ASUS Tablets", "com.asus.deskclock", "com.asus.deskclock.DeskClock"}
};
booleanfoundClockImpl=false;
for(int i=0; i<clockImpls.length; i++) {
Stringvendor= clockImpls[i][0];
StringpackageName= clockImpls[i][1];
StringclassName= clockImpls[i][2];
try {
ComponentNamecn=newComponentName(packageName, className);
ActivityInfoaInfo= packageManager.getActivityInfo(cn, PackageManager.GET_META_DATA);
alarmClockIntent.setComponent(cn);
debug("Found " + vendor + " --> " + packageName + "/" + className);
foundClockImpl = true;
} catch (NameNotFoundException e) {
debug(vendor + " does not exists");
}
}
if (foundClockImpl) {
PendingIntentpendingIntent= PendingIntent.getActivity(context, 0, alarmClockIntent, 0);
// add pending intent to your component// ....
}
In this way, I can run a default clock or alarm manager. thanks to frusso.
Solution 3:
you can find Alarm App Intent through PackageManager.
see here.
Post a Comment for "How To Launch Alarm Clock Screen Using Intent In Android?"