5
0
mirror of https://github.com/cwinfo/envayasms.git synced 2024-12-04 12:35:32 +00:00

Move post-parse sms sending to TargetUrlRequest

This commit is contained in:
Nir Yariv 2011-01-18 13:57:34 -05:00
parent 3ed1958ea3
commit 448eafecd8
3 changed files with 25 additions and 30 deletions

View File

@ -9,7 +9,6 @@ import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.util.Log;
@ -47,19 +46,7 @@ public class SMSReceiver extends BroadcastReceiver {
// SMS back the response
if (resp.trim().length() > 0) {
ArrayList<ArrayList<String>> items = url.parseXML(resp);
SmsManager smgr = SmsManager.getDefault();
for (int j = 0; j < items.size(); j++) {
String sendTo = items.get(j).get(0);
if (sendTo.toLowerCase() == "sender") sendTo = sender;
String sendMsg = items.get(j).get(1);
try {
Log.d("KALSMS", "SEND MSG:\"" + sendMsg + "\" TO: " + sendTo);
smgr.sendTextMessage(sendTo, null, sendMsg, null, null);
} catch (Exception ex) {
Log.d("KALSMS", "SMS FAILED");
}
}
url.sendMessages(items);
}
// delete SMS from inbox, to prevent it from filling up
DeleteSMSFromInbox(context, mesg);

View File

@ -7,7 +7,6 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.telephony.SmsManager;
import android.util.Log;
public class SMSSender extends BroadcastReceiver {
@ -33,20 +32,7 @@ public class SMSSender extends BroadcastReceiver {
// SMS back the response
if (resp.trim().length() > 0) {
ArrayList<ArrayList<String>> items = url.parseXML(resp);
SmsManager smgr = SmsManager.getDefault();
for (int j = 0; j < items.size(); j++) {
String sendTo = items.get(j).get(0);
String sendMsg = items.get(j).get(1);
try {
Log.d("KALSMS", "SEND MSG:\"" + sendMsg + "\" TO: " + sendTo);
smgr.sendTextMessage(sendTo, null, sendMsg, null, null);
} catch (Exception ex) {
Log.d("KALSMS", "SMS FAILED");
}
}
url.sendMessages(items);
}
wake.release();
}

View File

@ -22,12 +22,17 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import android.telephony.SmsManager;
import android.util.Log;
public class TargetUrlRequest {
private String sender = "";
public String openURL(String sender, String message, String targetUrl, Boolean isPollRequest) {
this.sender = sender;
List<NameValuePair> qparams = new ArrayList<NameValuePair>();
if(sender.trim().length() > 0 && message.trim().length() > 0) {
@ -105,5 +110,22 @@ public class TargetUrlRequest {
e.printStackTrace();
return (output);
}
}
}
public void sendMessages(ArrayList<ArrayList<String>> items) {
SmsManager smgr = SmsManager.getDefault();
for (int j = 0; j < items.size(); j++) {
String sendTo = items.get(j).get(0);
if (sendTo.toLowerCase() == "sender") sendTo = this.sender;
String sendMsg = items.get(j).get(1);
try {
Log.d("KALSMS", "SEND MSG:\"" + sendMsg + "\" TO: " + sendTo);
smgr.sendTextMessage(sendTo, null, sendMsg, null, null);
} catch (Exception ex) {
Log.d("KALSMS", "SMS FAILED");
}
}
}
}