本文为转载,原博地址忘记了,参考的代码然后进行调试成功,原博主看到见谅。
主要功能是,自身是无线热点,获取连接自身的设备IP列表
GetConnectIP.java
package wifi.localinfo;
import com.example.swissarmy.R;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class GetConnectIPActivity extends Activity {
private Button btn;
private TextView tv1, tv2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.socket_get_ip);
btn = (Button) findViewById(R.id.display_ip_button);
tv1 = (TextView) findViewById(R.id.display_connectip_textview);
tv2 = (TextView) findViewById(R.id.display_localip_textview);
TextView tvTitle =(TextView) findViewById(R.id.Titletext);
tvTitle.setText("查看连接IP");
ImageView back = (ImageView) findViewById(R.id.Titlehome);
back.setOnClickListener(new ImageView.OnClickListener() {// 创建监听
public void onClick(View v) {
finish();
}
});
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tv1.setText(GetConnectIP.getOneIp());
tv2.setText(GetLocalIp.getLocalIp());
}
});
}
@Override
protected void onStart() {
super.onStart();
}
@Override
protected void onStop() {
super.onStop();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
具体调用
GetConnectIP.getOneIp();
如有问题,欢迎指出。