Have you added the permission to read the wifi state?
Can you post the exception that is thrown?

On Dec 17, 7:13 am, zz zt1082 <zt1...@gmail.com> wrote:
> When I call mWifiManager.isWifiEnabled() , program is crash.
>
> my Code is:
> ---------------------------------------------
> import android.app.Activity;
> import android.net.wifi.ScanResult;
> import android.net.wifi.WifiManager;
> import android.os.Bundle;
> import android.util.Log;
>
> public class HelloWIFI extends Activity {
>         /** Called when the activity is first created. */
>
>         private WifiManager mWifiManager;
>
>         @Override
>         public void onCreate(Bundle savedInstanceState) {
>                 super.onCreate(savedInstanceState);
>                 setContentView(R.layout.main);
>
>                 mWifiManager =
> (WifiManager)this.getSystemService(this.WIFI_SERVICE);
>                 Log.i("INFO", "WifiState = " + mWifiManager.getWifiState());
>                 if (mWifiManager.isWifiEnabled())
>                 {
>                         Log.i("INFO", "WIFI is enable");
>                 }
>                 else
>                 {
>                         Log.w("Warning", "WIFI is NOT enable");
>                 }
>
>                 mWifiManager.setWifiEnabled(true);
>                 mWifiManager.startScan();
>
>                 for (ScanResult result:mWifiManager.getScanResults())
>                 {
>                         Log.i("INFO", "ScanResult:" + result.toString());
>                 }
>         }
>
>
>
> }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to