jmazin
jmazin

Reputation: 1377

How can I launch the Moto 360 'Agenda' app (or any other calendar) from a watchface?

I'm brand new to android (let alone android wear) development and I have something like this in my watchface tap handler:

Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
builder.appendPath("time");
ContentUris.appendId(builder, startMillis);
Intent intent = new Intent(Intent.ACTION_VIEW)
    .setData(builder.build())
    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

On tap I get the No application can handle this action message.

Of course, the Agenda app is there, and I have installed a few other calendar apps (eg google).

Upvotes: 0

Views: 360

Answers (3)

Ludwig van B.
Ludwig van B.

Reputation: 11

I followed String's suggestion and managed to get it working by calling:

Intent calendarIntent = new Intent();
calendarIntent.setAction(Intent.ACTION_MAIN);
calendarIntent.addCategory(Intent.CATEGORY_APP_CALENDAR);
startActivity(calendarIntent);

Upvotes: 1

paracycle
paracycle

Reputation: 7850

String's answer is definitely the more correct way of doing this in general. However, on a Moto360, I looked into what activity is being launched when the Agenda app is started. Starting from that I've managed to get the code:

ComponentName component = new ComponentName("com.google.android.wearable.app", "com.google.android.clockwork.home.calendar.AgendaActivity");
Intent intent = new Intent()
    .setComponent(component)
    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

to work to achieve what you are after.

WARNING: Launching any app this way is actually asking for trouble. Just note that the other application can change package names, activities can get renamed, etc which would all break this way of launching activities. However, failing a good way to launch the app you want with generic Intents, this might be one way to do it.

Upvotes: 1

Sterling
Sterling

Reputation: 6635

It sounds like the Wear components of these apps don't support the standard Calendar Intent in the way that their handheld components (presumably) do. Most likely the developers just haven't thought ahead sufficiently to anticipate that others (like yourself) would want to do this on the watch.

You can check this specifically by pulling the respective APKs off the watch using adb, then running apktool on them to extract a human-readable manifest. Looking at what <intent> elements they include should tell you both:

  • If they do support the standard CalendarContract, in which case there's something wrong with how you're calling it.
  • If not, perhaps they publish some other Intent that you can call.

Upvotes: 2

Related Questions