Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"android.provider.Telephony.SMS_RECEIVED" not working on my device (HTC Wildfire) - how to debug?

Tags:

android

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!?

like image 569
ncreated Avatar asked Nov 06 '11 22:11

ncreated


3 Answers

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?

like image 70
ncreated Avatar answered Nov 06 '22 18:11

ncreated


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.

like image 37
Jens Avatar answered Nov 06 '22 18:11

Jens


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.

like image 43
Toan Vu Avatar answered Nov 06 '22 18:11

Toan Vu