Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - SMS Broadcast receiver
    primarykey
    data
    text
    <p>I have been trying to get <a href="https://stackoverflow.com/questions/1944102/android-sms-receiver-not-working">this</a> program to work but so far having no luck. I cannot find where I am doing wrong. I'm not sure if there's something wrong with the code, or debugging.</p> <p>I'm trying to be notified if a new SMS arrives.</p> <p>Here is my program:</p> <pre><code>package Technicaljar.SMSBroadcastReceiver; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.telephony.SmsMessage; import android.util.Log; public class SMSBroadcastReceiver extends BroadcastReceiver { private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED"; private static final String TAG = "SMSBroadcastReceiver"; @Override public void onReceive(Context context, Intent intent) { Log.i(TAG, "Intent recieved: " + intent.getAction()); if (intent.getAction() == 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) { Log.i(TAG, "Message recieved: " + messages[0].getMessageBody()); } } } } } </code></pre> <p>And the manifest file:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="Technicaljar.SMSBroadcastReceiver" android:versionCode="1" android:versionName="1.0"&gt; &lt;application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true" &gt; &lt;receiver android:name=".SMSBroadcastReceiver"&gt; &lt;intent-filter&gt; &lt;action android:name="android.provider.telephony.SMS_RECEIVED"&gt;&lt;/action&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; &lt;/application&gt; &lt;uses-sdk android:minSdkVersion="7" /&gt; &lt;uses-permission android:name="android.permission.INTERNET"&gt;&lt;/uses-permission&gt; &lt;uses-permission android:name="android.permission.RECEIVE_SMS"&gt;&lt;/uses-permission&gt; &lt;/manifest&gt; </code></pre> <p>I am sending SMS through Telnet, and I cannot see any Intent received messages in the logcat. Here is my logcat from the time of installation.</p> <pre><code>D/AndroidRuntime( 478): D/AndroidRuntime( 478): &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; AndroidRuntime START &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; D/AndroidRuntime( 478): CheckJNI is ON D/AndroidRuntime( 478): --- registering native functions --- D/AndroidRuntime( 478): Shutting down VM D/dalvikvm( 478): Debugger has detached; object registry had 1 entries I/AndroidRuntime( 478): NOTE: attach of thread 'Binder Thread #3' failed D/Mms:app ( 220): getSmsNewMessageNotificationInfo: count=14, first addr=12345, thread_id=4 D/dalvikvm( 151): GC_EXPLICIT freed 391 objects / 22552 bytes in 65ms D/dalvikvm( 220): GC_EXPLICIT freed 926 objects / 44840 bytes in 73ms </code></pre> <p>So the SMS seems to be received by the emulator, but looks like the no intents are firing. What am I doing wrong here? After installing, do I have to somehow 'start' this receiver? Because when I install, I get</p> <pre><code> [2010-11-07 21:24:41 - SMSBroadcastReceiver] No Launcher activity found! [2010-11-07 21:24:41 - SMSBroadcastReceiver] The launch will only sync the application package on the device! </code></pre> <p>So I'm wondering if something's wrong here.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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