一个月前,我已经找到解决您问题的方法,只需在其中使用Thread put方法isConnected()。
在这种情况下,我使用WifiExplorerActivity来显示所有wifi网络并允许用户连接到它。
Thread t = new Thread() { @Override public void run() { try { //check if connected! while (!isConnected(WifiExplorerActivity.this)) { //Wait to connect Thread.sleep(1000); } Intent i = new Intent(WifiExplorerActivity.this, MainActivity.class); startActivity(i); } catch (Exception e) { } } }; t.start();这是检查wifi是否已连接的功能:
public static boolean isConnected(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = null; if (connectivityManager != null) { networkInfo = connectivityManager.getActiveNetworkInfo(); } return networkInfo != null && networkInfo.getState() == NetworkInfo.State.CONNECTED;}最后,确保您的Androidmanifest.xml如下所示:
<activity android:name=".WifiExplorerActivity" > <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter></activity>
另外,您可以使用ProgressDialog等待连接。参见http://developer.android.com/guide/topics/ui/dialogs.html



