Git Product home page Git Product logo

wifiutils's Introduction

WifiUtils

Maven Central Hex.pm


🚨Attention:🚨

For Android versions 10 and newer: WiFiUtils is currently using the Network request API (IoT API) for connecting to wifi networks which scopes the internet connectivity only to the app that requested it. There are plans to support WiFI Suggestion API in the future which overcomes this issue. For further info read the official docs here and take a look at the discussion thread here

WiFiUtils is a library that provides a set of convenience methods for managing WiFi State, WiFi Scan, And WiFi Connection to Hotspots. If you have ever worked with WifiManager you should know how painful it is to make a simple wifi network scan or even worse to connect to a hotspot programmatically. So that's what this library is all about. To make it easier for me and hopefully for other developers as well to do those kind of tasks programmatically via a friendlier API.

Add it to your project

Add the following to your app module build.gradle file

    dependencies {
       implementation("io.github.thanosfisherman.wifiutils:wifiutils:1.6.6")
    }

Apps using this library


Enabling/Disabling WiFi

turn on device's wifi using the following:

 WifiUtils.withContext(getApplicationContext()).enableWifi(this::checkResult);

Where checkResult could be a custom-defined method of your own that would deal accordingly in each situation. For Example:

  private void checkResult(boolean isSuccess)
  {
       if (isSuccess)
           Toast.makeText(MainActivity.this, "WIFI ENABLED", Toast.LENGTH_SHORT).show();
       else
           Toast.makeText(MainActivity.this, "COULDN'T ENABLE WIFI", Toast.LENGTH_SHORT).show();
  }

If you don't want to deal with call backs you can also call enableWifi method like so.

 WifiUtils.withContext(getApplicationContext()).enableWifi();

Similarly you can turn off the wifi using this:

WifiUtils.withContext(getApplicationContext()).disableWifi();

Scanning for WiFi Networks

You can easily perform a WiFi Network scan like so:

WifiUtils.withContext(getApplicationContext()).scanWifi(this::getScanResults).start();

private void getScanResults(@NonNull final List<ScanResult> results)
{
    if (results.isEmpty())
    {
        Log.i(TAG, "SCAN RESULTS IT'S EMPTY");
        return;
    }
    Log.i(TAG, "GOT SCAN RESULTS " + results);
}

Connecting to WiFi Networks

Now lets get to the interesting stuff. You can connect to any WiFi network programmatically knowing only SSID and WPA/WPA2 key:

  WifiUtils.withContext(getApplicationContext())
          .connectWith("JohnDoeWiFi", "JohnDoePassword")
          .setTimeout(40000)
          .onConnectionResult(new ConnectionSuccessListener() {
              @Override
              public void success() {
                  Toast.makeText(MainActivity.this, "SUCCESS!", Toast.LENGTH_SHORT).show();
              }

              @Override
              public void failed(@NonNull ConnectionErrorCode errorCode) {
                  Toast.makeText(MainActivity.this, "EPIC FAIL!" + errorCode.toString(), Toast.LENGTH_SHORT).show();
              }
          })
          .start();

