Intent to Launch the Clock Application on Android

Intent to launch the clock application on android

This code works for my clock widget.

PackageManager packageManager = context.getPackageManager();
Intent alarmClockIntent = new Intent(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"}

};

boolean foundClockImpl = false;

for(int i=0; i<clockImpls.length; i++) {
String vendor = clockImpls[i][0];
String packageName = clockImpls[i][1];
String className = clockImpls[i][2];
try {
ComponentName cn = new ComponentName(packageName, className);
ActivityInfo aInfo = 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) {
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, alarmClockIntent, 0);
// add pending intent to your component
// ....
}

In this way, I can run a default clock manager.

Intent to launch alarm settings (in clock application) on Android

Try the Following Code :

Intent i = new Intent(AlarmClock.ACTION_SET_ALARM); 
startActivity(i);

You can also set the alarm by doing something like below :

Intent i = new Intent(AlarmClock.ACTION_SET_ALARM); 
i.putExtra(AlarmClock.EXTRA_MESSAGE, "New Alarm");
i.putExtra(AlarmClock.EXTRA_HOUR, 11);
i.putExtra(AlarmClock.EXTRA_MINUTES, 20);
startActivity(i);

You will also need to have the following permission in the manifest :

<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>

For more information check the content here

Hope this helps!!!

Open device clock from button

Every manufacturer has a different clock implementation. You need to hardcode it like the answer here:

https://stackoverflow.com/a/4281243/1199931

AlarmClock intent says No apps can perform this action.

No apps can perform this action.

This happens when you don't have the required permission to set the alarm.

From AlarmClock reference:

Applications that wish to receive the ACTION_SET_ALARM and ACTION_SET_TIMER Intents should create an activity to handle the Intent that requires the permission com.android.alarm.permission.SET_ALARM.

Request the SET_ALARM permission:

<mainfest
...
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>

</manifest>

Start app at a specific time

You can do it with AlarmManager, heres a short example. First you need to set the alarm:

AlarmManager am = (AlarmManager) con.getSystemService(Context.ALARM_SERVICE);

Date futureDate = new Date(new Date().getTime() + 86400000);
futureDate.setHours(8);
futureDate.setMinutes(0);
futureDate.setSeconds(0);
Intent intent = new Intent(con, MyAppReciever.class);

PendingIntent sender = PendingIntent.getBroadcast(con, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
am.set(AlarmManager.RTC_WAKEUP, futureDate.getTimeInMillis(), sender);

Next, You need to create a reciever with some code to execute your application: (ie- starting your app):

public class MyAppReciever extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

startActivity(new Intent(context, MyAppMainActivity.class));
}
}

How to start the standard Stopwatch activity in Android (particularly Andorid Wear) programmatically?

Use @promanowicz 's answer like this:

    Intent intent = new Intent("com.google.android.wearable.action.STOPWATCH" );
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
startActivity(intent);


Related Topics



Leave a reply



Submit