I have code in my application that detects if Wi-Fi is actively connected. That code triggers a RuntimeException if airplane mode is enabled. I would like to display a separate error message when in this mode anyway. How can I reliably detect if an Android device is in airplane mode?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How can I create this custom Bottom Navigation on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
in order to get rid of the the depreciation complaint (when targeting API17+ and not caring too much about the backward compatibility), one has to compare with
Settings.Global.AIRPLANE_MODE_ON
:when considering lower API:
In Oreo please do not use the airplane mode broadCastReceiver. it is an implicit intent. it has been removed. Here is the current exceptions list. its not currently on the list so should fail to receive data. Consider it dead.
as stated by another user above use the following code:
From API Level - 17
From here :
Static Broadcast Receiver
Manifest code:
Java code: Broadcast Receiver java file
OR
Dynamic Broadcast Receiver
Java code: Activity java file
Register broadcast receiver on application open no need to add code in manifest if you take an action only when your activity open like check airplane mode is on or off when you access the internet etc
Java code: Broadcast Receiver java file