android.net.wifi.p2p 패키지에 있는 WifiP2pDevice 객체에 디바이스 정보(cpu 점유율, ip어드레스) 등을 넣어서 wifi p2p 를 이용하여 연결 할 때 원격 디바이스에 디바이스 정보를 넘겨 주고 싶습니다.
그래서 WifiP2pDevice 객체에 cpu 점유율과 ip address를 구하는 함수를 WifiP2pDevice내부에 만들어서wrietoParcel에 넣어 줬는데 원격디바이스에서 확인을 하면 값이 넘어오지않고 자신의 ip와 cpu 사용량을 호출합니다.
deviceadress나 devicename 들은 잘 넘어가는데 왜 제가 만든 정보들만 넘어가지 않는지 궁금합니다.
public WifiP2pDevice(String string) throws IllegalArgumentException {
String[] tokens = string.split("[ \n]");
Matcher match;
if (tokens.length < 1) {
throw new IllegalArgumentException("Malformed supplicant event");
}
switch (tokens.length) {
case 1:
/* Just a device address */
deviceAddress = string;
return;
case 2:
match = twoTokenPattern.matcher(string);
if (!match.find()) {
throw new IllegalArgumentException("Malformed supplicant event");
}
deviceAddress = match.group(2);
return;
case 3:
match = threeTokenPattern.matcher(string);
if (!match.find()) {
throw new IllegalArgumentException("Malformed supplicant event");
}
deviceAddress = match.group(1);
return;
default:
match = detailedDevicePattern.matcher(string);
if (!match.find()) {
throw new IllegalArgumentException("Malformed supplicant event");
}
deviceAddress = match.group(3);
primaryDeviceType = match.group(4);
deviceName = match.group(5);
wpsConfigMethodsSupported = parseHex(match.group(6));
deviceCapability = parseHex(match.group(7));
groupCapability = parseHex(match.group(8));
if (match.group(9) != null) {
String str = match.group(10);
wfdInfo = new WifiP2pWfdInfo(parseHex(str.substring(0, 4)),
parseHex(str.substring(4, 8)), parseHex(str.substring(
8, 12)));
}
// // yj add idle cpu 이곳이 제가 추가한 부분입니다.
idleCpu = ""+cpuUsage();
ipaddress = getIpaddress();
break;
}
if (tokens[0].startsWith("P2P-DEVICE-FOUND")) {
status = AVAILABLE;
}
//parcel에 쓰는 부분입니다.
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(deviceName);
dest.writeString(deviceAddress);
dest.writeString(primaryDeviceType);
dest.writeString(secondaryDeviceType);
// yj add idle cpu
dest.writeString(idleCpu);
dest.writeString(ipaddress);
dest.writeInt(wpsConfigMethodsSupported);
dest.writeInt(deviceCapability);
dest.writeInt(groupCapability);
dest.writeInt(status);
if (wfdInfo != null) {
dest.writeInt(1);
wfdInfo.writeToParcel(dest, flags);
} else {
dest.writeInt(0);
}
}
//받는 부분입니다.
public WifiP2pDevice createFromParcel(Parcel in) {
WifiP2pDevice device = new WifiP2pDevice();
device.deviceName = in.readString();
device.deviceAddress = in.readString();
device.primaryDeviceType = in.readString();
device.secondaryDeviceType = in.readString();
// yj add idle cpu
device.idleCpu = in.readString();
device.ipaddress = in.readString();
device.wpsConfigMethodsSupported = in.readInt();
device.deviceCapability = in.readInt();
device.groupCapability = in.readInt();
device.status = in.readInt();
if (in.readInt() == 1) {
device.wfdInfo = WifiP2pWfdInfo.CREATOR.createFromParcel(in);
}
return device;
}