Android에 WiFi-Direct(WiFi-P2P)
을 구현하려고합니다. 샘플 코드는 samples\android-19\legacy\WiFiDirectDemo
입니다.WiFi-Direct (WiFi-P2P) 용 Android에서 피어 장치의 IP 주소를 얻는 방법은 무엇입니까?
나는 phone-A
에 WiFiDirectDemo.apk
을 설치하고 실행합니다. phone-B
은 WiFi-Direct(WiFi-P2P)
을 Android Setting
으로 설정합니다.
phone-A
을 전화 -B에 연결하면 phone-A
에 다음 정보가 표시됩니다.
는 그리고 코드는 다음과 같다 :
@Override
public void onConnectionInfoAvailable(final WifiP2pInfo info) {
Log.d(WifiP2P.TAG, "onConnectionInfoAvailable----------- " + info);
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
this.info = info;
this.getView().setVisibility(View.VISIBLE);
// The owner IP is now known.
TextView view = (TextView) mContentView.findViewById(R.id.group_owner);
view.setText(getResources().getString(R.string.group_owner_text)
+ ((info.isGroupOwner == true) ? getResources().getString(R.string.yes)
: getResources().getString(R.string.no)));
// InetAddress from WifiP2pInfo struct.
view = (TextView) mContentView.findViewById(R.id.device_info);
view.setText("Group Owner IP - " + info.groupOwnerAddress.getHostAddress());
// After the group negotiation, we assign the group owner as the file
// server. The file server is single threaded, single connection server
// socket.
if (info.groupFormed && info.isGroupOwner) {
new FileServerAsyncTask(getActivity(), mContentView.findViewById(R.id.status_text))
.execute();
} else if (info.groupFormed) {
// The other device acts as the client. In this case, we enable the
// get file button.
mContentView.findViewById(R.id.btn_start_client).setVisibility(View.VISIBLE);
((TextView) mContentView.findViewById(R.id.status_text)).setText(getResources()
.getString(R.string.client_text));
}
// hide the connect button
mContentView.findViewById(R.id.btn_connect).setVisibility(View.GONE);
}
phone-A
는 Group Owner
입니다. 그리고 phone-A
에서 phone-B
으로 TCP 데이터를 보내려고합니다.
1. phone-B
의 IP 주소는 어떻게 얻습니까? ?
2. Group Owner IP
가 IP address
Phone-A
의
가능한 복제 [와이파이 다이렉트 시나리오에서 각 장치의 IP 주소를 얻는 방법?] (http://stackoverflow.com/questions/10053385/how-to-get-each-devices-ip- address-in-wi-fi-direct-scenario) –
내 대답을 참조하십시오. http://stackoverflow.com/a/43437529/3260008 – Amos
전체 코드를 보내 주시겠습니까? –