Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your application will need to have the uses-permission for <a href="http://developer.android.com/reference/android/Manifest.permission.html#RECEIVE_SMS" rel="nofollow">android.permission.RECEIVE_SMS</a> in your manifest.</p> <p>Once you have that you can register a broadcast receiver for <code>android.provider.Telephony.SMS_RECEIVED</code>.</p> <p>Then you'll want to create your <a href="http://developer.android.com/guide/topics/manifest/receiver-element.html" rel="nofollow">receiver</a>.</p> <pre><code>&lt;receiver android:name=".SMSBroadcastReceiver"&gt; &lt;intent-filter&gt; &lt;action android:name="android.provider.Telephony.SMS_RECEIVED" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; </code></pre> <p>Your receiver should extend the <a href="http://developer.android.com/reference/android/content/BroadcastReceiver.html" rel="nofollow">BroadcastReceiver</a> and in the onReceive() method when you receive an intent for <code>android.provider.Telephony.SMS_RECEIVED_ACTION</code> you want to retrieve the message and determine if it is one that you want to pay attention to.</p> <p>Your code might look something like this.</p> <pre><code>public class SMSBroadcastReceiver extends BroadcastReceiver { private static final String TAG = "SMSBroadcastReceiver"; private static final String SMS_RECEIVED_ACTION = "android.provider.Telephony.SMS_RECEIVED" @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(SMS_RECEIVED)) { Bundle bundle = intent.getExtras(); if (bundle != null) { Object[] pdus = (Object[]) bundle.get("pdus"); final SmsMessage[] messages = new SmsMessage[pdus.length]; for (int i = 0; i &lt; pdus.length; i++) { messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); } if (messages.length &gt; -1) { //You have messages, do something with them here to determine if you want to look at them and other actions. } } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload