I want my program to be able to receive sms from a special number("+9856874236").
I want application to be recive SMS ,if the SMS is contain "enable wifi" ,then change wifi to enable
i 'm using this code but it working crash??
MainActivity
package com.example.sms;
import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
static TextView messageBox;
static String x="";
static Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
messageBox=(TextView)findViewById(R.id.messageBox);
check();
}
//How to used other or many activity
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public static void updateMessageBox(String msg,String from)
{
messageBox.append(msg);
//Get parent phone number from database
//check parent number with ...
if(msg.equals("enable wifi"))
{
x="yes";
MainActivity objSampleClass = new MainActivity();
objSampleClass.check();
}
//context.startActivity(new Intent(context, MainActivity.class));
//Intent i=new Intent(context, p1.class);
//context.startActivity(i);
}
public void check()
{
if(x.equals("yes"))
{
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(true);
}
else
{
}
}
}
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sms"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.sms.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>
<receiver android:name="com.example.sms.TextMessageReceiver" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<activity
android:name="com.example.sms.Test"
android:label="@string/title_activity_test" >
</activity>
</application>
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" >
</uses-permission>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" >
</uses-permission>
</manifest>