There are also a few other options that would allow you to do the same job but first let's move the ConnectionSuccessListener from above into its own separate field named successListener so that we can save some space

    private ConnectionSuccessListener successListener = new ConnectionSuccessListener() {
        @Override
        public void success() {
            Toast.makeText(MainActivity.this, "SUCCESS!", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void failed(@NonNull ConnectionErrorCode errorCode) {
            Toast.makeText(MainActivity.this, "EPIC FAIL!" + errorCode.toString(), Toast.LENGTH_SHORT).show();
        }
    };

Connecting with SSID, BSSID and WPA/WPA2 key:

 WifiUtils.withContext(getApplicationContext())
                      .connectWith("MitsarasWiFi", "AB:CD:EF:12:34:56", "MitsarasPassword123")
                      .onConnectionResult(successListener)
                      .start();

Lastly WifiUtils can also connect using a specified scanResult after a WiFi Scan is complete, for example:

WifiUtils.withContext(getApplicationContext())
                     .connectWithScanResult("MitsarasPasword123", scanResults -> scanResults.get(0))
                     .onConnectionResult(successListener)
                     .start();

The above example will perform a WiFi Scan and connectWithScanResult will return a List<ScanResult> scanResults with all the available WiFi networks around. The method then expects you to Return a single scanResult out of the list of results of your choice so that it can try to connect to it. The rest is pretty much the same.

Canceling an ongoing connection

You have two options to cancel a connection in progress.

  • If Connection takes too long to complete and just hangs in there without calling back onConnectionResult You can specify a TimeOut in milliseconds.
WifiUtils.withContext(getApplicationContext())
                     .connectWith("MitsarasWiFi", "MitsarasPassword123")
                     .setTimeout(15000)
                     .onConnectionResult(this::checkResult)
                     .start();

The Connection will fail in 15 seconds. The default timeOut is 30 seconds.

  • You can also cancel an ongoing connection immediately using the following:
 WifiConnectorBuilder.WifiUtilsBuilder builder = WifiUtils.withContext(getApplicationContext());
 builder.connectWith("MitsarasWiFi", "MitsarasPassword123")
 .onConnectionResult(this::checkResult)
 .start();
 builder.cancelAutoConnect();

Connecting with WPS keys.

On Androids 5.0 and greater there is also an option to connect using WPS keys. This library makes it easier and safer to connect using WPS than the stock android API.

WifiUtils.withContext(getApplicationContext())
                     .connectWithWps("d8:74:95:e6:f5:f8", "51362485")
                     .onConnectionWpsResult(this::checkResult)
                     .start();

Disconnect

You can disconnect from the currently connected network.

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.

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 coming from WiFi Utils you can enable its logging capabilities with WifiUtils.enableLog(true);

You can also choose to send the logs to your own custom logger.

WifiUtils.forwardLog(new Logger() {
            @Override
            public void log(int priority, String tag, String message) {
                Timber.tag(tag).log(priority, message);
            }
        });

Permissions

Damn You are required to set a few permissions in order for this lib to work correctly :( Also please check this issue

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <!-- for Android 6 and above -->

Contributing?

There are a few more things left to be covered in this tutorial. Hopefully I will improve upon this in the future.

Feel free to add/correct/fix something to this library, I will be glad to improve it with your help.

Please have a look at the Contributing Guide before making a Pull Request.

License

License

Copyright 2021 Thanos Psaridis

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

wifiutils's People

Contributors

ahmetturk avatar amrsaalah avatar asantana48 avatar astroa7m avatar chintanrathod avatar eliaslecomte avatar gamebrina avatar hernandazevedo avatar kaha6uc avatar mafanwei avatar rlesniak avatar thanosfisherman avatar z3ntu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wifiutils's Issues

Working on android 8

Can't use the library. After clicking run in android studio it throws a error.
Big one....

Activity has leaked IntentReceiver

Hello man, first of all , congrats for lib, it's very helpful.
I have a problem when perform a search or enable wifi. If I perform these operations a bit faster I catch a leak error, here is the stack trace:

Activity com.example.wificonnectionmanager.view.wifilist.WifiListActivity has leaked IntentReceiver com.thanosfisherman.wifiutils.wifiScan.WifiScanReceiver@3d4faf that was originally registered here. Are you missing a call to unregisterReceiver()? android.app.IntentReceiverLeaked: Activity com.example.wificonnectionmanager.view.wifilist.WifiListActivity has leaked IntentReceiver com.thanosfisherman.wifiutils.wifiScan.WifiScanReceiver@3d4faf that was originally registered here. Are you missing a call to unregisterReceiver()? at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:903) at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:704) at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1741) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1721) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1715) at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:496) at com.thanosfisherman.wifiutils.ConnectorUtils.registerReceiver(ConnectorUtils.java:144) at com.thanosfisherman.wifiutils.WifiUtils$1.onWifiEnabled(WifiUtils.java:78) at com.thanosfisherman.wifiutils.wifiState.WifiStateReceiver.onReceive(WifiStateReceiver.java:28) at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:866) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5259) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)

