We are about to switch to a new forum software. Until then we have removed the registration on this forum.
WIFI list & Connection by android mode (at Processing Tool)
------------------------------ code-------------------
import android.net.wifi.*;
import android.content.*;
import java.util.*;
Context context;
void connect_to_wifi(){
//create wifi connection
String networkSSID = "";
String networkPass = "";
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + networkSSID + "\""; // Please note the quotes. String should contain ssid in quotes
//For WPA network you need to add passphrase like this:
conf.preSharedKey = "\""+ networkPass +"\"";
//Then, you need to add it to Android wifi manager settings:
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
wifiManager.addNetwork(conf);
//And finally, you might need to enable it, so Android conntects to it:
List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
for( WifiConfiguration i : list ) {
if(i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) {
wifiManager.disconnect();
wifiManager.enableNetwork(i.networkId, true);
wifiManager.reconnect();
break;
}
}
}
void setup() {
size(480,800);
noStroke();
fill(255);
rectMode(CENTER); // This sets all rectangles to draw from the center point
connect_to_wifi();
}
void draw() {
background(0);
rect(width/2, height/2, 150, 150);
}
Error Message : FATAL EXCEPTION: Animation Thread Please solve the problem. Help.
Answers
@Gwak
You need to post exactly what the error say. When you get the error in the console in Processing, select the error and hit ctrl+c and then paste the error message here using the key combination ctrl+v.
It helps if you explain what you are trying to do and in your case, where you get the code from.
Kf
@kfrajer Dear kfrajer, Similar questions. Link>
https://forum.processing.org/one/topic/android-processing-connect-to-wifi-programatically.html
https://forum.processing.org/two/discussion/19008/wifi-list-connection-by-android-mode-at-processing-tool#latest
https://forum.processing.org/two/discussion/18677/i-want-to-connect-to-wi-fi-and-a-list-of-applications#latest
Discussions>
However, many people are told to use the 'ketai library.'
But the Katai library is only Wi-Fi direct. A list of real Wi-Fi does not appear.
So, I want to get a WiFi list through the above code.
However, the error appears as follows.
(Error Message) FATAL EXCEPTION: Animation Thread Process: processing.test.android_test, PID: 9254 java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference at processing.test.android_test.android_test.connect_to_wifi(android_test.java:43) at processing.test.android_test.android_test.setup(android_test.java:64) at processing.core.PApplet.handleDraw(Unknown Source) at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source) at processing.core.PApplet.run(Unknown Source) at java.lang.Thread.run(Thread.java:818)
Have a look at some examples that you can find in google:
https://www.google.ca/search?q=abdroid+get+list+of+wifi+providers&rlz=1C1CHWA_enCA688CA688&oq=abdroid+get+list+of+wifi+providers&aqs=chrome..69i57.7084j0j8&sourceid=chrome&ie=UTF-8#q=android+get+list+of+wifi+providers
If you want to use Processing, it is possible to integrate code from the previous link for sure (it is java after all) but you will need to change certain calls. To see how to access the context and activity objects, check the Android section to see examples or use the search. For example,
https://forum.processing.org/two/search?Search=getactivity
I believe the code you posted above is incomplete and inconsistent with Android design. I don't have experience with what you are trying to do. if you find some code structure that might do what you need, you can share it and I could try to run it.
Kf
@kfrajer
Can not you get a code example?
@Gwak===the error code claims about "null object reference" and that s why you never initialized context.
dont forget to add permissions for wifi;
@kfrajer===this code can work if you add what i said
@akenaton, Thank you sincerely for your faithful reply.
-. All I need is sample code. I honestly do not know how to write through kfrajer's answer. So you need some sample code. Please. Thank you.
@Gwak=== use your code initialize your context nothing more!
@akenaton Dear akenaton,
-. Thank you for a really quick reply. I hope that only good things will happen in the future.
-. I need some sample code to pop up a WiFi list.
-. The sample code is all I can use. I can not write the sample code myself. So I ask you.
Please. Help. An example sample is required.