【发布时间】:2011-12-28 07:14:50
【问题描述】:
我想在发送网络请求方面寻求帮助。
在第 1 部分中,我必须检测短信中的某些文本/代码,这已完成。
现在我想知道何时检测到文本/代码(字符串),android 是如何将 web 请求发送到 java web 应用程序的?
我需要使用 post 和 get 方法吗?
使用:Eclipse Indigo 2.7,API 2.3.3
建议和任何帮助将不胜感激 =)
以下是我现有的代码:
// ---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null) // if contains message
{
// ---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i = 0; i < msgs.length; i++)
{
msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
str += "SMS from " + msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
str += "\n";
Log.i(TAG, "Message: "+msgs[i].getMessageBody().toString()); //The message content
// Checking for Pattern
// Direct use of Pattern:
Pattern p = Pattern.compile("123");
Matcher m = p.matcher(msgs[i].getMessageBody().toString());
while (m.find()) // Find each match in turn; String can't do this.
{
String result = m.group(); // Access a submatch group;
Log.i(TAG, "Password Match: " + result); //Showing the result
str +="found";
}
}
// ---display the new SMS message---
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
}
【问题讨论】:
标签: android eclipse webrequest