1. Check out our companion app, Forums for Android! Download from Google Play

Wifi Not Enabled on HTC Desire

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

  1. mist3r0

    mist3r0 Member
    Thread Starter
    15

    Dec 12, 2009
    19
    0
    15
    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:
     

    Advertisement

  2. sscAndroid

    sscAndroid Member
    16

    Oct 23, 2010
    17
    1
    16
    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 Member
    Thread Starter
    15

    Dec 12, 2009
    19
    0
    15
    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!
     

Share This Page

Loading...