我正在开发一个 Android 应用程序,当收到传入消息时,我需要发布到 PHP 表单或插入 MySQL 数据库。你们中的一些人可能会犹豫是否要回复,但我向你们保证,这不是恶意应用程序。
我在下面发布的代码是我用来阻止传入消息的代码,除了一个号码。当短信被阻止时,任何人都可以帮助我找出一种方法来触发向我的服务器发帖吗?
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;
public class SmsReceiver extends BroadcastReceiver {
public static int MSG_TPE=0;
private String getAddress;
public void onReceive(Context context, Intent intent) {
String MSG_TYPE=intent.getAction();
if(MSG_TYPE.equals("android.provider.Telephony.SMS_RECEIVED")) {
Toast received = Toast.makeText(context,"SMS Received: "+MSG_TYPE , Toast.LENGTH_LONG);
received.show();
Bundle bundle = intent.getExtras();
Object messages[] = (Object[]) bundle.get("pdus");
SmsMessage smsMessage[] = new SmsMessage[messages.length];
for (int n = 0; n < messages.length; n++) {
smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
}
getAddress = smsMessage[0].getOriginatingAddress();
if(getAddress.equals("APPROVEDPHONENUMBER")) {
Toast approved = Toast.makeText(context,"Approved SMS from: " + smsMessage[0].getOriginatingAddress(), Toast.LENGTH_LONG);
approved.show();
// Message is approved and let through
} else {
Toast blocked = Toast.makeText(context,"Blocked SMS from: " + smsMessage[0].getOriginatingAddress(), Toast.LENGTH_LONG);
blocked.show();
// Post to MySQL database
abortBroadcast();
}
for(int i=0;i<8;i++) {
System.out.println("Blocking SMS");
}
}
}
}
基本上我想要做的是在触发事件时从应用程序内部发布到外部 PHP 表单。