i have a problem with delivering sms receiver. I set in Manifest
permissions and intent filter, in Activity
- sms is created and BroadcastReceiver
catch intent as in tutorial
Here is code from Activity
try {
String DELIVERED = "SMS_RECEIVED";
PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0, new Intent(DELIVERED), 0);
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(contact.getPhone(), null, message, null, deliveredPI);
} catch (Exception e) {
Log.e(LOG_TAG, "Sms do not sent");
}
Here is permissions in Manifest
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_CONTACTS"/>
...
<receiver android:name="com.uniquare.sms.globals.DeliveredReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
and part of Receivers
public class DeliveredReceiver extends BroadcastReceiver {
private static final String LOG_TAG = "DeliveredReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.d(LOG_TAG, "onReceive()");
//get the SMS message passed in
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String phone = "";
if (bundle != null) {
//retrieve the SMS message received
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
.....
And there is something strange for me. If i send sms to my current device, BroadcastReceiver
works fine. But if i send to other users from contact list BroadcastReceiver
doesn't work at all.
I try to set android.provider.Telephony.SMS_RECEIVED
instead of SMS_RECEIVED
in Activity
PendingIntent
:
String DELIVERED = "android.provider.Telephony.SMS_RECEIVED";
PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0, new Intent(DELIVERED), 0);
in this case DeliveredReceiver
is working, onReceive
is called but when I try to get pdus
from Object[] pdus = (Object[]) bundle.get("pdus");
I get null
.
Do you have the same problems? Could u suggest me smth?