1

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?

validcat
  • 6,158
  • 2
  • 29
  • 38
  • 1
    I don't seem to fully understand, so you're saying when sending and sms from the android device your BroadcastReceiver doesn't catch it? If this is the case, BroadcastReceiver can't catch sent sms's http://stackoverflow.com/questions/990558/android-broadcast-receiver-for-sent-sms-messages (at least for now) – Aitor Calderon Apr 24 '13 at 14:15
  • I want to catch delivered status of sms that was sent. Can i use receivers for catching all received sms and get delivered status from? Can i find out is sms delivered or not? – validcat Apr 24 '13 at 14:33
  • SMS delivery status is a feature that can be enabled on phone settings IIRC. For what you want maybe this can help: http://stackoverflow.com/questions/15835052/how-to-know-which-sms-is-sent-delivered-from-android-broadcastreceiver – Aitor Calderon Apr 24 '13 at 15:25

0 Answers0