AirPlane ToggleButton???

Put your problem here if it does not fit any of the other categories.

AirPlane ToggleButton???

Postby shutup7742 » Tue Apr 19, 2011 4:32 pm

I am trying to use a ToggleButton to switch AirPlane mode on and off. I am not sure how to go about this.

My permissions are:

Code: Select all
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>

My .XML file looks like this:

Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView 
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ToggleButton 
android:id="@+id/Toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="On"
android:textOff="Off">
</ToggleButton>
</LinearLayout>

My Java has this for the toggle button:

Code: Select all
AirToggle = (ToggleButton) findViewById(R.id.Toggle);
    AirToggle.setOnClickListener(new OnClickListener(){
        public void onClick(View v){

        if (((ToggleButton)v).isChecked()){
            boolean isEnabled = Settings.System.getInt(context.getContentResolver(),Settings.System.AIRPLANE_MODE_ON, 0) == 1;
            if(isEnabled == false)
            {
            Settings.System.putInt(context.getContentResolver(),Settings.System.AIRPLANE_MODE_ON,1);                                Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
            intent.putExtra("state", 1);
            context.sendBroadcast(intent);
            }

            IntentFilter intentFilter = new IntentFilter("android.intent.action.SERVICE_STATE");

            BroadcastReceiver receiver = new BroadcastReceiver() {
                  @Override
                  public void onReceive(Context context, Intent intent) {
                        Log.d("AirplaneMode", "Service state changed");
                  }
            };

            context.registerReceiver(receiver, intentFilter);


            }

    };
});
}


Please help. :|

-Thanks. :mrgreen:
Check out our site: http://www.hot-app.com.
Make money online: http://www.cashcrate.com/1226485.
shutup7742
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Jan 29, 2011 1:14 am

Top

Re: AirPlane ToggleButton???

Postby shutup7742 » Tue Apr 19, 2011 9:00 pm

:D Figured it out I had to add
Code: Select all
context=getAppicationContext();
Check out our site: http://www.hot-app.com.
Make money online: http://www.cashcrate.com/1226485.
shutup7742
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Jan 29, 2011 1:14 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 18 guests