-1

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

trueblue
  • 188
  • 4
  • 17
  • Why you are using two button? you can also use toggle button or checkbox... – Niranj Patel Aug 14 '13 at 06:27
  • Thanks but actually I am using this to check the hot swapping of sim card. First button "Eject First Sim" will disconnect the sim from Network. Then sim is replaced with other sim in the slot. Then second button, "Detect Second Sim" will connect the second sim to the network without going through power cycle or flight mode. – trueblue Aug 14 '13 at 06:39
  • have a look at http://stackoverflow.com/questions/11395786/android-set-service-state – Anand Tiwari Aug 14 '13 at 06:41

0 Answers0