How to set ethernet static IP in android 2.3?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

How to set ethernet static IP in android 2.3?

跳至解决方案
9,046 次查看
DeanHuang
Contributor III

In adeneo 4.3 BSP (Android 2.3 for imx53 QSB), there is not this option in "Settings".

I had tried  a patch file for x86-android 2.3, but it has many compiling and symbol error.

Had anyone ever tried this?

标签 (2)
0 项奖励
回复
1 解答
4,062 次查看
DeanHuang
Contributor III

Weidong, Thanks.

I had done this feature according to android2.3-x86 ethernet patch

在原帖中查看解决方案

0 项奖励
回复
6 回复数
4,063 次查看
DeanHuang
Contributor III

Weidong, Thanks.

I had done this feature according to android2.3-x86 ethernet patch

0 项奖励
回复
4,062 次查看
weidong_sun
NXP TechSupport
NXP TechSupport

Hello,Dean,

     By default, we can't set static IP for ethernet on android platform. But android supplies SDK for user to realize it. we can add "Ethernet parameters setting" item in "Settings" menu, then load NetwokUtils and EthnetNative to set neccessary parameter.

     For more detailed information, you can look into the corresponding documnets and get more usages on your purpose.

Regards,

Weidong

0 项奖励
回复
4,062 次查看
DeanHuang
Contributor III

Hi Weidong,

we can add "Ethernet parameters setting" item in "Settings" menu, then load NetwokUtils and EthnetNative to set neccessary parameter.

Do you mean that we don't need to modify framework, and we just need to add a option in "Settings" or using other APKs to load NetwokUtils and EthnetNative?

BRs.

Dean

0 项奖励
回复
4,062 次查看
weidong_sun
NXP TechSupport
NXP TechSupport

Hello,Dean,

      I checked API in networkutils:

private native static boolean configureNative(

        String interfaceName, int ipAddress, int netmask, int gateway, int dns1, int dns2);

      I think if you load it in your setting program, static ip should be configured. I got a section of code from internet, but i didn't test, you can test it if it is OK:

ConnectivityManager mService = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

  EthernetManager mEthManager = (EthernetManager) getSystemService(Context.ETHERNET_SERVICE);

  if(mEthManager.getState() == EthernetManager.ETHERNET_STATE_ENABLED) {

   EthernetDevInfo mInterfaceInfo = mEthManager.getSavedConfig();

   String mIp;

   String mMask;

   String mGw;

   String mDns;

   mIp = "192.168.0.118";

   mMask = "255.255.255.0";

   mGw = "192.168.0.1";

   mDns = "192.168.0.1";

   mInterfaceInfo.setConnectMode(EthernetDevInfo.ETHERNET_CONN_MODE_MANUAL);

   mInterfaceInfo.setIpAddress(mIp);

   mInterfaceInfo.setNetMask(mMask);

   mInterfaceInfo.setDnsAddr(mDns);

   mInterfaceInfo.setGateWay(mGw);

   try{

    mEthManager.updateDevInfo(mInterfaceInfo);

                                Thread.sleep(500);  

   }catch(Exception e){

    e.printStackTrace();

   }

                } else {

   Toast.makeText(this, "Ethernet state disabled!", 5000).show();

                }

Regards,

Weidong

4,062 次查看
DeanHuang
Contributor III

Hi Weidong,

     Thanks for your suggestion.

     I didn't test this yet, but Android source code seems to use networkutils.configureInteface() instead of networkutils.native(), right?

     According to your sample, you use updateDevInfo().

     Main flow is EthernetManager.updateDevInfo() -> EthernetService.updateDevInfo()  -> EthernetStateTracker.resetInterface() -> networkutils.configureInterface().


     But there is no these classes before doing ethernet patch. Can I use networkutils.configureInterface() directly?


0 项奖励
回复
4,062 次查看
weidong_sun
NXP TechSupport
NXP TechSupport

Hello,Dean,

      Yes, you can try. the above code I gave you is for android 4.0. not android 2.3. but you should find corresponding class in android 2.3 SDK.

Regards,

Weidong

0 项奖励
回复