These leak error occurs when I perform operations finish activity and than reopen it.
I saw in code that you have unregistered the receivers, so I have no idea what is causing the problem.

UnknownHostException after switch WIFI

Hello, after I switch to another WiFi (with internet connection) and make a connection to my server, it show an error
java.net.UnknownHostException: Unable to resolve host "xxxx": No address associated with hostname

But when I closed my apps and open via browser, the address is accessible.
Any suggestion ?

Android 10 support. Testers needed

Please report any connectivity issues related to Android 10 here.

WiFiUtils now has a basic support for Android 10 thanks to the contribution #46 of @eliaslecomte

Hopefully owners of Android 10 devices will help us fix potential bugs.

error handling

hello. After used your library. I am confusing that how to implement error handling when connect to hotspot. May be connection fail ( for some reason). So i want to get this exception.
Plz help me how to implement that? Thanks you

mWifiManager.startScan() returns false

This call in WifiUtils.java line 88 returns true, when i load WifiUtils from Github and run:

private void connectWithWpa() {
    WifiUtils.withContext(getApplicationContext()).scanWifi(this::getScanResults).start();
}

private void getScanResults(@NonNull final List<ScanResult> results)
{
    if (results.isEmpty())
    {
        return;
    }
}

When I run the same code in my project using WifiUtils as library it returns false, so i never get any scanresults.

Crash when trying to connect to secure network with no password

java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.wifi.SCAN_RESULTS flg=0x4000010 } in com.thanosfisherman.wifiutils.wifiScan.WifiScanReceiver@c0dcff7
    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:876)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5258)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:940)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:735)
 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
    at com.thanosfisherman.wifiutils.ConfigSecurities.getWifiConfiguration(ConfigSecurities.java:119)
    at com.thanosfisherman.wifiutils.ConnectorUtils.connectToConfiguredNetwork(ConnectorUtils.java:234)
    at com.thanosfisherman.wifiutils.ConnectorUtils.connectToWifi(ConnectorUtils.java:163)
    at com.thanosfisherman.wifiutils.WifiUtils$2.onScanResultsReady(WifiUtils.java:137)
    at com.thanosfisherman.wifiutils.wifiScan.WifiScanReceiver.onReceive(WifiScanReceiver.java:20)
    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:866)
    at android.os.Handler.handleCallback(Handler.java:739) 
    at android.os.Handler.dispatchMessage(Handler.java:95) 
    at android.os.Looper.loop(Looper.java:135) 
    at android.app.ActivityThread.main(ActivityThread.java:5258) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:940) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:735) 

Sometime connect ,sometime not

I face an issue that when I implement the first time it's work fine but on the next day every time I got Epic fail. Can you help me out?

Not connecting on Oreo

I am connecting to wifi with its name and password

WifiUtils.withContext(context)
            .connectWith(ssid, password)
            .onConnectionResult(::onConnectionResult)
            .start()

Then I got this message in LogCat:

E/WifiConfigManager: UID 10345 does not have permission to update configuration "5ui5ide"-WPA_PSK

And Wi-Fi is not connected. This problem appears on Android 8 and 9

Handling configuration changes

Is it possible to stop running connection attempts or wifi scans, when a configuration change happens in my app? Because as fragments are destroyed on configuration changes, running wifi tasks return to an invalid environment and my app crashes.

In a few times, Scan Results are empty

Hi, Thank you very much for your effort, this library is very useful.

But sometimes I am facing a problem. At first, wifi scan result list is greater than 0. And I am trying
second, third... everything is OK. but when I do fourth try I am getting error below

WifiUtils: START SCANNING....
I/Result: SCAN RESULTS IT'S EMPTY
D/WifiUtils: WifiUtils: ERROR COULDN'T SCAN

After that, whenever I try to bring scan results, list size is 0. But If I load my fragment again, scan results are running well.

So, why sometimes scan results are empty ?

GPS is always open.

Would you help me?

I am using scanWifi() method in a Fragment.

private void scanWifi() {
if(getContext()!=null)
WifiUtils.withContext(getContext()).scanWifi(this::getScanResults).start();
}

