java - Android : sms recever is not working -


i writing sms receiver android code not working , there 1 here can please ? compiles when sms did not displayed supposed when using toast. 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 sms message passed in---         bundle bundle = intent.getextras();                 smsmessage[] msgs = null;         string messagereceived = "";                     if (bundle != null)         {             //---retrieve sms message received---            object[] pdus = (object[]) bundle.get("pdus");             msgs = new smsmessage[pdus.length];                (int i=0; i<msgs.length; i++){                 msgs[i] = smsmessage.createfrompdu((byte[])pdus[i]);                   messagereceived +="from "+ msgs[i].getoriginatingaddress();                 messagereceived+=" : ";                 messagereceived += msgs[i].getmessagebody().tostring();                 messagereceived += "\n";                     }               //---display new sms message---             toast.maketext(context, messagereceived, toast.length_short).show();         }                              }  } 


posted manifets make sure important parts of code available
manifets.xml :

    <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.example.homecontrolingbysms"     android:versioncode="1"     android:versionname="1.0" >      <uses-sdk         android:minsdkversion="8"         android:targetsdkversion="17" />     <uses-permission android:name="android.permission.send_sms"/>     <uses-permission android:name="android.permission.receive_sms"/>     <application         android:allowbackup="true"         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@style/apptheme" >         <activity             android:name="com.example.homecontrolingbysms.mainactivity"             android:label="@string/app_name" >             <intent-filter>                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>         <activity             android:name="com.example.homecontrolingbysms.door"             android:label="@string/app_name" >         </activity>          <activity             android:name="com.example.homecontrolingbysms.window"             android:label="@string/app_name" >          </activity>          <activity             android:name="com.example.homecontrolingbysms.light"             android:label="@string/app_name" >          </activity>      </application>  </manifest> 

register smsreceiver adding below code in menifest file

<receiver android:name="com.shreymalhotra.smsreceiver.smsreceiver">     <intent-filter>                 <action android:name="android.provider.telephony.sms_received" />     </intent-filter> </receiver> 

this links may you.

receiving sms on android app

http://shreymalhotra.me/blog/tutorial/receive-sms-using-android-broadcastreceiver-inside-an-activity/

please check it.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -