1
1
2
2
# react-native-settings
3
3
4
- ## Still very much in Alpha!
4
+ ## Still very much in Alpha
5
5
6
6
We created this module to allow us to query for specific device settings.
7
7
For example we wanted to know if the GPS is on/off without using 'react-native'
@@ -16,8 +16,8 @@ This way we can prompt the user to go to the correct place in the settings
16
16
application and make sure our application is aware that the user disables/enables
17
17
a setting or denies/grants a permission.
18
18
19
- Currently we've only added a way to extract the 'location' setting.
20
- We will add more in the future based on our requirements.
19
+ Currently we've only added a way to extract the 'location' setting (and airplane mode on Android) .
20
+ We will add more in the future based on requirements.
21
21
22
22
[ ` react-native example ` ] ( https://github.com/rmrs/react-native-settings/tree/master/example ) for both Android and iOS.
23
23
@@ -30,29 +30,35 @@ We will add more in the future based on our requirements.
30
30
` $ react-native link react-native-settings `
31
31
32
32
#### Android
33
- In your manifest file under:
34
33
35
- ``` xml
36
- <application >
37
- ```
38
- add the following:
39
-
40
- ``` xml
41
- <receiver android : name =" io.rumors.reactnativesettings.receivers.GpsLocationReceiver" >
42
- <intent-filter >
43
- <action android : name =" android.location.PROVIDERS_CHANGED" />
44
- <category android : name =" android.intent.category.DEFAULT" />
45
- </intent-filter >
46
- </receiver >
47
-
48
- <receiver android : enabled =" true" android : name =" io.rumors.reactnativesettings.receivers.AirplaneModeReceiver" >
49
- <intent-filter >
50
- <action android : name =" android.intent.action.AIRPLANE_MODE" />
51
- </intent-filter >
52
- </receiver >
34
+ In your ` MainApplication.java ` file register the receivers:
35
+
36
+ ``` java
37
+ ...
38
+
39
+ import android.content.IntentFilter ;
40
+ import io.rumors.reactnativesettings.RNSettingsPackage ;
41
+ import io.rumors.reactnativesettings.receivers.GpsLocationReceiver ;
42
+ import io.rumors.reactnativesettings.receivers.AirplaneModeReceiver ;
43
+
44
+ ...
45
+
46
+ public class MainApplication extends Application implements ReactApplication {
47
+
48
+ ...
49
+
50
+ @Override
51
+ public void onCreate () {
52
+
53
+ ...
54
+
55
+ registerReceiver(new GpsLocationReceiver (), new IntentFilter (" android.location.PROVIDERS_CHANGED" ));
56
+ registerReceiver(new AirplaneModeReceiver (), new IntentFilter (" android.intent.action.AIRPLANE_MODE" ));
57
+ }
58
+ }
53
59
```
54
- ### Manual installation
55
60
61
+ ### Manual installation
56
62
57
63
#### iOS
58
64
@@ -64,22 +70,29 @@ add the following:
64
70
#### Android
65
71
66
72
1 . Open up ` android/app/src/main/java/[...]/MainApplication.java `
67
- - Add ` import io.rumors.reactnativesettings.RNSettingsPackage; ` to the imports at the top of the file
68
- - Add ` new RNSettingsPackage() ` to the list returned by the ` getPackages() ` method
73
+
74
+ - Add ` import io.rumors.reactnativesettings.RNSettingsPackage; ` to the imports at the top of the file
75
+ - Add ` new RNSettingsPackage() ` to the list returned by the ` getPackages() ` method
76
+
69
77
2 . Append the following lines to ` android/settings.gradle ` :
70
- ```
71
- include ': react-native-settings '
72
- project(': react-native-settings ').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-settings/android')
73
- ```
78
+
79
+ ``` java
80
+ include ' :react-native-settings'
81
+ project(' :react-native-settings' ). projectDir = new File (rootProject. projectDir, ' ../node_modules/react-native-settings/android' )
82
+ ```
83
+
74
84
3 . Insert the following lines inside the dependencies block in ` android/app/build.gradle ` :
75
- ```
76
- compile project(': react-native-settings ')
77
- ```
85
+
86
+ ``` java
87
+ implementation project(' :react-native-settings' )
88
+ ```
78
89
79
90
## Usage
80
- #### Android and iOS
81
91
82
- ##### Getting a setting:
92
+ ### Android and iOS
93
+
94
+ #### Getting a setting
95
+
83
96
``` javascript
84
97
import RNSettings from ' react-native-settings'
85
98
@@ -92,7 +105,7 @@ RNSettings.getSetting(RNSettings.LOCATION_SETTING).then(result => {
92
105
})
93
106
```
94
107
95
- #### Android only:
108
+ #### Android only
96
109
97
110
``` javascript
98
111
import RNSettings from ' react-native-settings'
@@ -107,6 +120,7 @@ RNSettings.getSetting(RNSettings.AIRPLANE_MODE_SETTING).then(result => {
107
120
```
108
121
109
122
##### Open settings application in a specific setting
123
+
110
124
``` javascript
111
125
import RNSettings from ' react-native-settings'
112
126
@@ -124,6 +138,7 @@ if (result === RNSettings.ENABLED) {
124
138
` ` `
125
139
126
140
##### Listen to setting change event (when applicable)
141
+
127
142
` ` ` javascript
128
143
import RNSettings from ' react-native-settings'
129
144
import { DeviceEventEmitter } from ' react-native'
0 commit comments