private void getScanResults(@nonnull final List results) {
if (results.isEmpty()) {
Log.i("Result", "SCAN RESULTS IT'S EMPTY");
SnackBarMessageUtil.showErrorMessageWithAction(view, "RESULT IS EMPTY")
.setAction("TRY AGAIN", view -> scanWifi()).setActionTextColor(Color.WHITE)
.show();
return;
}
Log.i("Result", "GOT SCAN RESULTS " + results);
SnackBarMessageUtil.showSuccessMessage(view, "RESULT IS SUCCESSFUL");
}

ANR Error

.scanWifi().start() after an exception is thrown

03-11 09:17:32.961 22609-22609/com.mzydz.publish I/System.out: wifiNamezuojiedianshang1
03-11 09:17:32.961 22609-22609/com.mzydz.publish I/System.out: wifiNameMZY-5G
03-11 09:17:32.961 22609-22609/com.mzydz.publish I/System.out: wifiNameIP-COM_306C30
03-11 09:17:32.961 22609-22609/com.mzydz.publish I/System.out: wifiNamezckj
03-11 09:17:32.961 22609-22609/com.mzydz.publish I/System.out: wifiNameMZY
03-11 09:17:32.961 22609-22609/com.mzydz.publish I/System.out: wifiNameZCKJ-Wifi
03-11 09:17:39.162 22609-22609/com.mzydz.publish E/ANR_LOG: >>> msg's executing time is too long
03-11 09:17:39.162 22609-22609/com.mzydz.publish E/ANR_LOG: Blocked msg = { when=-6s220ms what=0 target=android.app.ActivityThread$H callback=android.app.LoadedApk$ReceiverDispatcher$Args } , cost = 6220 ms
03-11 09:17:39.162 22609-22609/com.mzydz.publish E/ANR_LOG: >>>Current msg List is:
03-11 09:17:39.162 22609-22609/com.mzydz.publish E/ANR_LOG: Current msg <1> = { when=-4s2ms what=1 target=com.loc.e$c }
03-11 09:17:39.162 22609-22609/com.mzydz.publish E/ANR_LOG: Current msg <2> = { when=+377ms what=132 target=android.app.ActivityThread$H }
03-11 09:17:39.162 22609-22609/com.mzydz.publish E/ANR_LOG: >>>CURRENT MSG DUMP OVER<<<

scan stop immediately

Basicly, most of phone can scan wifi's normally.

but some of phone get COULDN'T SCAN error and stop scam immediately.
i cannot find any solution, i cannot gathering detail log. i stuck at here..

D/WifiUtils: WifiUtils: WIFI ENABLED...
D/WifiUtils: WifiUtils: START SCANNING....
I/ROCATEER_LOG - (WifiSelectActivity.java:140) [getScanResults]: SCAN RESULTS IT'S EMPTY
D/WifiUtils: WifiUtils: ERROR COULDN'T SCAN

is there any solution or hint for this error?

Disconnect from connected network without disabling Wi-Fi?

How can I disconnect from a connected network without disabling Wi-Fi?

Right now I'm disconnecting with default SDK methods:

WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(
    Context.WIFI_SERVICE
);
wifiManager.disconnect();

