4

I am working with the Uber API which uses uber://?... URLs to deep link into the Uber native app. I am building a mobile website and I'm building one of these URLs as described here;

On iOS everything works fine but on Android the Uber app opens and only gets one of the parameters product_id. So I think there is some issue with how I am encoding the URL and how the Android system is opening it. Here is my JS to build the URL:

uber.createURL = function() {

    var params = {
        "client_id": uber.CLIENT_ID,
        "product_id": maps.product_id,
        "pickup[latitude]": maps.noSurgeMarker.getPosition().lat(),
        "pickup[longitude]": maps.noSurgeMarker.getPosition().lng(),
        "dropoff[latitude]": maps.destMarker.getPosition().lat(),
        "dropoff[longitude]": maps.destMarker.getPosition().lng(),
        "pickup[formatted_address]": $('#pickup').val(),
        "dropoff[formatted_address]": $('#destination').val()
    };

    var url = 'uber://?action=setPickup';

    for (var key in params) {
        if (params.hasOwnProperty(key)) {
            url += ('&' + key + '=' + encodeURIComponent(params[key]));
        }
    }

    return url;
};

I am then calling the following code to open the link:

var url = uber.createURL();
window.location.href = url;

Am I missing something obvious? Again, this works on iOS but not on Android. Also the strange thing is if I generate the URL using createURL on a computer, send it over to my Android device using PushBullet, opening it works perfectly. But if I get the URL through Chrome for Android the Uber app opens and only has product_id correct, not any of the pickup or dropoff parts.

Note: I already trued using jQuery's params function but that didn't work any better, which is why I went to the manual for (var key in params) {...} loop.

Sam Stern
  • 24,624
  • 13
  • 93
  • 124
  • Try `url += ('&' + encodeURIComponent(key) + '=' + encodeURIComponent(params[key]));`. I think the square brackets are troublesome. – Eugen Pechanec Jan 08 '15 at 22:40
  • That was @GregEnnis's answer below. It did not work... – Sam Stern Jan 09 '15 at 06:04
  • 1
    Now comes the part when you wait for uber to fix their stuff (decode the uri on their part)... One more thing you could try. In the source there's another notation (for web service at the end of document) that uses an underscore instead of square brackets i.e. `pickup_latitude` instead of `pickup[latitude]`. If that doesn't work I'm out of ideas. – Eugen Pechanec Jan 09 '15 at 10:35
  • @hatboysam Does it help if you use [Intent Intercept](https://play.google.com/store/apps/details?id=uk.co.ashtonbrsc.android.intentintercept&hl=en) to see exactly how the intent that Uber gets looks like? – aluxian Jan 10 '15 at 13:50
  • @AlexandruRosianu that's a great idea, unfortunately it won't intercept this one. I will use that app a lot for future development though, that's helpful. – Sam Stern Jan 11 '15 at 03:31

2 Answers2

3

Ok well I figured out it is not an issue of encoding but rather how Chrome launches intents to apps. Here is an intent from Pushbullet, this one works fine:

I/ActivityManager(  942): START u0 
{act=android.intent.action.VIEW 
dat=uber://?
client_id=REDACTED&
action=setPickup&
product_id=a1111c8c-c720-46c3-8534-2fcdd730040d&
pickup[latitude]=37.780654&
pickup[longitude]=-122.405599&
dropoff[latitude]=37.7970558&
dropoff[longitude]=-122.43199099999998
flg=0x10000000 cmp=com.ubercab/.client.feature.launch.LauncherActivity} from pid 19023

Here is an intent from Chrome, this one launches the Uber app but none of the data is parsed by the app (it just opens as if I had clicked the launcher icon):

I/ActivityManager(  942): START u0 
{act=android.intent.action.VIEW 
cat=[android.intent.category.BROWSABLE] 
dat=uber://?
client_id=REDACTED&
action=setPickup&
product_id=a1111c8c-c720-46c3-8534-2fcdd730040d&
pickup[latitude]=37.780654&
pickup[longitude]=-122.405599&
dropoff[latitude]=37.7970558&
dropoff[longitude]=-122.43199099999998
flg=0x10000000 cmp=com.ubercab/.client.feature.launch.LauncherActivity (has extras)} from pid 26446

You can see that the only difference is the added cat=[android.intent.category.BROWSABLE] which is something that is required for intents launched from Chrome for android (reference).

So overall I think this is something Uber will have to solve. For now it looks like I'm going to have to package my website into a WebView in an Android app if I want it to work.

Andrew Noonan
  • 848
  • 6
  • 13
Sam Stern
  • 24,624
  • 13
  • 93
  • 124
  • 1
    They've added `` to the intent filter that matches for the `uber://` scheme https://gist.github.com/mnemonicflow/11343e69458fa58d6f52#file-com-ubercab-ububeractivity-xml-L19-L23 – Alex Bitek Jan 26 '16 at 07:55
2

You need to call encodeUriComponent on both key and params[key].

Greg Ennis
  • 14,917
  • 2
  • 69
  • 74