Can I launch an intent using only javascript in an

2019-07-19 14:36发布

I have a html page that shows the directions from the current location to a certain address.

I would like to do the same but use the map app instead of showing it in a browser.

When I use :

<script>
    document.location = "geo:0,0?q=myaddress";
</script>

That works fine but does not show me the route.

What I read from this : Android Google Directions Service usable natively? with wrapper framework? Public transit/biking directions available?

It should be possible using this code :

String url = "http://maps.google.com/maps?saddr=some+address&daddr=another+Address"
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,  Uri.parse(url));

Can I do the same just using javascript ?

2条回答
劳资没心,怎么记你
2楼-- · 2019-07-19 15:13

Android is capable of detecting links to Google Maps in the browser and redirect the Intent to the native Google Maps app, if it is set as the default app. There is, however, no way to force the user to use the Google Maps app. Clicking the link can also show him the activity chooser or open Google Maps in the browser. It might also open a third-party app that is registered to handle the same Intent. The code snippet you posted will behave exactly like that, too.

This not only works from the browser, but with all links in the system. For example, I sent the link you posted via e-mail to myself and clicked it on my phone. I could open it with my Goolge Maps app. So there is really no need for JavaScript, you can just use a simple HTML link to send the Intent.

查看更多
不美不萌又怎样
3楼-- · 2019-07-19 15:14

Just simply call the function from JavaScript to Android , and inside the function you can call the android intent.

you can find out the tutorial how to call android function from JavaScript:

http://android-er.blogspot.in/2011/10/call-javascript-inside-webview-from.html

and call the map using Google V3 library .

https://developers.google.com/maps/articles/android_v3

查看更多
登录 后发表回答