Okay so now I can turn on开发者_运维问答 the airplane mode (thanks to the help of Stealth Rabbi in my other post. AirPlane ToggleButton?). The problem now is when I click my toggle button to turn Airplane mode off nothing happens, exept for the toggle button switches from on to off but does not change the state of airplane mode. Any suggestions are appretiated.
-Thanks
You have to broadcast the ACTION_AIRPLANE_MODE_CHANGED Intent to notify the system that you changed the settings
Okay I figured it out. '
public void onClick(View v){
context = getApplicationContext();
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);
}
}else
{
Settings.System.putInt(context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON,0);
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra("state", 0);
context.sendBroadcast(intent);
}
};
});`
In the else part of the code I changed the number one to number 0.
精彩评论