Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid : sms receiver is not working
    primarykey
    data
    text
    <p>I am writing an sms receiver android code but it is not working. It compiles will but when I get an sms it did not displayed as supposed to be when using Toast. This is my code:</p> <pre><code>package com.example.homecontrolingbysms; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.telephony.SmsMessage; import android.widget.Toast; public class SmsReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { //---get the SMS message passed in--- Bundle bundle = intent.getExtras(); SmsMessage[] msgs = null; String messageReceived = ""; if (bundle != null) { //---retrieve the SMS message received--- 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]); messageReceived +="From "+ msgs[i].getOriginatingAddress(); messageReceived+=" : "; messageReceived += msgs[i].getMessageBody().toString(); messageReceived += "\n"; } //---display the new SMS message--- Toast.makeText(context, messageReceived, Toast.LENGTH_SHORT).show(); } } } </code></pre> <p>I also posted manifest to make sure all important parts of code are available <br> manifest.xml:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.homecontrolingbysms" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /&gt; &lt;uses-permission android:name="android.permission.SEND_SMS"/&gt; &lt;uses-permission android:name="android.permission.RECEIVE_SMS"/&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name="com.example.homecontrolingbysms.MainActivity" 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;activity android:name="com.example.homecontrolingbysms.Door" android:label="@string/app_name" &gt; &lt;/activity&gt; &lt;activity android:name="com.example.homecontrolingbysms.Window" android:label="@string/app_name" &gt; &lt;/activity&gt; &lt;activity android:name="com.example.homecontrolingbysms.Light" android:label="@string/app_name" &gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </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.
 

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