on android app: send intent for PosLink (fixes #437)

This commit is contained in:
leCradle 2013-03-11 20:24:51 +01:00
parent 303b1cc03a
commit d3270f698c
4 changed files with 43 additions and 7 deletions

View File

@ -107,11 +107,15 @@ window.rangeLinkClick = function() {
} }
window.showPortalPosLinks = function(lat, lng) { window.showPortalPosLinks = function(lat, lng) {
if (android && android.intentPosLink) {
android.intentPosLink('https://maps.google.com/?q='+lat+','+lng);
} else {
var qrcode = '<div id="qrcode"></div>'; var qrcode = '<div id="qrcode"></div>';
var script = '<script>$(\'#qrcode\').qrcode({text:\'GEO:'+lat+','+lng+'\'});</script>'; var script = '<script>$(\'#qrcode\').qrcode({text:\'GEO:'+lat+','+lng+'\'});</script>';
var gmaps = '<a href="https://maps.google.com/?q='+lat+','+lng+'">gmaps</a>'; var gmaps = '<a href="https://maps.google.com/?q='+lat+','+lng+'">gmaps</a>';
var osm = '<a href="http://www.openstreetmap.org/?mlat='+lat+'&mlon='+lng+'&zoom=16">OSM</a>'; var osm = '<a href="http://www.openstreetmap.org/?mlat='+lat+'&mlon='+lng+'&zoom=16">OSM</a>';
alert('<div style="text-align: center;">' + qrcode + script + gmaps + ' ' + osm + '</div>'); alert('<div style="text-align: center;">' + qrcode + script + gmaps + ' ' + osm + '</div>');
}
} }
window.reportPortalIssue = function(info) { window.reportPortalIssue = function(info) {

View File

@ -2,10 +2,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cradle.iitc_mobile" package="com.cradle.iitc_mobile"
android:versionCode="1" android:versionCode="1"
android:versionName="0.2" > android:versionName="0.2.1" >
<uses-sdk <uses-sdk
android:minSdkVersion="11" android:minSdkVersion="14"
android:targetSdkVersion="17" /> android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />

View File

@ -0,0 +1,25 @@
package com.cradle.iitc_mobile;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.webkit.JavascriptInterface;
// provide communication between IITC script and android app
public class IITC_JSInterface {
// context of main activity
Context context;
IITC_JSInterface(Context c) {
context = c;
}
// send intent for gmaps link
@JavascriptInterface
public void intentPosLink(String s) {
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse(s));
context.startActivity(intent);
}
}

View File

@ -13,6 +13,7 @@ public class IITC_WebView extends WebView {
private WebSettings settings; private WebSettings settings;
private IITC_WebViewClient webclient; private IITC_WebViewClient webclient;
private IITC_JSInterface js_interface;
// init web view // init web view
private void iitc_init(Context c) { private void iitc_init(Context c) {
@ -21,6 +22,8 @@ public class IITC_WebView extends WebView {
settings.setDomStorageEnabled(true); settings.setDomStorageEnabled(true);
settings.setAllowFileAccess(true); settings.setAllowFileAccess(true);
settings.setGeolocationEnabled(true); settings.setGeolocationEnabled(true);
this.js_interface = new IITC_JSInterface(c);
this.addJavascriptInterface(js_interface, "android");
// our webchromeclient should share geolocation with the iitc script // our webchromeclient should share geolocation with the iitc script
// allow access by default // allow access by default
@ -59,4 +62,8 @@ public class IITC_WebView extends WebView {
return this.webclient; return this.webclient;
} }
public IITC_JSInterface getJSInterface() {
return this.js_interface;
}
} }