guys I have an activity that gets the ip address of android, but is giving me the wrong ip. I'm testing this in Genymotion as it runs on Virtualbox and gets an ip. http://pctechtips.org/data/ipAddressAndroid.png I'm working on a class that would display tcp/ip configuration for android. but the ip portion I think is wrong. any help appreciated tcpConfigActivity
package com.example.george.droidnet;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
/**
* Created by george on 2/7/17.
*/
public class TcpConfigActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.output);
//reference textView text config
TextView tcpText = (TextView) findViewById(R.id.text_output);
tcpText.setText("TCP/IP Configuration: ");
TextView tcpOutput = (TextView) findViewById(R.id.config_output);
tcpOutput.setText(getIpConfig());
}
public String getIpConfig() {
WifiManager wifiMgr = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
int ip = wifiInfo.getIpAddress();
return Integer.toString(ip);
}
}
this is the output.xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/primary_light"
android:divider="@drawable/vertical_divider1"
android:orientation="vertical"
android:showDividers="middle"
tools:context="com.example.george.droidnet.MainActivity"
android:weightSum="1">
<TextView
android:id="@+id/hostname"
android:layout_height="100dp"
android:layout_width="match_parent"
android:background="@color/primary"
android:textSize="24sp"
/>
<TextView
android:id="@+id/text_output"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/TextStyle"
android:text="output1" />
<TextView
android:id="@+id/config_output"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/txtOutStyle"
android:text="output2"/>
</LinearLayout>