Android模拟器的IP地址 [英] android emulator ip address

查看:139
本文介绍了Android模拟器的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发的聊天应用程序,我们要取它是使用code.We连接到专用网络仿真器的IP地址正在开发code在eclipse。

解决方案

  WifiManager wifiManager =(WifiManager)getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
INT IP = wifiInfo.getIpAddress();
ipString =的String.Format(
    %D,%D,%D%D,
    (IP&安培;为0xFF)
    (IP>→8&安培; 0xff的),
    (IP>> 16安培;为0xFF)
    (IP>> 24&安培;为0xFF)
);
 

这个线程。不要忘了INTERNET权限在AndroidManifest!

希望这有助于!

We are developing chat application and we want to fetch the IP address of the emulator which is connected to private network using the code.We are developing code in eclipse.

解决方案

WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ip = wifiInfo.getIpAddress();
ipString = String.format( 
    "%d.%d.%d.%d", 
    (ip & 0xff), 
    (ip >> 8 & 0xff),
    (ip >> 16 & 0xff),
    (ip >> 24 & 0xff)
);

From this thread. Don't forget to have INTERNET permission in your AndroidManifest!

Hope this helps!

这篇关于Android模拟器的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