First of all I already searched for possible solutions, tried everything and it still didn't work. I must be missing something.
I am trying to create an app that receives/reads and writes SMS.
the write part is working just fine, my broadcast receiver just doesn't catch broadcast.
AndroidManifest.xml
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
...
<receiver android:name=".SmsReceiver"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
SmsReceiver.java
public class SmsReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "ON RECEIVE BROADCAST", Toast.LENGTH_LONG).show();
Log.d("ON ","RECEIVE");
Bundle bundle = intent.getExtras();
Object[] messages = (Object[]) bundle.get("pdus");
SmsMessage[] sms = new SmsMessage[messages.length];
// Create messages for each incoming PDU
for (int n = 0; n < messages.length; n++) {
sms[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
}
for (SmsMessage msg : sms) {
Log.e("RECEIVED MSG",":"+msg.getMessageBody());
// Verify if the message came from our known sender
}
}
none of the Logs or toasts are fired.
Tried changing action on manifest to android.intent.action.AIRPLANE_MODE
just to test the declaration and the broadcast was received, is just not working for the SMS.
UPDATED
Tried on a different phone and it worked. Must be because I am using Handcent SMS, and some how its blocking the broadcast. Either way I need it to be working on every phone independent of the applications installed.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…