Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions android/src/main/java/com/devstepbcn/wifi/AndroidWifiModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.json.JSONException;
import org.json.JSONObject;

import com.facebook.react.bridge.Promise;

public class AndroidWifiModule extends ReactContextBaseJavaModule {

//WifiManager Instance
Expand Down Expand Up @@ -91,6 +93,20 @@ public void loadWifiList(Callback successCallback, Callback errorCallback) {
}
}

//Returns a promise that resolves a boolean of wether or not the canWrite
//permission has been granted
@ReactMethod
public void checkCanWrite(Promise promise) {
boolean canWrite = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N || Build.VERSION.RELEASE.toString().equals("6.0.1")) {
// In versions >= 6.0.1, we no longer need to request permission to write to settings.
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// In version 6.0.0, we need to request permission to write to settings in order to forceWifi.
canWrite = Settings.System.canWrite(reactContext);
}
promise.resolve(canWrite);
}

//Method to force wifi usage if the user needs to send requests via wifi
//if it does not have internet connection. Useful for IoT applications, when
//the app needs to communicate and send requests to a device that have no
Expand Down