本文整理汇总了Java中android.text.format.Formatter.formatIpAddress方法的典型用法代码示例。如果您正苦于以下问题:Java Formatter.formatIpAddress方法的具体用法?Java Formatter.formatIpAddress怎么用?Java Formatter.formatIpAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.format.Formatter
的用法示例。
在下文中一共展示了Formatter.formatIpAddress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.text.format.Formatter; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//try to set this WiFi IP (in case there is no [valid] value set yet)
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
String wifiIP = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
SharedPreferences sPrefs = getSharedPreferences(AppAnalyzer.PREFNAME, MODE_WORLD_READABLE);
String target_ip = sPrefs.getString(BadIntentConstants.TARGET_IP, " ");
if (target_ip.equals(" ") || target_ip.equals("0.0.0.0")) {
sPrefs.edit()
.putString(BadIntentConstants.TARGET_IP, wifiIP)
.apply();
}
addPreferencesFromResource(R.xml.bad_intent_preferences);
}
示例2: getWifiAddress
import android.text.format.Formatter; //导入方法依赖的package包/类
public static String getWifiAddress(Context context) {
WifiManager wifiMgr = (WifiManager) context.getApplicationContext().getSystemService(WIFI_SERVICE);
if(wifiMgr == null){
return null;
}
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
int ip = wifiInfo.getIpAddress();
return Formatter.formatIpAddress(ip);
}
示例3: show_network_info
import android.text.format.Formatter; //导入方法依赖的package包/类
private void show_network_info() {
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
String mac = wm.getConnectionInfo().getMacAddress();
StringBuilder sb = new StringBuilder();
sb.append("WiFi IP address: ");
sb.append(ip);
sb.append("\nWiFi MAC address: ");
sb.append(mac);
final AlertDialog dialog = new AlertDialog.Builder(this)
.setTitle(R.string.networkinfo)
.setMessage(sb.toString())
.setPositiveButton(R.string.dismiss, null)
.create();
dialog.show();
}
示例4: startServer
import android.text.format.Formatter; //导入方法依赖的package包/类
protected void startServer() {
WifiManager wifiMgr = (WifiManager) getApplicationContext()
.getSystemService(Service.WIFI_SERVICE);
if (wifiMgr.isWifiEnabled()) {
// Deprecated. Does not support ipv6. *shrug* :)
String ipAddress = Formatter.formatIpAddress(wifiMgr.getConnectionInfo()
.getIpAddress());
URI baseUri = UriBuilder.fromUri("http://" + ipAddress)
.port(49152)
.build();
ResourceConfig config = new ResourceConfig(SseFeature.class)
.register(JacksonFeature.class);
config.registerInstances(new SecureFilter(this));
config.registerInstances(new DeskDroidResource(this));
// server = JettyHttpContainerFactory.createServer(baseUri, config);
server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config);
}
}
示例5: getIpAddress
import android.text.format.Formatter; //导入方法依赖的package包/类
private String getIpAddress (){
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
@SuppressWarnings("deprecation")
String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
Log.d("ANDROID_Launcher","IP:"+ip);
return ip;
}
示例6: getRouterIp
import android.text.format.Formatter; //导入方法依赖的package包/类
public static String getRouterIp(Context context){
WifiManager wifiService = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if(wifiService == null){
return null;
}
DhcpInfo dhcpInfo = wifiService.getDhcpInfo();
return Formatter.formatIpAddress(dhcpInfo.gateway);
}
示例7: getGatewayIP
import android.text.format.Formatter; //导入方法依赖的package包/类
public static String getGatewayIP(Context context) {
try {
return Formatter.formatIpAddress(((WifiManager) context.getSystemService(NETWORK_NAME_WIFI)).getDhcpInfo().gateway);
} catch (Throwable e) {
LogTool.e(TAG, "", e);
return "";
}
}
示例8: getNetPartOfIpAddress
import android.text.format.Formatter; //导入方法依赖的package包/类
public static String getNetPartOfIpAddress(Context context) {
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
wm.getConnectionInfo().getNetworkId();
String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
ip = ip.substring(0, ip.lastIndexOf('.')+1);
return ip;
// TODO: get subnetmask and build net address
}
示例9: getIPV4Address
import android.text.format.Formatter; //导入方法依赖的package包/类
/**
* Get IP address from first non-localhost interface
* @param ctx is android context
* @return address or empty string
*/
public static String getIPV4Address(Context ctx) {
if(ctx == null){
return "127.0.0.1";
}
WifiManager wm = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);
String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
return ip;
}
示例10: getApIPV4Address
import android.text.format.Formatter; //导入方法依赖的package包/类
public static String getApIPV4Address(Context ctx){
if(ctx == null){
return "127.0.0.0";
}
WifiManager wm = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);
String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
String apIP = ip.substring(0, ip.lastIndexOf(".") + 1) + "0";
Log.d(TAG, "AP: " + apIP);
return apIP;
}
示例11: getGatewayIpAddress
import android.text.format.Formatter; //导入方法依赖的package包/类
public static void getGatewayIpAddress(Context c) {
// get wifi ip
final WifiManager manager = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
final DhcpInfo dhcp = manager.getDhcpInfo();
final String address = Formatter.formatIpAddress(dhcp.gateway);
StringBuilder IFCONFIG = new StringBuilder();
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress() && !inetAddress.isLinkLocalAddress()
&& inetAddress.isSiteLocalAddress()) {
IFCONFIG.append(inetAddress.getHostAddress().toString() + "\n");
}
}
}
} catch (SocketException ex) {
Log.e("LOG_TAG", ex.toString());
}
MLog.d(TAG, "ifconfig " + IFCONFIG.toString());
MLog.d(TAG, "hotspot address is " + address);
}
示例12: getWifiAddress
import android.text.format.Formatter; //导入方法依赖的package包/类
public static String getWifiAddress(Context context) {
WifiManager wifiMgr = (WifiManager) context.getApplicationContext().getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
int ip = wifiInfo.getIpAddress();
return Formatter.formatIpAddress(ip);
}
示例13: getIpAddress
import android.text.format.Formatter; //导入方法依赖的package包/类
public static String getIpAddress(Context context) {
WifiManager wm = (WifiManager) context.getSystemService(WIFI_SERVICE);
return Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
}
示例14: getIpAddress
import android.text.format.Formatter; //导入方法依赖的package包/类
public static String getIpAddress(Context context) {
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
return Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
}
示例15: GetIp
import android.text.format.Formatter; //导入方法依赖的package包/类
public String GetIp() {
return Formatter.formatIpAddress(_wifiManager.getConnectionInfo().getIpAddress());
}