1. Are you ready for the Galaxy S20? Here is everything we know so far!

Wifi Not Enabled on HTC Desire

Discussion in 'Android Development' started by mist3r0, Oct 22, 2010.

  1. mist3r0

    mist3r0 Newbie
    Thread Starter

    Hello boys,

    I'm a beginner android programmer.

    In my application I want active wifi, but I've a problem when test my application on my HTC DESIRE.

    This is The code that I've write:

    Code (Text):
    1.  
    2. if(cur.getString().equals("false"))
    3.             if((wifiManager.getWifiState() != WifiManager.WIFI_STATE_DISABLED) && wifiManager.isWifiEnabled())
    4.                  wifiManager.setWifiEnabled(false);
    5.         else if(cur.getString().equals("true"))
    6.                if((wifiManager.getWifiState() != WifiManager.WIFI_STATE_ENABLED) && !wifiManager.isWifiEnabled())
    7.                  wifiManager.setWifiEnabled(true);
    8.  
    The problem is that, if the Wifi is enabled my application turn off the wifi, but don't work if the wifi is disabled and I want enable.

    NOTE: I've insert this permission in the manifest file

    Code (Text):
    1.  
    2. <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
    3.    
    4.     <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
    5.  
    6.     <uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
    7.    
    8.     <uses-permission android:name="android.permission.UPDATE_DEVICE_STATS"></uses-permission>
    9.  
    Why the Wifi not enabled?? Is a problem of Sense Interface? Can you help me?:thinking::thinking::thinking:
     



    1. Download the Forums for Android™ app!


      Download

       
  2. sscAndroid

    sscAndroid Newbie

    You should get used to adding brackets to your if statements.

    As your indentation already indicates, your else if clause belongs to the inner if clause.

    Try
    Code (Text):
    1.  
    2. if(cur.getString().equals("false")) {
    3.             if((wifiManager.getWifiState() != WifiManager.WIFI_STATE_DISABLED) && wifiManager.isWifiEnabled())
    4.                  wifiManager.setWifiEnabled(false);
    5. }
    6. else if(cur.getString().equals("true")) {
    7.                if((wifiManager.getWifiState() != WifiManager.WIFI_STATE_ENABLED) && !wifiManager.isWifiEnabled())
    8.                  wifiManager.setWifiEnabled(true)
    9. }
    instead.
     
  3. mist3r0

    mist3r0 Newbie
    Thread Starter

    Oh Thanks!!! :) This is a big mistake!!! :(

    I've another question for you:

    There is a method to directly enable gps without run this intent:

    Code (Text):
    1.  
    2. Intent in = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    3. startActivity(in);
    4.  
    because thisi ntent bring me into setting menu and I do not want this!
     
Loading...

Share This Page

Loading...