Hotspot connected callback immediately executed when input password and to connect.

  1. Add new feature to connect hotspot which is not need password.(sorry,it's ok)
  2. Please add wifi connecting status to do callback, actually we need update UI to show WiFi status. For example ,to tell users we are connecting ,we has saved password, we have disconnected, the password is not correct and so on.
  3. Find bugs that I connect WiFi hotspot at once, this success connected callback function has executed on mt8163 Android 6.0 although password incorrect.
    That's all ,
    Best wishes!

Callback for timeout in method .connectWithScanResult()

Short Description

Need a callback for timeout, Then chance to reconnect based on option available. Provide callback for timeout.
Give a brief description of what the issue is
Need a callback for timeout, Then chance to reconnect based on option available. Provide callback for timeout.

Steps to reproduce

What are the steps to reproduce the issue? Post some code if possible.

Resulted in

What is the result of the above steps? E.g The lib crashes with NullPointerException

Expected Results

What should the expected results be? E.g The lib should have worked without crashing.

Android 7.0 Connectivity issue

Hi. When I use a device with android 7.1.1 it connects successfully but with a device having an OS version 7.0 it does not connect.. Any advice regarding this please. Location service is enabled.

ANR ERROR

.scanWifi().start() after an exception is thrown

03-11 09:17:32.961 22609-22609/com.mzydz.publish I/System.out: wifiNamezuojiedianshang1
03-11 09:17:32.961 22609-22609/com.mzydz.publish I/System.out: wifiNameMZY-5G
03-11 09:17:32.961 22609-22609/com.mzydz.publish I/System.out: wifiNameIP-COM_306C30
03-11 09:17:32.961 22609-22609/com.mzydz.publish I/System.out: wifiNamezckj
03-11 09:17:32.961 22609-22609/com.mzydz.publish I/System.out: wifiNameMZY
03-11 09:17:32.961 22609-22609/com.mzydz.publish I/System.out: wifiNameZCKJ-Wifi
03-11 09:17:39.162 22609-22609/com.mzydz.publish E/ANR_LOG: >>> msg's executing time is too long
03-11 09:17:39.162 22609-22609/com.mzydz.publish E/ANR_LOG: Blocked msg = { when=-6s220ms what=0 target=android.app.ActivityThread$H callback=android.app.LoadedApk$ReceiverDispatcher$Args } , cost = 6220 ms
03-11 09:17:39.162 22609-22609/com.mzydz.publish E/ANR_LOG: >>>Current msg List is:
03-11 09:17:39.162 22609-22609/com.mzydz.publish E/ANR_LOG: Current msg <1> = { when=-4s2ms what=1 target=com.loc.e$c }
03-11 09:17:39.162 22609-22609/com.mzydz.publish E/ANR_LOG: Current msg <2> = { when=+377ms what=132 target=android.app.ActivityThread$H }
03-11 09:17:39.162 22609-22609/com.mzydz.publish E/ANR_LOG: >>>CURRENT MSG DUMP OVER<<<

New logo/icon

Hi, I am a graphic designer, I want to help others in graphic design.

After I reviewed your project, you have no logo on this project. Therefore I want to contribute to this project by creating a new logo / icon. what do you think?

Is there anyway to get scan wifi result in other format?

Hello,

Is there anyway to get wifi scan result in other format?
Currently your lib return a string but hard to parse into Json or other format, so it's not easy to show the results as ListView on the Android UI.

Thanks & Best Regards
Sui
2019-09-02

android:allowBackup is forced to true - security impact

Hi

Why did you put android:allowBackup
in this file at true
WifiUtils/sample/src/main/AndroidManifest.xml at sample/src/main/AndroidManifest.xml
Because when i install another library ( https://github.com/JuanSeBestia/react-native-wifi-reborn#readme) who use Wifiutils I have conflict with my manifest and yours. And that force me to pass my manifest parameters allowBackup to true.

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.thanosfisherman.wifiutils.sample"
          xmlns:android="http://schemas.android.com/apk/res/android">

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>

</manifest>

Can you help me to found a solution

Constant disconnect on OnePlus devices

I'm using the latest WifiUtils and it works OK on most devices, but whenever we try it on OnePlus on Android 10 the connection to the new WiFi network drops and gets stuck in a loop.

I've attached a video showing the behaviour on OnePlus8:
https://drive.google.com/open?id=1-vP8LR-rMQcaWBRugKhmPMZ8R2C-OabD

All I get in the logs when the 'Device to use with iParcelBox' pops up is the following:
D/WifiUtils: WifiUtils: AndroidQ+ connected to wifi V/FA: Screen exposed for less than 1000 ms. Event not sent. time: 152 V/FA: Activity paused, time: 83058133 D/ViewRootImpl[MainActivity]: windowFocusChanged hasFocus=false inTouchMode=true D/DecorView: onWindowFocusChangedFromViewRoot hasFocus: true, DecorView@527918c[MainActivity]

App crashes on newly created project

I created a new project in Android Studio. I have granted all needed permissions. When I want to connect to WPA wifi I have error like this:

2020-02-15 19:16:45.039 16166-16166/pl.theliverboy.wifitest D/WifiUtils: WifiUtils: WIFI ENABLED...
--------- beginning of crash
2020-02-15 19:16:45.046 16166-16166/pl.theliverboy.wifitest A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0x7414903054 in tid 16166 (verboy.wifitest), pid 16166 (verboy.wifitest)

About connect to open wifi

1.connect to an open wifi ,set password empty string "",it success
2.forget the wifi by system
3.redo step 1,it will connect time out.
wifi log
05-02 20:31:53.980 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: WIFI ENABLED...
WifiUtils: WIFI ENABLED...
WifiUtils: START SCANNING....
05-02 20:31:53.980 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: START SCANNING....
05-02 20:31:54.550 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: GOT SCAN RESULTS
05-02 20:31:54.570 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: ScanResult capabilities [ESS]
WifiUtils: Got security via ScanResult OPEN
05-02 20:31:54.580 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: Got Security Via WifiConfiguration [OPEN]
WifiUtils: PASSWORD WAS EMPTY. TRYING TO CONNECT TO EXISTING NETWORK CONFIGURATION
05-02 20:31:54.820 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: disableAllButOne true
05-02 20:31:54.830 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: Connection Broadcast action: android.net.wifi.supplicant.STATE_CHANGE
05-02 20:31:54.840 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: Connection Broadcast action: COMPLETED
05-02 20:31:54.890 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: Connection Broadcast action: android.net.wifi.STATE_CHANGE
05-02 20:31:54.900 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: Connection Broadcast action: android.net.wifi.STATE_CHANGE
05-02 20:31:54.940 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: Connection Broadcast action: android.net.wifi.supplicant.STATE_CHANGE
WifiUtils: Connection Broadcast action: DISCONNECTED
05-02 20:31:54.940 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: Disconnected. Re-attempting to connect...
05-02 20:31:55.000 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: reEnableNetworkIfPossible false
05-02 20:31:55.010 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: Connection Broadcast action: android.net.wifi.supplicant.STATE_CHANGE
WifiUtils: Connection Broadcast action: SCANNING
05-02 20:32:24.820 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: Connection Timed out...
05-02 20:32:24.860 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: reEnableNetworkIfPossible false
05-02 20:32:24.940 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: WIFI ENABLED...
WifiUtils: START SCANNING....
05-02 20:32:24.940 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: DIDN'T CONNECT TO WIFI
05-02 20:32:26.150 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: GOT SCAN RESULTS
05-02 20:32:26.180 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: ScanResult capabilities [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS]
WifiUtils: Got security via ScanResult PSK
05-02 20:32:26.200 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: Got Security Via WifiConfiguration [PSK]
WifiUtils: Attempting to remove previous network config...
05-02 20:32:26.200 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: COULDN'T REMOVE PREVIOUS CONFIG, CONNECTING TO EXISTING ONE
05-02 20:32:26.440 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: disableAllButOne true
05-02 20:32:26.450 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: Connection Broadcast action: android.net.wifi.supplicant.STATE_CHANGE
WifiUtils: Connection Broadcast action: FOUR_WAY_HANDSHAKE
05-02 20:32:26.450 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: Connection Broadcast action: android.net.wifi.STATE_CHANGE
05-02 20:32:26.470 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: Connection Broadcast action: android.net.wifi.supplicant.STATE_CHANGE
05-02 20:32:26.480 7382-7382/com.sunvua.android.frigg D/WifiUtils: WifiUtils: Connection Broadcast action: DISCONNECTED
WifiUtils: Authentication error...

my device is samsung N9100

Working on android 9

Android 8.0 (API level 26) introduced restrictions regarding permissions and the allowed frequency of Wi-Fi scans.
To improve network performance, security, and battery life, Android 9 (API level 28) tightened permission requirements and further limited the frequency of Wi-Fi scans.

Reference link

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.