0

I am trying to implement an smsListner. I created my manifest with the receiver:

<receiver android:name=".smsListner" >
    <intent-filter android:priority="1000">
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />
    </intent-filter>
</receiver>

I add the permission:

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

And I implement a class that extends the BroadcastReceiver:

public class smsListner extends BroadcastReceiver {

    final SmsManager sms = SmsManager.getDefault();

    @Override
    public void onReceive(Context context, Intent intent) {


        Toast.makeText(context, "Ok",Toast.LENGTH_LONG).show();

        final  Bundle bundle = intent.getExtras();

        if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")){


        }
    }

Now I just launch Android Studio, and send a real SMS to my device (not an emulator), but the BroadcastReceiver, onReceive method never fired.

Is it possible to debug / develop receiver SMS on a real device?

Cédric Boivin
  • 10,854
  • 13
  • 57
  • 98
  • 1
    1) Do you have the `RECEIVE_SMS` permission listed in the manifest, outside of the `` tags? 2) If you're running on Marshmallow with a `targetSdkVersion` of 23 or above, are you handling the runtime permission correctly? 3) If you're running on a version prior to KitKat, are you sure another app isn't intercepting and aborting the broadcast? 4) Are you sure the `name` attribute on the `` is pointing to the right class, in the right place? 5) Are you launching an `Activity` in your app at least once after installation to bring it out of the _stopped_ state? – Mike M. Sep 30 '16 at 19:34
  • Hi Mike, 1) I try both, inside the application and outside the application. 2) I am not sure on the answer. I am running 6.0.1 (Marshmallow) version. I am targetting the 23 version. 3) How i can determine if another apps intercept the broadcast? 4) I am sure that the name of my receiver is good, and pointing in the rightClass (I also but the full Namespace in the name. 5) I have my main activity are running – Cédric Boivin Sep 30 '16 at 19:39
  • 1
    The permissions go outside of the `` tags. Also, since you're running on Marshmallow, with a `targetSdkVersion` of 23, you'd need to request the permissions at runtime, as described in [this post](http://stackoverflow.com/questions/32635704/android-permission-doesnt-work-even-if-i-have-declared-it). For testing purposes, you could temporarily drop the `targetSdkVersion` to <23. – Mike M. Sep 30 '16 at 19:45
  • Thanks for the tips but doens't work ... :-((( maybe something wrong in my code ... – Cédric Boivin Sep 30 '16 at 20:04
  • 1
    Ok ... it's now working !!! Thanks – Cédric Boivin Sep 30 '16 at 20:05
  • Cool. I'll just vote this as a duplicate of that post, so you can close out your question. (You might need to refresh the page.) Glad you got it working. Cheers! – Mike M. Sep 30 '16 at 20:07

0 Answers0