0

I'm creating at the moment a SMS Broadcast Receiver. I also use GoSMS in my phone.

The problems is: if i dont set android:priority or set value less than 2147483647 (this is GoSms's priority)

for my receiver, i cannot receive the message.

When i set android:priority ="2147483647", my app can receive the message but, some application in my phone have been force close:

08-01 17:52:47.775: E/AndroidRuntime(3501): FATAL EXCEPTION: main
08-01 17:52:47.775: E/AndroidRuntime(3501): java.lang.RuntimeException: Unable to start service com.android.exchange.SmsRelayService@414f47f8 with Intent { cmp=com.android.exchange/.SmsRelayService (has extras) }: java.lang.NullPointerException
08-01 17:52:47.775: E/AndroidRuntime(3501):     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2388)
08-01 17:52:47.775: E/AndroidRuntime(3501):     at android.app.ActivityThread.access$1900(ActivityThread.java:127)
08-01 17:52:47.775: E/AndroidRuntime(3501):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1222)
08-01 17:52:47.775: E/AndroidRuntime(3501):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 17:52:47.775: E/AndroidRuntime(3501):     at android.os.Looper.loop(Looper.java:137)
08-01 17:52:47.775: E/AndroidRuntime(3501):     at android.app.ActivityThread.main(ActivityThread.java:4507)
08-01 17:52:47.775: E/AndroidRuntime(3501):     at java.lang.reflect.Method.invokeNative(Native Method)
08-01 17:52:47.775: E/AndroidRuntime(3501):     at java.lang.reflect.Method.invoke(Method.java:511)
08-01 17:52:47.775: E/AndroidRuntime(3501):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
08-01 17:52:47.775: E/AndroidRuntime(3501):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
08-01 17:52:47.775: E/AndroidRuntime(3501):     at dalvik.system.NativeStart.main(Native Method)
08-01 17:52:47.775: E/AndroidRuntime(3501): Caused by: java.lang.NullPointerException
08-01 17:52:47.775: E/AndroidRuntime(3501):     at android.provider.Telephony$Sms$Intents.getMessagesFromIntent(Telephony.java:888)
08-01 17:52:47.775: E/AndroidRuntime(3501):     at com.android.exchange.SmsRelayService.onStartCommand(SmsRelayService.java:69)
08-01 17:52:47.775: E/AndroidRuntime(3501):     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2371)

this is my code

public class SmsListener extends BroadcastReceiver{
 @Override
    public void onReceive(Context context, Intent intent) {

        if(intent.getAction().equals(Constants.SMS_RECEIVED_ACTION)){
        // Do some thing
        }
}
}

and

<receiver android:name=".widget.SmsListener" >
            <intent-filter android:priority="2147483647">
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>

I am running in Galaxy S2, ICS

Help me please

Regards

Nam Vu
  • 5,669
  • 7
  • 58
  • 90
  • Which API version are you on? – Turnsole Aug 01 '12 at 15:11
  • It looks like the S2 is running 4.0.3. I don't have that source handy, so I can't tell you exactly what is turning up null, but it is almost certainly one/all of the extras in the Intent. How are you sending SMS messages to the phone? – Turnsole Aug 01 '12 at 15:54
  • i use another cell phone to send sms – Nam Vu Aug 01 '12 at 18:04

1 Answers1

1

If you just need to receive the SMS and you don't want to abort the SMS broadcast, you can simply allow other apps to receive the broadcast by changing GO SMS pro's application settings. You can instruct users to do that if they are using GO SMS. Like this: "Open Go SMS, hit 'Menu' and click 'Settings', click on 'Receive Settings', then uncheck the 'Disable other message notifications."

But if you need to abort the broadcast, let me say that setting the priority equal to "2147483647" didn't work for me. The bottom line was that both applications received the broadcast and the SMS would actually receive. The first-app-installed rule suggested here (see the comments for the selected answer) and here didn't work for me either.

However some one suggested a piece of code here that apparently you can get a list of receivers running on the device with it, you'd better look into that. So hopefully you can warn the user of some receiver that might interfere with yours, so you won't get one-star ranks with a "App doesn't work" comment from the users.

Community
  • 1
  • 1
Wise
  • 628
  • 2
  • 11
  • 25
  • Thanks, but i dont want to warn user anything. Just only want to receiver the SMS. – Nam Vu Aug 03 '12 at 09:27
  • So just instruct the users to change GO SMS's application setting: "Open Go SMS, hit 'Menu' and click 'Settings', click on 'Receive Settings', then uncheck the 'Disable other message notifications." – Wise Aug 03 '12 at 09:40