Finding the GMail URL scheme for iOS

Posted: 29 Jan 2013

Tagged:iOS

In iOS, URL schemes are the standard way to open one application from another as
well as to pass data to the newly open app. While the method is standard, the
schemes used by various applications are not, so it tends to be a bit of an
adventure determining how to launch applications made by third parties. The
good people at HandleOpenURL.com are doing their
best to catalogue apps but there are many gaps including, notably for me, GMail.
It’s clear that such a scheme must exist because the various Google apps can not
only launch GMail but can insert information into a new message being composed.

Determining the url prefix was relatively simple, it follows the scheme used by
most Google products, and is googlegmail://. The trick is making it do more
than just open the GMail app. My hope was to find a way to use the message
identifier or some similar to be able to pull up specific messages, which I have
still not determined how to do, but getting it to do a custom compose would at
least be something.

The solution? Create an app that registers googlegmail://, uninstall the GMail
app, install my custom one, and have it print whatever it gets sent on the URL.
This is a relatively simple process, summed up well in this tutorial at
mobiledevelopertips.com,
so I wont go into the details here. After using Google Chrome for iOS to
initiate a message in GMail, the resulting scheme turns out to be:

googlegmail:///co?subject=<subject text>&body=<body text>

Interesting note here, for many versions of iOS (no longer in 6.1, not sure when
it changed) Safari would reject any URL which had no text between the second
and third forward slash. In other words, this URL was effectively hidden from
anyone testing through Safari, but works just fine from anything else. Very
sneaky Google, very sneaky indeed.

Now if only there were a way to access a message directly by the id from the
static URL…

###Update:
With the new release of GMail for iOS there have been some new developments,
including the addition of the feature I was after in the first place, direct
links to individual emails in the app. Read here for more information.