From 3ed1958ea391cc004d709a18fd2f2bc18a3aa4be Mon Sep 17 00:00:00 2001 From: Nir Yariv Date: Sat, 15 Jan 2011 19:27:19 -0500 Subject: [PATCH] add a poll=true parameter --- res/xml/prefs.xml | 2 +- src/kalsms/niryariv/itp/SMSReceiver.java | 2 +- src/kalsms/niryariv/itp/SMSSender.java | 2 +- src/kalsms/niryariv/itp/TargetUrlRequest.java | 16 ++++++++++------ 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/res/xml/prefs.xml b/res/xml/prefs.xml index 2022e3a..b39b361 100644 --- a/res/xml/prefs.xml +++ b/res/xml/prefs.xml @@ -20,7 +20,7 @@ android:key="pref_poll_switch" android:title="Server Polling" android:disableDependentsState="false" - android:summary="Poll target URL every 15 minutes (Note: Polling increased power consumption, and is not supported by all phone models)" + android:summary="Poll target URL every 15 minutes (Note: increases power usage)" > \ No newline at end of file diff --git a/src/kalsms/niryariv/itp/SMSReceiver.java b/src/kalsms/niryariv/itp/SMSReceiver.java index 5394982..265155b 100644 --- a/src/kalsms/niryariv/itp/SMSReceiver.java +++ b/src/kalsms/niryariv/itp/SMSReceiver.java @@ -41,7 +41,7 @@ public class SMSReceiver extends BroadcastReceiver { Log.d("KALSMS", "MSG RCVD:\"" + message + "\" from: " + sender); // send the message to the URL - String resp = url.openURL(sender, message, targetUrl).toString(); + String resp = url.openURL(sender, message, targetUrl, false).toString(); Log.d("KALSMS", "RESP:\"" + resp); // SMS back the response diff --git a/src/kalsms/niryariv/itp/SMSSender.java b/src/kalsms/niryariv/itp/SMSSender.java index 004c629..96940df 100755 --- a/src/kalsms/niryariv/itp/SMSSender.java +++ b/src/kalsms/niryariv/itp/SMSSender.java @@ -26,7 +26,7 @@ public class SMSSender extends BroadcastReceiver { Log.d("KALSMS", "url:\"" + targetUrl); TargetUrlRequest url = new TargetUrlRequest(); // send the message to the URL - String resp = url.openURL("","",targetUrl).toString(); + String resp = url.openURL("","",targetUrl, true).toString(); Log.d("KALSMS", "RESP:\"" + resp); diff --git a/src/kalsms/niryariv/itp/TargetUrlRequest.java b/src/kalsms/niryariv/itp/TargetUrlRequest.java index ede5d55..e1e8d92 100644 --- a/src/kalsms/niryariv/itp/TargetUrlRequest.java +++ b/src/kalsms/niryariv/itp/TargetUrlRequest.java @@ -26,15 +26,19 @@ import android.util.Log; public class TargetUrlRequest { - public String openURL(String sender, String message, String targetUrl) { + public String openURL(String sender, String message, String targetUrl, Boolean isPollRequest) { - String url = targetUrl; + List qparams = new ArrayList(); + if(sender.trim().length() > 0 && message.trim().length() > 0) { - List qparams = new ArrayList(); qparams.add(new BasicNameValuePair("sender", sender)); - qparams.add(new BasicNameValuePair("msg", message)); - url = targetUrl + "?" + URLEncodedUtils.format(qparams, "UTF-8"); - } + qparams.add(new BasicNameValuePair("msg", message)); + } else if (isPollRequest) { + qparams.add(new BasicNameValuePair("poll", "true")); + } + + String url = targetUrl + "?" + URLEncodedUtils.format(qparams, "UTF-8"); + try { HttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(url);