Commit 65374808 authored by joaspacce's avatar joaspacce Committed by Mehdi Achour

feat: Add isAirPlaneMode function (#524)

* Add isAirPlaneModeOne function

* changelog update

* added notes

* pr changes

* few more pr changes
parent bf54cd04
## Release Notes
### 0.25
* Added `isAirPlaneMode()` (https://github.com/rebeccahughes/react-native-device-info/pull/524)
### 0.24.3
* Support React Native Windows 0.57, minimal version is now 10.0.14393 for the target platform
......
......@@ -230,6 +230,7 @@ import DeviceInfo from 'react-native-device-info';
| [getUserAgent()](#getuseragent) | `string` | ✅ | ✅ | ❌ | 0.7.0 |
| [getVersion()](#getversion) | `string` | ✅ | ✅ | ✅ | ? |
| [is24Hour()](#is24hour) | `boolean` | ✅ | ✅ | ✅ | 0.13.0 |
| [isAirPlaneMode()](#isairplanemode) | `Promise<boolean>` | ❌ | ✅ | ❌ | 0.25.0 |
| [isEmulator()](#isemulator) | `boolean` | ✅ | ✅ | ✅ | ? |
| [isPinOrFingerprintSet()](#ispinorfingerprintset) | (callback)`boolean` | ✅ | ✅ | ✅ | 0.10.1 |
| [isTablet()](#istablet) | `boolean` | ✅ | ✅ | ✅ | ? |
......@@ -792,6 +793,23 @@ const is24Hour = DeviceInfo.is24Hour(); // true
---
### isAirPlaneMode()
Tells if the device is in AirPlaneMode.
**Examples**
```js
DeviceInfo.isAirPlaneMode().then(airPlaneModeOn => {
// false
});
```
**Notes**
> * This only works if the remote debugger is disabled.
---
### isEmulator()
Tells if the application is running in an emulator.
......
......@@ -17,6 +17,7 @@ import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.os.BatteryManager;
import android.provider.Settings;
import android.provider.Settings.Secure;
import android.webkit.WebSettings;
import android.telephony.TelephonyManager;
......@@ -220,6 +221,17 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
p.resolve(batteryLevel);
}
@ReactMethod
public void isAirPlaneMode(Promise p) {
boolean isAirPlaneMode;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
isAirPlaneMode = Settings.System.getInt(this.reactContext.getContentResolver(),Settings.System.AIRPLANE_MODE_ON, 0) != 0;
} else {
isAirPlaneMode = Settings.Global.getInt(this.reactContext.getContentResolver(),Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
}
p.resolve(isAirPlaneMode);
}
public String getInstallReferrer() {
SharedPreferences sharedPref = getReactApplicationContext().getSharedPreferences("react-native-device-info", Context.MODE_PRIVATE);
return sharedPref.getString("installReferrer", null);
......@@ -284,7 +296,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
constants.put("apiLevel", Build.VERSION.SDK_INT);
constants.put("deviceLocale", this.getCurrentLanguage());
constants.put("deviceCountry", this.getCurrentCountry());
constants.put("uniqueId", Secure.getString(this.reactContext.getContentResolver(), Secure.ANDROID_ID));
constants.put("uniqueId", Settings.Secure.getString(this.reactContext.getContentResolver(), Settings.Secure.ANDROID_ID));
constants.put("systemManufacturer", Build.MANUFACTURER);
constants.put("bundleId", packageName);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
......
......@@ -41,6 +41,7 @@ declare const _default: {
getFreeDiskStorage: () => number;
getBatteryLevel: () => Promise<number>;
isLandscape: () => boolean;
isAirPlaneMode: () => Promise<boolean>;
};
export default _default;
......@@ -242,5 +242,8 @@ export default {
isLandscape: function() {
const { height, width } = Dimensions.get('window');
return width >= height;
}
},
isAirPlaneMode: function() {
return RNDeviceInfo.isAirPlaneMode();
}
};
......@@ -42,4 +42,5 @@ declare module.exports: {
getFreeDiskStorage: () => number,
getBatteryLevel: () => Promise<number>,
isLandscape: () => boolean,
isAirPlaneMode: () => Promise<boolean>,
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment