Skip to content

Commit f8b68f3

Browse files
committed
Add method to check state of canWrite permission
1 parent a05db17 commit f8b68f3

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

android/src/main/java/com/devstepbcn/wifi/AndroidWifiModule.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import org.json.JSONException;
3737
import org.json.JSONObject;
3838

39+
import com.facebook.react.bridge.Promise;
40+
3941
public class AndroidWifiModule extends ReactContextBaseJavaModule {
4042

4143
//WifiManager Instance
@@ -91,6 +93,20 @@ public void loadWifiList(Callback successCallback, Callback errorCallback) {
9193
}
9294
}
9395

96+
//Returns a promise that resolves a boolean of wether or not the canWrite
97+
//permission has been granted
98+
@ReactMethod
99+
public void checkCanWrite(Promise promise) {
100+
boolean canWrite = true;
101+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N || Build.VERSION.RELEASE.toString().equals("6.0.1")) {
102+
// In versions >= 6.0.1, we no longer need to request permission to write to settings.
103+
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
104+
// In version 6.0.0, we need to request permission to write to settings in order to forceWifi.
105+
canWrite = Settings.System.canWrite(reactContext);
106+
}
107+
promise.resolve(canWrite);
108+
}
109+
94110
//Method to force wifi usage if the user needs to send requests via wifi
95111
//if it does not have internet connection. Useful for IoT applications, when
96112
//the app needs to communicate and send requests to a device that have no

0 commit comments

Comments
 (0)