How to fix Unprotected SMS BroadcastReceiver lint warning : <p>My app needs to be able to receive SMS messages. It all works, but I get this lint warning:</p>

<blockquote>
  <p>BroadcastReceivers that declare an intent-filter for SMS_DELIVER or
  SMS_RECEIVED must ensure that the caller has the BROADCAST_SMS
  permission, otherwise it is possible for malicious actors to spoof
  intents.</p>
</blockquote>

<p>How do I "ensure that the caller has the BROADCAST_SMS permission"?</p>

<p>In my manifest I have:</p>

<pre><code>&lt;uses-permission android:name="android.permission.RECEIVE_SMS" /&gt;
&lt;application ...&gt;
    &lt;receiver
        android:name=".SmsReceiver"
        android:enabled="true"
        android:exported="true"&gt;
        &lt;intent-filter android:priority="1000"&gt;
            &lt;action android:name="android.provider.Telephony.SMS_RECEIVED" /&gt;
        &lt;/intent-filter&gt;
    &lt;/receiver&gt;
&lt;/application&gt;
</code></pre>

<p>My code:</p>

<pre><code>public class SmsReceiver extends BroadcastReceiver {
    public SmsReceiver() {}

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

        final Bundle bundle = intent.getExtras();
        if (bundle != null) {
            final Object[] pdusObj = (Object[]) bundle.get("pdus");
            for (int i = 0; i &lt; pdusObj.length; i++) {
                final SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
                // use currentMessage
            }
        }
    }
}
</code></pre>
