Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Professional Android 4 Application Development
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Android 4 Application Development
This is the forum to discuss the Wrox book Professional Android 4 Application Development Reto Meier; ISBN: 978-1-1181-0227-5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android 4 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 18th, 2014, 04:36 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jul 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Wifi seems to be not ready after reconnect !?


I encounter a strange problem using WifiManager:
The code is:

	static class InitTask extends AsyncTask<Void, Integer, Integer> {


		protected Integer doInBackground (Void... arg0) {
			WifiManager wifi = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
			WifiConfiguration conf = new WifiConfiguration();

			conf.SSID = "\"" + site.getWifiSSID() + "\"";   // Please note the quotes. String should contain ssid in quotes
			// Only support WPA
			conf.preSharedKey = "\"" + site.getwifiWPAKey() + "\"";
			int wifiState = wifi.getWifiState();
			Boolean enabled = wifi.isWifiEnabled();
			if ((site.getSavedDeviceWifiState() != WifiManager.WIFI_STATE_ENABLED) &&
					(site.getSavedDeviceWifiState() != WifiManager.WIFI_STATE_ENABLING)) {

			List<WifiConfiguration> list = wifi.getConfiguredNetworks();
			for( WifiConfiguration i : list ) {
			    if(i.SSID != null && (i.SSID.equals("\"" + site.getWifiSSID() + "\"") == false)) {
			         wifi.enableNetwork(conf.networkId, true);
			 String verif = site.getWifiSSID();
                // If I put a breakpoint here, the following code runs without any problem
		int responseCode = 0; 
		try {
			int i = 0;
			url = new URL(site.getDescriptionFileUrl());

			// Création d'une connection HTTP à une URL
			URLConnection connection = url.openConnection();
			HttpURLConnection httpConnection = (HttpURLConnection)connection;

                        // Next Call immediately throws a ConnectException
			responseCode = httpConnection.getResponseCode();

			if (responseCode == HttpURLConnection.HTTP_OK) {
		catch (MalformedURLException e) {
			Log.d("2ndGuide", "Malformed URL Exception." + e);
		catch (IOException e) {
			Log.d("2ndGuide", "IO Exception." + e);
		Log.d("2ndGuide", mActivity.getResources().getString(R.string.label_messageAlertCnfBadUrl));
		return -6;
So the problem is that if I let the code executes normally, getResponseCode() throws a ConnectException error:
07-18 20:29:41.821: D/2ndGuide(1925): ConnectException.java.net.ConnectException: - Network is unreachable

If I put a breakpoint just before then click immediately on Play, to just wait a little bit, the code runs normally.

I never seen such warning in the doc or anywhere nor a mechanism to wait for the network being ready after a call to reconnect().

What's the problem??

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 13 - Bonjour without Wifi network acsteester BOOK: Professional iOS Network Programming: Connecting the Enterprise to the iPhone and iPad 5 July 31st, 2013 08:55 AM
ready vs. ready phrnck@mac.com BOOK: Beginning JavaScript and CSS Development with jQuery 1 August 14th, 2009 02:05 PM
Windows Mobile 6 to use WiFi yukijocelyn C# 2005 2 May 28th, 2008 11:48 PM
setting up WiFi Access on Fedora Core 5 crmpicco Linux 0 August 24th, 2007 05:58 PM
Check/Reconnect Missing References ErikTheProgrammer Access VBA 3 February 20th, 2005 02:47 PM

All times are GMT -4. The time now is 03:18 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.