diff --git a/.gitignore b/.gitignore index 4db771a..c380c39 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ .DS_Store /build /captures -.externalNativeBuild \ No newline at end of file +.externalNativeBuild +.project \ No newline at end of file diff --git a/README.md b/README.md index 3518487..862a899 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,43 @@ WifiUtils.withContext(getApplicationContext()) .start(); ``` +### Disconnect + +You can disconnect from the currently connected network. + +```java +WifiUtils.withContext(context) + .disconnect(new DisconnectionSuccessListener() { + @Override + public void success() { + Toast.makeText(MainActivity.this, "Disconnect success!", Toast.LENGTH_SHORT).show(); + } + + @Override + public void failed(@NonNull DisconnectionErrorCode errorCode) { + Toast.makeText(MainActivity.this, "Failed to disconnect: " + errorCode.toString(), Toast.LENGTH_SHORT).show(); + } + }); +``` + +### Disconnect and remove saved network configuration + +You can also remove the saved wifi network configuration. On Android 10, this will just simply disconnect (as wifi configuration's made by WifiUtils are no longer saved). +Notice: WifiUtils can't remove network configurations created by the user or by another app. + +```kotlin +WifiUtils.withContext(context) + .remove(SSID, object : RemoveSuccessListener { + override fun success() { + Toast.makeText(context, "Remove success!", Toast.LENGTH_SHORT).show() + } + + override fun failed(errorCode: RemoveErrorCode) { + Toast.makeText(context, "Failed to disconnect and remove: $errorCode", Toast.LENGTH_SHORT).show() + } + }) +``` + ### Enable Logging If you want to receive some extra logging info comming from WiFi Utils you can enable its logging capabilities with `WifiUtils.enableLog(true);` @@ -159,7 +196,6 @@ Damn You are required to set a few permissions in order for this lib to work cor ```xml - ``` ### Add it to your project diff --git a/sample/src/main/java/com/thanosfisherman/wifiutils/sample/MainActivity.java b/sample/src/main/java/com/thanosfisherman/wifiutils/sample/MainActivity.java index 0c7a1e0..c7ad9ae 100644 --- a/sample/src/main/java/com/thanosfisherman/wifiutils/sample/MainActivity.java +++ b/sample/src/main/java/com/thanosfisherman/wifiutils/sample/MainActivity.java @@ -63,7 +63,7 @@ private void connectWithWpa() { private void disconnect(final Context context) { WifiUtils.withContext(context) - .disconnectFrom(SSID, new DisconnectionSuccessListener() { + .disconnect(new DisconnectionSuccessListener() { @Override public void success() { Toast.makeText(MainActivity.this, "Disconnect success!", Toast.LENGTH_SHORT).show(); diff --git a/sample/src/main/java/com/thanosfisherman/wifiutils/sample/MainKotlinActivity.kt b/sample/src/main/java/com/thanosfisherman/wifiutils/sample/MainKotlinActivity.kt index 1eb6778..06d3561 100644 --- a/sample/src/main/java/com/thanosfisherman/wifiutils/sample/MainKotlinActivity.kt +++ b/sample/src/main/java/com/thanosfisherman/wifiutils/sample/MainKotlinActivity.kt @@ -11,6 +11,8 @@ import com.thanosfisherman.wifiutils.wifiConnect.ConnectionErrorCode import com.thanosfisherman.wifiutils.wifiConnect.ConnectionSuccessListener import com.thanosfisherman.wifiutils.wifiDisconnect.DisconnectionErrorCode import com.thanosfisherman.wifiutils.wifiDisconnect.DisconnectionSuccessListener +import com.thanosfisherman.wifiutils.wifiRemove.RemoveErrorCode +import com.thanosfisherman.wifiutils.wifiRemove.RemoveSuccessListener import kotlinx.android.synthetic.main.activity_main.* class MainKotlinActivity : AppCompatActivity() { @@ -23,8 +25,11 @@ class MainKotlinActivity : AppCompatActivity() { setContentView(R.layout.activity_main) ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), 555) WifiUtils.enableLog(true) + textview_ssid.text = SSID + textview_password.text = PASSWORD button_connect.setOnClickListener { connectWithWpa(applicationContext) } button_disconnect.setOnClickListener { disconnect(applicationContext) } + button_remove.setOnClickListener{ remove(applicationContext) } } private fun connectWithWpa(context: Context) { @@ -45,7 +50,7 @@ class MainKotlinActivity : AppCompatActivity() { private fun disconnect(context: Context) { WifiUtils.withContext(context) - .disconnectFrom(SSID, object : DisconnectionSuccessListener { + .disconnect(object : DisconnectionSuccessListener { override fun success() { Toast.makeText(context, "Disconnect success!", Toast.LENGTH_SHORT).show() } @@ -55,4 +60,17 @@ class MainKotlinActivity : AppCompatActivity() { } }) } + + private fun remove(context: Context) { + WifiUtils.withContext(context) + .remove(SSID, object : RemoveSuccessListener { + override fun success() { + Toast.makeText(context, "Remove success!", Toast.LENGTH_SHORT).show() + } + + override fun failed(errorCode: RemoveErrorCode) { + Toast.makeText(context, "Failed to disconnect and remove: $errorCode", Toast.LENGTH_SHORT).show() + } + }) + } } \ No newline at end of file diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 79af269..d926e8e 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -7,26 +7,57 @@ android:layout_height="match_parent" tools:context="com.thanosfisherman.wifiutils.sample.MainActivity"> + + + +