I am writing a code which has two buttons. On click of first button, the GSM network has to be disconnected and on click of second button, the GSM network has to be connected. I dont want to use Airplane Mode. Below is my code :
package com.example.airplane;
public class MainActivity extends Activity {
// constants
ServiceState tmpServc = new ServiceState();
Button togState;
Button newState;
final int STATE_POWER_OFF = 3;
final int STATE_IN_SERVICE = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
togState = (Button)findViewById(R.id.togState);
newState = (Button)findViewById(R.id.button1);
// set click event for button
togState.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tmpServc.setState(STATE_POWER_OFF);
}
});
newState.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tmpServc.setState(STATE_IN_SERVICE);
}
});
}
Kindly help me out in this. Or is there any better way other than this? Regards