1
0
mirror of https://github.com/danog/termux-api.git synced 2024-11-26 20:04:42 +01:00

Wifi API additions (#177)

* Added Wifi turn on/off methods

* Added Wifi toggle method
This commit is contained in:
Cem 2018-06-15 00:42:53 +03:00 committed by Fredrik Fornwall
parent 875d6ec4d5
commit 1689cfec08
3 changed files with 15 additions and 0 deletions

View File

@ -22,6 +22,7 @@
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />

View File

@ -168,6 +168,9 @@ public class TermuxApiReceiver extends BroadcastReceiver {
WifiAPI.onReceiveWifiScanInfo(this, context, intent);
}
break;
case "WifiEnable":
WifiAPI.onReceiveWifiEnable(this, context, intent);
break;
default:
TermuxApiLogger.error("Unrecognized 'api_method' extra: '" + apiMethod + "'");
}

View File

@ -112,4 +112,15 @@ public class WifiAPI {
});
}
static void onReceiveWifiEnable(TermuxApiReceiver apiReceiver, final Context context, final Intent intent) {
ResultReturner.returnData(apiReceiver, intent, new ResultReturner.ResultJsonWriter() {
@Override
public void writeJson(JsonWriter out) {
WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
boolean state = intent.getBooleanExtra("enabled", false);
manager.setWifiEnabled(state);
}
});
}
}