set Flight Mode via Intent - Android Phone

Android examples for Phone:Airplane Mode

Description

set Flight Mode via Intent

Demo Code


//package com.java2s;

import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;

import android.provider.Settings;

public class Main {

    public static void setFlightMode(Context context, boolean isOpen) {
        ContentResolver resolver = context.getContentResolver();
        if (isOpen) {
            Settings.System.putString(resolver,
                    Settings.System.AIRPLANE_MODE_ON, "1");
            Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
            context.sendBroadcast(intent);
        } else {//from   w w w  .  j  av  a 2s  . co  m
            Settings.System.putString(resolver,
                    Settings.System.AIRPLANE_MODE_ON, "0");
            Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
            context.sendBroadcast(intent);
        }
    }
}

Related Tutorials