简体   繁体   English

从Chrome到本机应用的深层链接

[英]Deep linking from Chrome to native app

I am working with the Uber API which uses uber://?... URLs to deep link into the Uber native app. 我正在使用Uber API,它使用uber://?... URL深入链接到Uber原生应用程序。 I am building a mobile website and I'm building one of these URLs as described here ; 我建立一个移动网站和我建立其中一个URL 这里所描述 ;

On iOS everything works fine but on Android the Uber app opens and only gets one of the parameters product_id . 在iOS上一切正常,但在Android上Uber应用程序打开,只获得一个参数product_id So I think there is some issue with how I am encoding the URL and how the Android system is opening it. 所以我认为我对如何编码URL以及Android系统如何打开它存在一些问题。 Here is my JS to build the URL: 这是我构建URL的JS:

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. 同样,这适用于iOS,但不适用于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. 另外奇怪的是,如果我在计算机上使用createURL生成URL,使用PushBullet将其发送到我的Android设备,打开它可以很好地工作。 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. 但是,如果我通过Chrome for Android获取网址,Uber应用程序会打开并且只有product_id正确,而不是任何拾取或下降部分。

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. 注意:我已经使用jQuery的params函数进行了修改但是没有更好的工作,这就是为什么我去手册for (var key in params) {...}循环。

Ok well I figured out it is not an issue of encoding but rather how Chrome launches intents to apps. 好吧,我发现这不是编码问题,而是Chrome如何启动应用程序的意图。 Here is an intent from Pushbullet, this one works fine: 这是Pushbullet的一个意图,这个工作正常:

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): 这是来自Chrome的一个意图,这个推出Uber应用程序,但没有任何数据被应用程序解析(它只是打开就像我点击了启动器图标一样):

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 ). 您可以看到唯一的区别是添加了cat=[android.intent.category.BROWSABLE] ,这是从Chrome for Android( 引用 )启动的意图所需要的。

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. 现在,如果我希望它可以工作,我似乎必须将我的网站打包到Android应用程序中的WebView

你需要在key和params [key]上调用encodeUriComponent

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM