How to detect airplane mode in native app?

How to detect airplane mode in native app?

  

Hi,

Is there a built in function or supported plugin that can provide information regarding if "flight mode" on device is activated or not?

In app I need to know when flight mode is activated even if wi-fi is on.

Thank you.


But isn't the idea behind airplane mode that it shuts of everything including wifi? Are you really after detecting airplane mode, or do you need to know whether there's wifi but no internet?

Hi Killian.

The use case is that there is a wifi on a plane without internet - just local services. So as it is possible to have flight mode activated and wifi activated and connected to local network without internet we want to show different screens to the users. However currently we are using offline.js library but if wifi is poor or temporary lost connection the app should not switch to "flight mode screens" (lets call it that). 

Of course we can use workaround like manual switch inside the app (like demo app from OutSystems) but if it is possible to use native "flight mode" as a indicator it would be much better.

To know if airplane mode is on you would need to include a Cordova plugin in your app that checked that, using native code. unfortunately, as far as I can tell, currently there's no such plugin in the cordova listing. 

Hi João,

yes that what I was thinking and couldn't find any plugin so decided to ask :) I'll post here if I'll encounter any suitable plugin on github.

If WiFi is on, then airplane mode is not on. What you are referring to is "Lie-Fi", i.e. there's a network but no internet. See here for more on lie-fi and how to handle it.

Hi Killian,

There is a scenario when user activates a airplane mode and then reactivates wifi access - in this case he will have both wifi and airplane mode activated.



In this case how differ this (airplane mode and local network access) from normal "Lie-Fi" ?


Thank you.

Hi Mykola,

Even with Airplane mode ON, and Wi-Fi ON it is possible to have both no internet or full internet access... for the scenario you describe, wouldn't it be better to try and ping your own server (or other well known service) to see if it's accessible and decide which screens to show based on whether you can reach it or not?

Hi Jorge, 

That's exactly why it would be great to have access to "flight mode" status because it is only thing activated manually by the user and we can assume he is on local network. Otherwise even pinging our server can lead to false "no internet" scenario. 

I can't see how "flight mode" gives you any guarantees of anything... but maybe I'm just not understanding in what scenarios you want to provide set of screens A or set of screens B. 

Scenarios are simple - if it is a local network we show screen A if it is normal internet access 3G,4G or wi-fi we have a screen B. Pinging server or using offline.js library leads to situation when network is bad or it phone temporary loses connection and user is shown screen A and once network connection is restored switches back to B which is confusing. Same if we show user message like "you network is unavailable - try screen A and wise versa. So we can have in-app switch that explicitly says for example "I'm connected to local network" and then we show screen A until user turns the switch back to "Internet connection on". So in our case "Flight mode" will serve as that switch. 

Solution

Ok, got it.

The problem I see with using "Flight mode" as that switch is that it depends on your users' "correct" behaviour... For instance, I know people that simply set their phones to flight mode when they do not want to have calls coming through, that would disrupt your scenarios.

My suggestion would be to use any of the options you mention to (unobtrusively) provide a prompt for the said in-app switch.

For instance, if you don't detect internet connectivity for a while you might show a prompt with the "switch to B-screens" toggle, in a non-disruptive/ignorable way, and when you detect it again, show the reverse toggle. This way you wouldn't have to rely on users using the features of their phones like you want them to...

Out of curiosity, I did try and find how people are addressing this same use case and apparently it is possible to determine on Android, but there's no way of determining if an iOS device has Airplane Mode ON/OFF (the most common solution I found was the approach on Apple's Reachability sample, but still relies on checking connectivity so not exactly what you need)

Solution

Thanks for your links and suggestions, Jorge. It should help us to get right solution for our scenario.