안드로이드 프레임 워크의 소스 코드는 미라 캐스트 싱크 장치를 검색하는 방법을 보여줍니다.
기본적으로 와이파이 다이렉트 장치 검색 API, discoverPeers를 사용하여 -> requestPeers -> isWifiDisplay & isPrimarySinkDeviceType WifiP2pWfdInfo 네 개의 장치 유형을 정의
private static boolean isWifiDisplay(WifiP2pDevice device) {
return device.wfdInfo != null
&& device.wfdInfo.isWfdEnabled()
&& isPrimarySinkDeviceType(device.wfdInfo.getDeviceType());
}
private static boolean isPrimarySinkDeviceType(int deviceType) {
return deviceType == WifiP2pWfdInfo.PRIMARY_SINK
|| deviceType == WifiP2pWfdInfo.SOURCE_OR_PRIMARY_SINK;
}
https://github.com/kensuke/How-to-Miracast-on-AOSP/wiki/wfd_scan
,
public static final int WFD_SOURCE = 0;
public static final int PRIMARY_SINK = 1;
public static final int SECONDARY_SINK = 2;
public static final int SOURCE_OR_PRIMARY_SINK = 3;
HTTP s : // andro id.googlesource.com/platform/frameworks/base/+/master/wifi/java/android/net/wifi/p2p/WifiP2pWfdInfo.java
당신은 와이파이 다이렉트에 익숙하지 않으면, 어쩌면 내 응용 프로그램 와이파이 직접 API를 사용할 때 유용합니다.
HTTP의 : //github.com/kensuke/WiFiDirectTestApp
ADD : 2014년 2월 24일이 - 미라 캐스트 기기의 소스를 인식하거나 싱크 출력 문자열을 toString 분석
와이파이 다이렉트 onPeersAvailable()에 대한 requestPeers() 콜백 메소드 인이 메소드의 매개 변수 인 WifiP2pDeviceList는 WifiP2pDevice 인스턴스의 목록 인 P2p 디바이스 근처에 있으며 WifiP2pDevice에는 Miracast 정보 (wfd ..)를 포함하는 Wi-Fi Direct 정보가 하나 있습니다. WifiP2pDevice.toString() 메서드.
검색 "WFD DeviceInfo : XXX"문자열에서 XXX는 마스크 된 "0x03"(WifiP2pWfdInfo.java 참조)의 마스크 된 값인 0부터 3까지의 숫자 값입니다. 이 값은 SOURCE 또는 SINK를 정의합니다 (WifiP2pWfdInfo.java 상수 참조).
private static final int WFD_SOURCE = 0;
private static final int PRIMARY_SINK = 1;
private static final int SECONDARY_SINK = 2;
private static final int SOURCE_OR_PRIMARY_SINK = 3;
이 매우 의무 방법은 비 뿌리 장치, 일반 응용 프로그램을에 사용 할 수 있습니다.
WifiP2p 장치의 샘플.toString() 값을 리턴
"장치 : ZTS1145
deviceAddress : 7A : E8 : B6 : F6 : 4D 74
기본 유형 : 10-0050F204-5
이차 유형 : 널
WPS : 392
grpcapab : 0
01,237, devcapab 33
상태 3
wfdInfo : WFD 활성화 : trueWFD DeviceInfo : 273
WFD CtrlPort : 7236
WFD MaxThroughput를 10 "
// callback method of requestPeers();
public void onPeersAvailable(WifiP2pDeviceList peers) {
List<WifiP2pDevice> devs = new ArrayList<WifiP2pDevice>(peers.getDeviceList());
for (int i = 0; i < devs.size(); i++) {
WifiP2pDevice dev = devs.get(i);
boolean src = isWifiDisplaySource(dev);
boolean sink = isWifiDisplaySink(dev);
Log.d(TAG, dev.deviceName + " isSource[" + src + "] isSink[" + sink + "]");
}
}
private static final int WFD_DISABLED = -1;
private static final int WFD_SOURCE = 0;
private static final int PRIMARY_SINK = 1;
private static final int SECONDARY_SINK = 2;
private static final int SOURCE_OR_PRIMARY_SINK = 3;
private static final int DEVICE_TYPE = 0x3;
private int getWFDDeviceInfoFromString(String devStr) {
if (devStr == null) {
return WFD_DISABLED;
}
boolean wfd = false;
for (String line : devStr.split("\n")) {
// start self parsing...
// TODO: sprintf parse is more easy
// search "WFD enabled: [true|false]"
if (!line.matches(".*WFD enabled:.*")) {
continue;
}
String[] tokens = line.split(":");
int toks = tokens.length;
for (int i = 0; i < toks - 1; i++) {
if (!tokens[i].contains("WFD enabled")) {
continue;
}
String tok = tokens[i + 1].replaceAll("\\s", ""); // delete white space
if (tok.startsWith("true")) {
wfd = true;
break;
}
// why didn't use .equals() instead of .contains() and .startsWith() ? because
// 1) "wfdInfo: WFD enabled: trueWFD DeviceInfo: 273" // inputed string
// 2) "(wfdInfo):(WFD enabled):(trueWFD DeviceInfo):(273)" // : splited string
// 3) "(trueWFD DeviceInfo)" => "trueWFD DeviceInfo" // white space deleted
}
}
if (!wfd) {
return WFD_DISABLED;
}
for (String line : devStr.split("\n")) {
// search "WFD DeviceInfo: \d+"
if (!line.matches(".*WFD DeviceInfo:.*")) {
continue;
}
String[] tokens = line.split(":");
int toks = tokens.length;
for (int i = 0; i < toks - 1; i++) {
if (!tokens[i].contains("WFD DeviceInfo")) {
continue;
}
String tok = tokens[i + 1].replaceAll("\\s", "");
int deviceInfo = Integer.parseInt(tok);
Log.d(TAG, "line[" + line + "] DeviceInfo[" + deviceInfo + "] masked[" + (deviceInfo & DEVICE_TYPE) + "]");
return deviceInfo;
}
}
return WFD_DISABLED;
}
private boolean isWifiDisplaySource(WifiP2pDevice dev) {
if (dev == null) {
return false;
}
int deviceInfo = getWFDDeviceInfoFromString(dev.toString());
if (deviceInfo == WFD_DISABLED) {
return false;
}
int deviceType = deviceInfo & DEVICE_TYPE; // masked
return deviceType == WFD_SOURCE || deviceType == SOURCE_OR_PRIMARY_SINK;
}
private boolean isWifiDisplaySink(WifiP2pDevice dev) {
if (dev == null) {
return false;
}
int deviceInfo = getWFDDeviceInfoFromString(dev.toString());
if (deviceInfo == WFD_DISABLED) {
return false;
}
int deviceType = deviceInfo & DEVICE_TYPE; // masked
return deviceType == PRIMARY_SINK || deviceType == SOURCE_OR_PRIMARY_SINK;
}
안녕하세요. Android 소스 코드에서 말하는 API가 숨겨진 것으로 표시되었음을 알립니다. 즉, SDK 생성에 참여하지 않습니다. 이러한 API는 표준 휴대 전화의 일반 앱에서는 사용할 수 없습니다. 이 동작을 변경하는 Android 운영 체제의 맞춤형 버전을 구축 할 수 있습니다. 이것에 동의하십니까? –
댓글을 수정하십시오! 내 첫 번째 대답은 시스템 앱만 사용합니다. 그래서, 일반 앱을 위해 게시 된 의무 방법 ... –