Note that there are some explanatory texts on larger screens.

plurals
  1. POIntercept Text Messages : Debugging Problems
    text
    copied!<p>I am using a simple BroadcastReceiver and onReceive method to intercept text messages as they come. For some reason, every time I send the text message: the app crashes. When I try to debug the app: I send the text message and the app still crashes but instead of taking me into the Receiver class, it suspends inside of the "ActivityThreadhandleReceiver(ActivityThread,ActivityThreadReceiverData)". The Debugging window just says for the Thread: "(Suspended(exception RuntimeException))".</p> <p>How am I supposed to find out why my app is crashing if it won't allow me to step through my code.</p> <p>Here is my Receiver Class: </p> <pre><code>public class FinderReciever extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); SmsMessage[ ] msgs = null; String str = ""; if (bundle != null) { //---retrieve the received message here --- Object[ ] pdus = (Object[ ]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int i=0; i&lt;msgs.length; i++){ msgs[i] = SmsMessage.createFromPdu((byte[ ])pdus[i]); str += "SMS from " + msgs[i].getOriginatingAddress(); str += " :"; str += msgs[i].getMessageBody().toString(); str += "\n"; } // ........first show sms here..... Toast.makeText(context, str, Toast.LENGTH_SHORT).show(); } </code></pre> <p>And here is my Manifest:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; </code></pre> <p> </p> <pre><code>&lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt; &lt;activity android:name=".PhoneFinder_Activity" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;receiver android:name=".SmsReceiver"&gt; &lt;intent-filter&gt; &lt;action android:name= "android.provider.Telephony.SMS_RECEIVED" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; &lt;/application&gt; &lt;uses-permission android:name="android.permission.READ_SMS" /&gt; &lt;uses-permission android:name="android.permission.RECEIVE_SMS" /&gt; </code></pre> <p></p> <p>Any help would be much appreciated. Thanks! </p> <p>EDIT: Even after re-formatting the method to run inside of my main Activity I get the exact same result. This exact same method works upon the sending of texts Intent:</p> <pre><code> String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; String RECEIVED = "SMS_RECEIVED"; PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0); PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); PendingIntent receivedPI = PendingIntent.getBroadcast(this, 0, new Intent(RECEIVED), 0); //---when the SMS has been sent--- registerReceiver(new BroadcastReceiver(){ @Override public void onReceive(Context arg0, Intent arg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "FRIGGEN SMS!", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show(); break; } } }, new IntentFilter(RECEIVED)); </code></pre>
 

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