2

In this program I use some constants such as WIFI_STATIC_IP change to a static IP.

When I create the file.apk and install on Android API-10 or version 2.3.3 seems to work. It connects to the wireless and fixed IP assigned.

Yet another tablet Api-15 or version 4.0.3 connects to the wifi but does not change the IP. However it indicates that these constants are Deprecated in API-17 or higher.

I don't understand because it only works on the API-11 version and not in the API-15, or symply I don't understand what is Deprecated.

Settings.System.putInt(cr, Settings.System.ACCELEROMETER_ROTATION, 0); Settings.System.putInt(cr, Settings.System.WIFI_USE_STATIC_IP, 1); Settings.System.putString(cr, Settings.System.WIFI_STATIC_IP, "192.168.1.209"); Settings.System.putString(cr, Settings.System.WIFI_STATIC_NETMASK, "255.255.255.0"); Settings.System.putString(cr, Settings.System.WIFI_STATIC_GATEWAY, "192.168.1.1"); Settings.System.putString(cr, Settings.System.WIFI_STATIC_DNS1, "192.168.1.1");

Moreover in the manifest.xml file I indicate this versions:

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />
Christian Garbin
  • 2,512
  • 1
  • 23
  • 31

1 Answers1

0

Deprecated means you are not supposed to be using it anymore. It's usually the first step to remove the API altogether. You need to change code now or it will stop working in the future.

The warning you see is from the @Deprecated annotation in the API as explained here.

The Android source code is open and it's pretty well documented.

From the Android code (the two important pieces: the @Deprecated and the pointer to WifiManager):

     /**
      * The static IP address.
      * <p>
      * Example: "192.168.1.51"
      *
      * @deprecated Use {@link WifiManager} instead
      */ 
     @Deprecated
     public static final String WIFI_STATIC_IP = "wifi_static_ip";

What you need to do next: study the WiFiManager class and rewrite your code to use it.

Christian Garbin
  • 2,512
  • 1
  • 23
  • 31
  • Thanks for your quick reply, also you're right. But I still have some unanswered questions. I do not understand why it works in version 2.3.3 and not in 4.1.2 if the constant is deprecated in 4.2 or higher – Varios Usos Apr 19 '13 at 15:01
  • As you mention me if I understood what it is deprecated, so in fact I look WifiManager but I don't know how to use it to put the fixed ip address [link](http://developer.android.com/reference/android/net/wifi/WifiManager.html) – Varios Usos Apr 19 '13 at 15:03
  • Just checking: do you `android.permission.WRITE_SETTINGS` set for your application. Other than that, check the catlog for any signs of errors from the system. – Christian Garbin Apr 19 '13 at 16:29
  • The program doesn't produce errors and it has got android.permission.WRITE_SETTINGS and others, moreover in some android mobile 2.3.3 the .apk change the fixed ip, but the problem is in other tablet 4.0.3 because it doesn't change the ip and without errors – Varios Usos Apr 20 '13 at 07:50
  • See this question, but also read the comments in the answer (some people claim it doesn't work). The gist of it: starting in Android 4, the network settings was moved to the SSID (no longer global). http://stackoverflow.com/questions/10278461/how-to-configue-static-ip-netmask-gateway-programmatically-on-android-3-x-or-4 – Christian Garbin Apr 20 '13 at 10:40
  • I know this question and moreover I tried this too but it doesn't work on any device, at least the devices that I have got with 2.3.3 and 4.0.3 versions, so thanks. – Varios Usos Apr 20 '13 at 18:08