Using Eclipse Ganymede
I found various bits of code on the internet and put together some
code to test javascript and Android attaching latitude, longitude to a
browser form application. If I comment out the location loc code and
execute the two assignment lines, things work as expected. The
javascript code in the browser picks up latitude, longitude. With the
loc code, the browser displays a blank screen for a moment and then
goes away. Any help and thoughts appreciated
Regards, Tom Birchmire
Android code:
package com.gpsmancer.gpstest;
import android.app.Activity;
import android.os.Bundle;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.webkit.WebView;
public class gps_lat_lon extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
WebView wv = new WebView (this);
wv.getSettings().setJavaScriptEnabled (true);
JsObj jo = new JsObj (this);
wv.addJavascriptInterface ( jo, "roid" ) ;
setContentView (wv);
wv.loadUrl( "http://gpsmancer.com/android/
androidgpstest.html");
}
class JsObj {
private Context con;
public JsObj (Context con) {
this.con = con;
}
public String gps (String top, String end) {
LocationManager locman = (LocationManager) con.getSystemService
(Context.LOCATION_SERVICE);
// Location loc = locman.getLastKnownLocation( "gps" ) ;
// int lat = (int) (loc.getLatitude () * 1000000);
// int lon = (int) (loc.getLongitude () * 1000000);
int lat = (int) (43.123456 * 1000000 );
int lon = (int) (71.234567 * 1000000 ) ;
return top + "Latitude:" + lat + ", longitude:" + lon + end;
}
}
}
Browser code:
<html>
<head><title>JS calls Android Method</title></head>
<body>
<h1>JS on Android</h1>
<script type="text/javascript">
document.write(roid.gps("<i>", "</i>"));
</script>
</body>
</html>
Manifest Permissions:
<?xml version="1.0" encoding="utf-8"?>
some code omittted
<uses-permission android:name="android.permission.INTERNET"></uses-
permission>
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-
permission>
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"></uses-
permission>
<uses-permission
android:name="android.permission.ACCESS_MOCK_LOCATION"></uses-
permission>
</manifest>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---