B4A Library Wifi Library

Firpas

Active Member
Licensed User
Longtime User
The "StartWifi" method of ABWifi 2.x fails when wifi is disable.
This is the error:

java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.wifi.WIFI_STATE_CHANGED flg=0x4000010 (has extras) } in com.AB.ABWifi.ABWifi$1@42228ef8

at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:782)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5603)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.AB.ABWifi.ABWifi$1.onReceive(ABWifi.java:132)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:772)
... 9 more


And the manifest include this two lines:

AddPermission(android.permission.ACCESS_WIFI_STATE)
AddPermission(android.permission.CHANGE_WIFI_STATE)

Any idea???

Thanks in advance
 

alwaysbusy

Expert
Licensed User
Longtime User
Kind of a weird error. StartWifi should just return false in the lib when _wifi == null (causing the java.lang.NullPointerException error later in the BroadcastReceiver). I'll look into it.

Anyhow the two lines:
AddPermission(android.permission.ACCESS_WIFI_STATE)
AddPermission(android.permission.CHANGE_WIFI_STATE)

Should not be added as they are already added in the library
 

alwaysbusy

Expert
Licensed User
Longtime User
Here is a temporary new version. There is also a new demo project, as there were some changes (extra event). Check that one out first before trying it in your project. This is a hard one to debug as I'm connected via wifi to the device, and it's just that connection that must be disabled to reproduce the problem.

Changes (so far)

Sub Activity_Resume
' start ABWifi
If wifi.StartWifi() Then ' use the boolean to see if it's ready to do a GetNewReadingWifi(), if false, you'll have to wait for the WifiEnabled() event
' Get a reading
wifi.GetNewReadingWifi
End If
End Sub

' new
Sub wifi_WifiEnabled(IsEnabled As Boolean)
If IsEnabled Then
wifi.GetNewReadingWifi
Else
ToastMessageShow("Failed to enable Wifi", True)
End If
End Sub
 

Attachments

  • ABWifi2.02.zip
    359.6 KB · Views: 259

Firpas

Active Member
Licensed User
Longtime User
Once again thanks for your quick response.
I tried the new library and now produces a different error:

** Activity (scanwifi) Create, isFirst = true **
** Activity (scanwifi) Resume **
Get new reading
Enabled: true

java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.wifi.SCAN_RESULTS flg=0x4000010 } in com.AB.ABWifi.ABWifi$2@4222b850

at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:782)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5603)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.AB.ABWifi.ABWifi$2.onReceive(ABWifi.java:236)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:772)
... 9 more
 

Firpas

Active Member
Licensed User
Longtime User
One question ...
If I start a timer (10 sec) in the "_WifiEnabled" event, and then call "_GetNewReadingWifi", works well.

I hope this comment will help you.

Thanks for your cooperation again.
 

Firpas

Active Member
Licensed User
Longtime User
One suggestion ...
It would be very useful to give the library a pair of methods to connect to a ABWifiReading:

ABWifiConnect (SSID as string) as boolean
ABWifiConnect2 (BSSID as string) as boolean

It's just a suggestion
 
Last edited:

alwaysbusy

Expert
Licensed User
Longtime User
Ok, another version. I'm afraid we are going to to some trial and error because I'm unable to reproduce the problem here on my devices.
Not having to use a timer is the reason I've started rewriting the lib, so using one is not a solution I'm afraid. It appears in the last version (2.02) it was now the var CurrConn that somehow became null just one line after it was checked:

Lib java code:

if (CurrConn != null) {
if (result.BSSID.compareTo(CurrConn.getBSSID) == 0) { <== null pointer exception
reading.IsConnected = true;
}
}

Added some more checks in this one:

if (CurrConn != null) {
String resBSSID = result.BSSID;
if (currBSSID!=null && resBSSID != null) {
if (resBSSID.compareTo(currBSSID) == 0) {
reading.IsConnected = true;
}
}
}

Can you also tell me the device and the Android version you are using?

I'm not going to add any more functionality until that nasty one is solved. Also, I believe connecting to a Wifi is already in another lib?
 

Attachments

  • ABWifiTest2.03.zip
    359.7 KB · Views: 447

Firpas

Active Member
Licensed User
Longtime User
Here is my devices and Androd version:

Tablets

Samsung Galaxy Tab 4 (GT-N8000) - Android 4.4.2
Asus Fonepad 7 (K013) - Android 4.4.2

Smartphones

Samsung Galalaxy S4 - Android 4.4.2
Samsung Galaxy Trend - Android 4.0.4
HTC WildFire - Androd 2.2.1

Now i'm going to test the ne versión 2.03 and i´back.

Best regards
 

Firpas

Active Member
Licensed User
Longtime User
Ok, I tried the new version 2.03 on some of my devices (both tablets and S$) and now works fine.

I still think that adding a method to connect to a specific wifi via SSID or BSSID will be very useful.

Thank you very much for your cooperation.
 

ibra939

Active Member
Licensed User
Longtime User
wonderful tool
 

FrankBerra

Active Member
Licensed User
Longtime User
After some headaches using ABWifi V 2.01 i found this bug fix! It works!

Here the results using this codes starting with wifi powered off:
B4X:
wifi.Initialize("wifi")
wifi.StartWifi
wifi.GetNewReadingWifi

With ABW 2.01
Nexus 5 (5.0.1): no problems at all (Wifi Activation is sooo quick!)
Samsung Galaxy S2 (4.1.2): crashes (probably because WiFi activation is so slow compared to Nexus 5 ?!)

With ABW 2.03
No problems on both devices

Thank You!
You should update the original thread: https://www.b4x.com/android/forum/threads/wifi-library.8613/
 

Objects for Android

Member
Licensed User
Longtime User
In the latest reply there is a mention of ABW 2.03 and the first page the version is 2.01
Does the 2.03 version is publicly available ?

Thanks.
 

Objects for Android

Member
Licensed User
Longtime User
Just find in the topic the version 2.03, problem is that under 6.50 of B4A library seams not to work properly (When I try to call : ABLoadWifi - I get : Error description: Unknown member: abloadwifi).

Library is well load and my variables in declare in global correctly. The only member I saw are :
StartWifi
StopWifi
Initialize
GetNewReadingWifi
DisableWifi
EnableWifi

Any idea ?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…