Start android Activity after receiving sms -


application starts , runs service in background. want run activity, after receiving specific text phone number

receive sms java class follows,

receivesms.java

public class receivesms  extends broadcastreceiver {      boolean sendsms;     string mobileno;     string varmessagebody; @override public void onreceive(context context, intent intent) {      bundle bundle = intent.getextras();         smsmessage[] msgs = null;         string str = "";         if (bundle != null) {             object[] pdus = (object[]) bundle.get("pdus");             msgs = new smsmessage[pdus.length];             (int = 0; < msgs.length; i++) {                 msgs[i] = smsmessage.createfrompdu((byte[]) pdus[i]);                 str += "sms " + msgs[i].getoriginatingaddress();                 mobileno = msgs[i].getoriginatingaddress();                 str += " :";                 str += msgs[i].getmessagebody().tostring();                 varmessagebody = msgs[i].getmessagebody().tostring();                 str += "\n";                 mobileno = msgs[i].getoriginatingaddress();              }             if (varmessagebody.startswith("start")) {                 intent intenthome = new intent(context,simpleactivity.class);                 intenthome.setflags(intent.flag_activity_new_task);                 context.startactivity(intenthome);              }          }    } 

}

simple activity class follows

public class simpleactivity extends activity{  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main); }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.main, menu);     return true; } 

}

this manifest

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.androidautostartup" android:versioncode="1" android:versionname="1.0" > <uses-permission android:name="android.permission.receive_sms"></uses-permission> <uses-permission android:name="android.permission.receive_boot_completed" > </uses-permission> <uses-sdk android:minsdkversion="8" android:targetsdkversion="18" />  <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <receiver android:name=".bootcomplete" android:enabled="true" android:exported="false" > <intent-filter android:priority="99999"> <action android:name="android.intent.action.boot_completed" /> </intent-filter> </receiver> <receiver android:name=".receivesms"> <intent-filter android:priority="99999"> <action android:name="android.provider.telephony.sms_recieved"></action> </intent-filter> </receiver> <service android:name=".autostartup" > </service> <activity android:name="com.example.androidautostartup">    </activity> <activity android:name="com.example.androidautostartup.simpleactivity"> </activity> <activity android:name="com.example.androidautostartup.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> </application> </manifest> 

please can solve does't run simple activity after receiving "start" sms message.

you need add simpleactivity androidmanifest.


Comments