Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old April 19th, 2011, 10:35 AM   #1 (permalink)
Junior Member
 
Join Date: Feb 2011
Location: here
Posts: 15
 
Device(s): Droid
Thanks: 0
Thanked 0 Times in 0 Posts
Cry AirPlane ToggleButton???

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:

<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_SECURE_SETT INGS"/>
My .XML file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
androidrientation="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:

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.

shutup7742 is offline  
Reply With Quote
Sponsors
Old April 19th, 2011, 03:01 PM   #2 (permalink)
Junior Member
 
Join Date: Feb 2011
Location: here
Posts: 15
 
Device(s): Droid
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Figured it out I had to add context=getAppicationContext();
shutup7742 is offline  
Reply With Quote
Old April 20th, 2011, 07:10 AM   #3 (permalink)
Junior Member
 
Join Date: Sep 2010
Posts: 23
 
Device(s):
Thanks: 0
Thanked 2 Times in 1 Post
Default

When I try to use Settings.System I get an Eclipse error saying it can't be resolved. This is the code:

boolean isEnabled = Settings.System.getInt(getApplicationContext().get ContentResolver( ),Settings.System.AIRPLANE_MODE_ON, 0) == 1;

Can anyone see where I'm going wrong please?
shadowy is offline  
Reply With Quote
Old April 20th, 2011, 01:57 PM   #4 (permalink)
Junior Member
 
Join Date: Feb 2011
Location: here
Posts: 15
 
Device(s): Droid
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by shadowy View Post
When I try to use Settings.System I get an Eclipse error saying it can't be resolved. This is the code:

boolean isEnabled = Settings.System.getInt(getApplicationContext().get ContentResolver( ),Settings.System.AIRPLANE_MODE_ON, 0) == 1;

Can anyone see where I'm going wrong please?
Did you try to add the follwing:

context=getAppicationContext();?


you should try to put:

context=getAppicationContext();
boolean isEnabled = Settings.System.getInt(getApplicationContext().get ContentResolver( ),Settings.System.AIRPLANE_MODE_ON, 0) == 1;
shutup7742 is offline  
Reply With Quote
Reply

Bookmarks

Tags
airplaine mode, android sdk, eclipse, toggle button, togglebutton


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 11:40 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo