2013-04-18 61 views
2

在這個程序中我使用了一些常量,比如WIFI_STATIC_IP改變爲靜態IP。wifi_static_ip棄用的Api-17 4.2

當我創建file.apk並安裝在Android API-10或版本2.3.3似乎工作。它連接到分配的無線和固定IP。

另一個平板電腦Api-15或4.0.3版連接到wifi,但不更改IP。但是它表明這些常量在API-17或更高版本中已棄用。

我不明白,因爲它只適用於API-11版本而不適用於API-15,或者我不明白什麼是棄用。

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");

而且在manifest.xml文件我表示這個版本:

<uses-sdk 
    android:minSdkVersion="8" 
    android:targetSdkVersion="16" /> 

回答

0

已過時意味着你不應該再被使用。這通常是完全刪除API的第一步。您現在需要更改代碼,否則它將在未來停止工作。

您看到的警告來自API中的@Deprecated註釋,如解釋here所述。

Android源代碼是開放的,它有很好的文檔。

從Android代碼(這兩個重要的部分:在@Deprecated和指針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"; 

你下一步需要做什麼:研究WiFiManager類和重寫你的代碼中使用它。

+0

感謝您的快速回復,您也是對的。但我仍然有一些未解答的問題。 我不明白它爲什麼在版本2.3.3中起作用,而不是在4.1.2中,如果常量在4.2或更高版本中已棄用 –

+0

正如你提到我,如果我明白它被棄用的是什麼,那麼實際上我看起來是WifiManager, '不知道如何使用它來把固定的IP地址[鏈接](http://developer.android.com/reference/android/net/wifi/WifiManager.html) –

+0

只是檢查:你'android.permission。 WRITE_SETTINGS'設置爲您的應用程序。除此之外,請檢查catlog是否有來自系統的錯誤跡象。 – chr