0

I am try to read incoming sms that I sent to the user. I saw a lots of answers around the internet but I can't make it work.

This is my manifest with the permissions and the Receiver:

<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<application>
...
<receiver android:name=".notifications.receiver.SmsCodeReader"
        android:permission="android.permission.BROADCAST_SMS"
        android:exported="true">
        <intent-filter>
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
    </receiver>

</application>

And this is my Receiver class:

public class SmsCodeReader extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    Toast.makeText(context, "received something", Toast.LENGTH_SHORT).show();
}
}

I am working on API 22 so no need run-time permission, but no matter what I try I cant make the Receiver to work. I didn't get any exception or error in the log

EDIT: If I send Broadcast with Intent like this:

Intent in = new Intent("android.provider.Telephony.SMS_RECEIVED");
sendBroadcast(in);

I can see the Toast. so it's mean the Broadcast is properly registered in the manifest. So, why it doesn't work with real SMS?

Thanks to all

Codey
  • 460
  • 1
  • 8
  • 23
  • Do you have the permissions outside of the `` tags, and the `` inside them? Are you sure the `name` attribute on the `` is pointing to the right class, in the right place? Are you launching an `Activity` in your app at least once after installation to bring it out of the _stopped_ state? Does the device have any additional settings or permissions beyond the standard Android ones that might be preventing your app from receiving SMS by default? – Mike M. Apr 26 '17 at 07:55
  • The manifest is right, no error in it. I did have a default SMS app in my device – Codey Apr 26 '17 at 08:08
  • pleas see my edit... Thanks – Codey Apr 26 '17 at 11:45
  • 1
    Ok. It's just because I have a Xioami not 2. I needed to give the permission to read SMS in the app settings – Codey Apr 26 '17 at 12:15

0 Answers0