Application starts and runs as a service in background. I want to run an Activity, after receiving specific text from any phone number
Receive SMS java class as 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];
for (int i = 0; i < msgs.length; i++) {
msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
str += "SMS from " + 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 as 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 the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
This is my 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 anyone can solve this it does't run simple activity after receiving the "START" sms message.
You need to add the SimpleActivity to your AndroidManifest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With