Java Code Examples for android.content.Intent.ACTION_AIRPLANE_MODE_CHANGED

The following are Jave code examples for showing how to use ACTION_AIRPLANE_MODE_CHANGED of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: amap   File: MIP_NetworkUtils.java   View Source Code Vote up 6 votes
/**
 * 飞行模式开关
 * 
 * @param setAirPlane
 */
public static void toggleAirplaneMode(Context context, boolean setAirPlane)
{
    ConnectivityManager connManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connManager != null)
    {
        Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, setAirPlane ? 1 : 0);
        // 广播飞行模式信号的改变,让相应的程序可以处理。
        // 不发送广播时,在非飞行模式下,Android 2.2.1上测试关闭了Wifi,不关闭正常的通话网络(如GMS/GPRS等)。
        // 不发送广播时,在飞行模式下,Android 2.2.1上测试无法关闭飞行模式。
        Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        // intent.putExtra("Sponsor", "Sodino");
        // 2.3及以后,需设置此状态,否则会一直处于与运营商断连的情况
        intent.putExtra("state", setAirPlane);
        context.sendBroadcast(intent);
    }
}
 
Example 2
Project: chargepreserver   File: CPService.java   View Source Code Vote up 6 votes
@Override
public void onDestroy() {
    if (created) {
        this.unregisterReceiver(batReceiver);
        Log.d(getClass().getSimpleName(), "Receiver unregistered");
        if (wl.isHeld()) {
            wl.release();
            Log.d(getClass().getSimpleName(), "WL released");
        }
    }

    boolean isEnabled = Settings.System.getInt(getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) == 1;
    if (isEnabled) {
        Log.d(getClass().getSimpleName(), "Turning airplanemode off");
        Settings.System.putInt(getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0);
        Intent reload = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        reload.putExtra("state", false);
        sendBroadcast(reload);
    }

    Log.d(getClass().getSimpleName(), "Charge Preserver service stopped");
    Toast.makeText(this.getApplicationContext(), "Service has been shutdown", Toast.LENGTH_SHORT).show();
    prefEditor.putBoolean("isService", false);
    prefEditor.commit();
}
 
Example 3
Project: buildAPKsApps   File: AirplaneModeSettingHandler.java   View Source Code Vote up 5 votes
private void setAirMode(boolean enabled) {
	// update setting
	Settings.System.putInt(mActivity.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, enabled ? 1 : 0);
	// notify change
	Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
	intent.putExtra("state", enabled);
	mActivity.sendBroadcast(intent);
}