Fix live monitoring

This commit is contained in:
Victor Shcherb 2012-01-28 13:45:28 +01:00
parent 8650ecce1d
commit c699043f4e
3 changed files with 17 additions and 5 deletions

View file

@ -2,9 +2,9 @@
<resources>
<string name="live_monitoring_descr">Enable sending HTTP requests to a specified web service</string>
<string name="live_monitoring">Enable Live Tracking</string>
<string name="live_monitoring_interval_descr">Specify Live Tracking inverval</string>
<string name="live_monitoring_interval_descr">Specify Live Tracking interval</string>
<string name="live_monitoring_interval">Live Tracking interval</string>
<string name="live_monitoring_url_descr">Specify the Live Tracking web address with parameter syntax : lat={0}, lon={1}, timestamp={2}, hdop={3}, altitude={5}, speed={6}</string>
<string name="live_monitoring_url_descr">Specify the Live Tracking web address with parameter syntax : lat={0}, lon={1}, timestamp={2}, hdop={3}, altitude={4}, speed={5}</string>
<string name="live_monitoring_url">Live Tracking web address</string>
<string name="gpx_monitoring_disabled_warn">Please enable \'Log track to GPX\' Tracking settings</string>
<string name="show_current_gpx_title">Show current track</string>

View file

@ -488,7 +488,7 @@ public class OsmandSettings {
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<String> LIVE_MONITORING_URL = new StringPreference("live_monitoring_url",
"http://example.com?lat={0}&lon={1}&timestamp={2}&hdop={3}&altitude={5}&speed={6}", false);
"http://example.com?lat={0}&lon={1}&timestamp={2}&hdop={3}&altitude={4}&speed={5}", false);
// this value string is synchronized with settings_pref.xml preference name

View file

@ -1,5 +1,9 @@
package net.osmand.plus.activities;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.text.MessageFormat;
@ -34,13 +38,21 @@ public class LiveMonitoringHelper {
}
public void sendData(float lat, float lon, float alt, float speed, float hdop, long time) {
String url = MessageFormat.format(settings.LIVE_MONITORING_URL.get(), lat, lon, time, hdop, alt, speed);
String url = MessageFormat.format(settings.LIVE_MONITORING_URL.get(), lat, lon, time+"", hdop, alt, speed);
try {
URL curl = new URL(url);
log.info("Monitor " + url);
URLConnection conn = curl.openConnection();
conn.setDoInput(false);
conn.setDoOutput(false);
conn.connect();
InputStream is = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String r;
StringBuilder bs = new StringBuilder();
while((r=reader.readLine()) != null){
bs.append(r).append('\n');
}
is.close();
} catch (Exception e) {
log.error("Failed connect to " + url, e);
}