Disable flight mode in android 2.2 -
i working android app allows enabling of flight mode. enabling part working fine. problem arises when user exists/quits application. want flight mode disabled once user quits app. there possibility of doing programmatically or should user turn of setting manually?
if ((flightmode.ischecked())) { boolean isenabled = settings.system.getint(getcontentresolver(), settings.system.airplane_mode_on, 0) == 1; flag=1; toast.maketext(this, "flight mode on", toast.length_short).show(); if(isenabled == false) { settings.system.putint(getcontentresolver(), settings.system.airplane_mode_on,1); intent intent = new intent(intent.action_airplane_mode_changed); intent.putextra("state", 1); sendbroadcast(intent); } } else { settings.system.putint(getcontentresolver(), settings.system.airplane_mode_on,0); intent intent = new intent(intent.action_airplane_mode_changed); intent.putextra("state", 0); sendbroadcast(intent); toast.maketext(this, "flight mode off", toast.length_short).show(); }
and disable use code :
alt_bld .setmessage("are sure want exit?") alt_bld .setcancelable(true); alt_bld.setpositivebutton("yes", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog,int id) { if(flag==1) { settings.system.putint(getcontentresolver(), settings.system.airplane_mode_on,0); intent intent = new intent(intent.action_airplane_mode_changed); intent.putextra("state", 0); sendbroadcast(intent); } finish(); }
your code looks fine. make sure manifest contains:
<uses-permission android:name="write_settings" />
and system settings should stay way app sets them.
Comments
Post a Comment