Android device opens Play Store instead of calendar app on intent url

I’m dispatching an intent url for android devices using python. This is the relevant code:

description = (
        u"Nom de l'établissement: {}\n"
        u"Identifiant Etablissement: {}\n"
        u"Fin des ventes: {}\n\n"
        u"Classe: {}\n"
        u"Carte d'accès: \n"
        u"        • Identifiant: {}\n"
        u"        • Mot de passe: {}\n"
        u"Accès au site: {}\n"
    ).format(org.name, org.id, org.sales_close_date, event.title,
             access_card.access_id, access_card.access_code,
             access_card.link)
encoded_description_google = description.replace(u'\n', u'%0A')
        if request.META.get('HTTP_USER_AGENT', '').lower().find('android') > -1:
            google_url = (
                u"intent://view?id=com.google.android.calendar&package=com.google.android.calendar&" 
                u"startDate={}&endDate={}&title={}&description={}"
                u"#Intent;scheme=https;package=com.google.android.calendar;end"
            ).format(
                start_date_str, end_date_str, cal_event_title, encoded_description_google
            )

I tried to open this url on my pixel using chrome, kiwi, brave and firefox but always play store opens instead of the calendar app. I tried the same with outlook and the result was the same, play store opened with the google calendar and outlook apps page.

I have tried adding explicit #Intent and package. I also used view but it didn’t help. I have also checked app settings, for calendar ‘Open by default’ is on. and for play store under open by default, in verified links I didn’t see any calendar links so I don’t know what am I doing wrong here.

Thankyou in advance.

The issue you’re facing stems from how Android handles intent URLs and app links. Even though you’ve specified #Intent;package=com.google.android.calendar;end, Android still resolves to the Play Store instead of directly opening the Calendar app because intent URLs can sometimes be overridden by default behaviors or misinterpretations of the intent by certain browsers.

Here’s an approach to resolve this:

Solution 1: Use ACTION_VIEW for Calendar Intents

Instead of using a raw intent URL, use the ACTION_VIEW intent to launch the Calendar app directly. The intent URL you’re using may not be correctly interpreted by browsers, but Android intents are more reliable when invoked programmatically. You can leverage Android Calendar’s ACTION_VIEW to open events properly.

Update your URL formatting to something like this:

google_url = (
    u"intent://#Intent;action=android.intent.action.VIEW;"
    u"data=content://com.android.calendar/time/{};"
    u"package=com.google.android.calendar;end"
).format(start_date_str)

This structure opens the Calendar app directly with a specific timestamp (you can pass a timestamp in milliseconds for the event). This approach minimizes the risk of being redirected to the Play Store.

Solution 2: Use geo: scheme for Location or event: for Calendar Links

Android supports certain well-known URI schemes for launching specific actions like maps, events, etc. For calendar events, you can try the following:

  1. Use the geo: scheme for events that might involve locations.
  2. Try the event: scheme (although this is less common) for events.

If you are passing an event that’s meant to be saved to the user’s calendar, use:

google_url = (
    u"intent://#Intent;action=android.intent.action.VIEW;"
    u"data=event:{};package=com.google.android.calendar;end"
).format(event_id)

Ensure that the event_id or other relevant identifiers are correct and replaceable by the Calendar app.

Solution 3: Test with Universal Links

Android apps (like Google Calendar) can also open URLs via app deep linking. You can craft a Google Calendar link using a standard web link that the Calendar app can understand:

google_url = (
    u"https://calendar.google.com/calendar/u/0/r/eventedit?"
    u"dates={}/{}&text={}&details={}&sf=true"
).format(
    start_date_str, end_date_str, cal_event_title, encoded_description_google
)

This link will open the event in a web-based version of Google Calendar, which will attempt to open it in the app if the app is installed. It’s also a more browser-friendly option and works across more environments.

Solution 4: Programmatically Trigger Intents on Android

If you’re dispatching intents within a Python web application, consider integrating a small Android component (using a companion Android app or WebView approach) that correctly handles the intents. This approach would bypass browser issues and directly launch intents for the Calendar.

Here’s an Android example (in Java or Kotlin) to handle this:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("content://com.android.calendar/time/"));
intent.setPackage("com.google.android.calendar");
startActivity(intent);

This method would directly open the Calendar app from your Python code using a trigger that sends this intent to the Android component.

Solution 5: Review AndroidManifest Settings

If you’re sure you’re hitting the right intent URLs but the Play Store still opens, double-check that your intent filter in the AndroidManifest.xml is correct for Calendar links (on Android) and that the app is set to handle the intents you’re trying to invoke.

In summary:

  1. Try using ACTION_VIEW intents and data=content://com.android.calendar/time/ URLs.
  2. Use a standard Google Calendar link with https://calendar.google.com to ensure proper deep linking.
  3. Consider adding an Android-specific handler if you’re dispatching from a server.

Let me know if the problem persists, and we can explore further based on the specific behavior of the browsers you’re testing on!