我目前正在爲android編碼,我希望當我收到短信時該應用執行一些操作...現在奇怪的部分...我已經在模擬器中測試了以下代碼它工作100%但是當我把我的Android 2.3.3 GO短信不會在所有的工作:\接收短信Android
import android.content.BroadcastReceiver;
import android.content.Context;<br />
import android.content.Intent;<br />
import android.os.Bundle;<br />
import android.telephony.gsm.SmsMessage;<br />
import android.widget.Toast;
public class SMSReceiver extends BroadcastReceiver {
String lsms;
/* package */ static final String ACTION =
"android.provider.Telephony.SMS_RECEIVED";
@Override
public void onReceive(Context context, Intent intent) {
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null) {
//---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";
}
//---display the new SMS message---
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
}
}
}
是的......我添加了必要的代碼,以AndroidManifest.xml中 的權限:
<uses-permission android:name="android.permission.RECEIVE_SMS" />
而意圖
<receiver android:name=".receiver.SMSReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
我在做類似的事情! http://stackoverflow.com/questions/14452808/sending-and-receiving-mms-in-android – toobsco42 2013-01-22 08:06:28