8

I face really frustrating problem.

I created SMS receiver as most online and book's tutorials say.

AndroidManifest.xml:

<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />

<application android:name="roboguice.application.RoboApplication"
             android:icon="@drawable/icon"
             android:label="@string/app_name"
             android:debuggable="true" >    

    <!-- ... other stuffs here ... -->

    <receiver android:name=".receivers.SmsReceiver"> 
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
    </receiver>
</application>

SmsReceiver.java:

public class SmsReceiver extends BroadcastReceiver {

    public static final String TAG = "SmsReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "SMS received!");
        Toast.makeText(context, "SMS received.", Toast.LENGTH_LONG).show();
    }
}

While it works correctly on Emulator (Android 2.2) it doesn't work on my HTC Wildfire (Android 2.2.1, not rooted).

The main problem is that I'm new into Android deveopment and I have completely no idea how to debug it.

Can I find out something usefull with LogCat logs sendt from my HTC device while it receives SMS message? Why is my device different!?

ncreated
  • 641
  • 1
  • 5
  • 14
  • The SMS broadcast is ordered, so step 1 is to yank up your receivers priority something fierce. You do this by setting the android:priority attribute on your intent-filter to a recklessly high value and testing again. Try something like 2147483647. – Jens Nov 06 '11 at 22:26
  • It doesn't change anything :(. No log in LogCat, no Toast shown, just nothing on device (on Emulator it works as expected). I'm wondering why I get such log in LogCat when phone receives sms message: "11-06 23:43:20.540: DEBUG/SMSDispatcher(171): dispatchWapPushToCIQ >>>". Could that be the reason or any trace? – ncreated Nov 06 '11 at 22:53
  • Hm, try downloading an existing SMS-filter (from Market) or something similar to your Wildfire and test that first - it could be something wonky in the HTC phone (has happened before..) – Jens Nov 07 '11 at 10:22
  • 1
    Thanks :), that was good trace. I've find out that "GO SMS Pro" application was blocking this Intent for my app (more details in my solution-answer to this topic). – ncreated Nov 07 '11 at 13:08

4 Answers4

10

Reason & Solution:

I've fix that. "android.provider.Telephony.SMS_RECEIVED" was not working because I had "GO SMS Pro" application installed on my device and there was "Disable other message notification" option checked ("Disable other SMS related apps' notification in notification bar, avoid duplicate notifications."). Unchecking it fixed my problem.

How to make sure that my broadcast receiver will receive this intent even if some other app blocks it? Due to "android:priority" (Intercept SMS messages in Android and prevent them appearing in Messaging App) how can I know what "priority" is set for "GO SMS Pro" app?

ncreated
  • 641
  • 1
  • 5
  • 14
10

For your Reason & Solution:

Intent intent = new Intent("android.provider.Telephony.SMS_RECEIVED");
List<ResolveInfo> infos = getPackageManager().queryBroadcastReceivers(intent, 0);
for (ResolveInfo info : infos) {
    System.out.println("Receiver name:" + info.activityInfo.name + "; priority=" + info.priority);
}

And just look through your output for the GO SMS Pro crap. It's probably ridiculously high.

Jens
  • 16,853
  • 4
  • 55
  • 52
  • 2
    Thanks a milion :)! Now I see that guys from "GO SMS Pro" made two receivers with priority equal to max integer value (2147483647). Their app is probably calling abortBroadcast() on SMS_RECEIVED. So is there any way I can fight with their app? Documentation says nothing about what happens when priorities are equal, but as I find out "Go SMS Pro" app is called first, consumes my SMS_RECEIVED intent and my app isn't called as a result :(. – ncreated Nov 07 '11 at 20:06
  • It's "installed first wins" if I remember correctly. Best bet is to warn the customer that GO SMS Pro is a known problem (dialog, notification or what have you). – Jens Nov 07 '11 at 23:04
  • 1
    Thanks again. Probably best solution would be some extension of what you wrote: to use code above and check if there are any other receivers registered for SMS_RECEIVED intent with max priority. Then to warn user that listed apps could cause a problem. – ncreated Nov 08 '11 at 01:38
  • Just a small suggestion: you would better use `Telephony.Sms.Intents.SMS_RECEIVED_ACTION` constant – Igor Mikushkin Apr 12 '20 at 09:22
2

GO SMS PRO has priority is 2^31-1 = 2147483647. So your app can not receiver any message because GO SMS service aborted other broadcasts.

Toan Vu
  • 21
  • 3
0

I am pretty sure that this code is right. You might not be seeing the Toast message, But the logs would have come. Check the Logcat and you should see the log you have put.

You should be using Notifications inside BroadcastReceivers and not Toasts.

500865
  • 6,920
  • 7
  • 44
  • 87