1

I have searched and searched, and can't find the answer on this one. I'm trying to do a simple SMS intent filter, and it works great when I run it on an AVD, but as soon as I debug on an actual device, the receiver never fires. I have modified my manifest in all sorts of ways, and can't get it to work.

Can anyone find what's missing, or incorrect?

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.customs.dbc.smsrelay"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.customs.dbc.smsrelay.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <service android:name="com.customs.dbc.smsrelay.StartServices" />
    <service android:name="com.customs.dbc.smsrelay.SMSRelayMonitor" />

    <receiver
        android:name=".GotBoot"
        android:enabled="true"
        android:exported="true"
        android:label="GotBoot"
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver>
    <receiver android:name="com.customs.dbc.smsrelay.IncomingSms" >
        <intent-filter
            android:priority="999"
            android:exported="true" >
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
    </receiver>
</application>

</manifest>

Receiver:

    package com.customs.dbc.smsrelay;

    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.telephony.SmsManager;
    import android.telephony.SmsMessage;
    import android.util.Log;

    public class IncomingSms extends BroadcastReceiver {

    // Get the object of SmsManager
    final SmsManager sms = SmsManager.getDefault();

    public void onReceive(Context context, Intent intent) {     

        // Retrieves a map of extended data from the intent.
        final Bundle bundle = intent.getExtras();

        try {

            if (bundle != null) {

                final Object[] pdusObj = (Object[]) bundle.get("pdus");

                for (int i = 0; i < pdusObj.length; i++) {

                    SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
                    String phoneNumber = currentMessage.getDisplayOriginatingAddress();

                    String senderNum = phoneNumber;
                    String message = currentMessage.getDisplayMessageBody();
                    // got the message

                    //TODO This is where I can send the message off from here
                    Intent newSms = new Intent("SMSRELAYGOTNEWMESSAGE").putExtra("msg", message).putExtra("sender", senderNum);
                    context.sendBroadcast(newSms);

                // Log it for debugging
                    Log.i("SmsReceiver", "senderNum: "+ senderNum + "; message: " + message);

                } // end for loop
              } // bundle is null

        } catch (Exception e) {
            Log.e("SmsReceiver", "Exception smsReceiver" +e);
        }
    }    
}

Update:

I have now attempted to register the receiver dynamically as well, and still no go.

Here is my service class:

package com.customs.dbc.smsrelay;

import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;

public class SMSRelayMonitor extends IntentService {

    public SMSRelayMonitor() {
        super("SMSRelayMonitor");
        // TODO Auto-generated constructor stub
    }

    @Override
protected void onHandleIntent(Intent intent) {
    // TODO Auto-generated method stub

}

public int onStartCommand(Intent intent, int flags, int startId) {
    IntentFilter filter = new IntentFilter("SMSRELAYGOTNEWMESSAGE");        
    this.registerReceiver(mIntentReceiver, filter);
    IntentFilter smsFilter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
    this.registerReceiver(smsReceiver, smsFilter);
    return START_STICKY;
}

public void onDestroy() {
    super.onDestroy();
    unregisterReceiver(mIntentReceiver);
    unregisterReceiver(smsReceiver);
}

private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {

    @SuppressWarnings("unused")
    @Override
    public void onReceive(Context context, Intent intent) {
        String message = intent.getStringExtra("msg");
        String sender = intent.getStringExtra("sender");
        Notification notice = new Notification.Builder(context).setContentTitle("New message").build();
        NotificationManager noticeManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notice.flags |= Notification.FLAG_AUTO_CANCEL;
        noticeManager.notify(0, notice);
    }
};

private final BroadcastReceiver smsReceiver = new BroadcastReceiver() {
    //final SmsManager sms = SmsManager.getDefault();

    public void onReceive(Context context, Intent intent) {     

        // Retrieves a map of extended data from the intent.
        final Bundle bundle = intent.getExtras();

        try {

            if (bundle != null) {

                final Object[] pdusObj = (Object[]) bundle.get("pdus");

                for (int i = 0; i < pdusObj.length; i++) {

                    SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
                    String phoneNumber = currentMessage.getDisplayOriginatingAddress();

                    String senderNum = phoneNumber;
                    String message = currentMessage.getDisplayMessageBody();
                    // got the message

                    //TODO This is where I can send the message off from here
                    Intent newSms = new Intent("SMSRELAYGOTNEWMESSAGE").putExtra("msg", message).putExtra("sender", senderNum);
                    context.sendBroadcast(newSms);

                    // Log it for debugging
                    Log.i("SmsReceiver", "senderNum: "+ senderNum + "; message: " + message);

                } // end for loop
              } // bundle is null

        } catch (Exception e) {
            Log.e("SmsReceiver", "Exception smsReceiver" +e);

        }
    }
};
}
Dilleyboy
  • 41
  • 4

1 Answers1

0

The issue I was seeing was caused by another app installed on the phone. "Go SMS Pro" is the culprit. After doing a factory restore on my hardware device, the intent was firing. After I installed Go SMS Pro again, the intent would not fire on my app.

SMS Broadcastreceiver not called when GO SMS Pro installed

Dilleyboy
  • 41
  • 4