Open In App

How to Check Airplane Mode State in Android Programmatically?

Last Updated : 28 Jul, 2021
Like Article

Airplane Mode is often seen in action during flights, avoiding calls, or rebooting the network on mobiles, tablets, and laptops. Airplane mode is a standalone mode where the device turns down the radio communications. These may include Wifi, GPS, Telephone Network, Hotspot depending upon the year of manufacture, brand, and location of purchase of the device, but not the Bluetooth. Applications supporting streaming might require internet connectivity and needs to stay updated on the state of Internet Connection. While Airplane Mode impacts internet connectivity, such applications would require alternatives to handle such an instance. Through this article, we will show you how you could programmatically check the Airplane Mode State.

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. We demonstrated the application in Kotlin, so make sure you select Kotlin as the primary language while creating a New Project.

Step 2: Working with the activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. Create a Button in the layout file.


<?xml version="1.0" encoding="utf-8"?>

Step 3: Working with the MainActivity.kt file

Go to the file and refer to the following code. Below is the code for the file. Comments are added inside the code to understand the code in more detail. Below is the code to check if Airplane Mode State.


import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.widget.Button
import android.widget.Toast
import androidx.annotation.RequiresApi
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        // Find the button from the layout file
        // and add functionality to it
        val btn = findViewById<Button>(
        btn.setOnClickListener {
            // Get the value of AIRPLANE MODE 
            // from the system settings.
            // This is an Integer. Airplane Mode 
            // is ON is its 1 and 0 otherwise.
            // Toast the message (off/on)
            if(Settings.System.getInt(contentResolver, Settings.Global.AIRPLANE_MODE_ON, 0) == 0){
            } else {


Check if the Airplane Mode is turned off. Now click the button. We shall get a message that it is turned off. Now turn on the Airplane Mode. Return to the activity and again click the button. We shall get a message that it is turned on.


Useful Tip:

Note that we cannot change the state of the Airplane Mode programmatically. We have a provision to change it only if the application is a System Application. This can be done by adding permission to write settings in the Manifest file and calling a putInt() function in the Settings.System.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads