Reputation: 31
I have successfully created an android application that is capable of discovering peers through wifi peer 2 peer. I discovered and requested the WifiP2Pdevicelist class and with that i managed to obtained the primaryDeviceType value. However what i want is the device model of the peer. Is there anyway to convert the primaryDeviceType or get device model through wifi p2p?
Got the deviceName, deviceAddress, primaryDeviceType, and secondaryDeviceType from the WifiP2Pdevicelist class used for Wifi P2P. The output of the deviceName is the Wifi-direct name which could be changed. I have yet to connect to the peer because all of this is done using the requestPeer() and discoverPeer() method.
WifiManager wifi;
WifiP2pManager manager;
WifiP2pManager.Channel channel;
BroadcastReceiver receiver;
IntentFilter intentFilter;
ListView listView;
List<WifiP2pDevice> peers = new ArrayList<>();
String[] deviceName, deviceType, deviceAddress;
WifiP2pDevice[] deviceArray;
public ArrayList<WifiP2pDevice> wifiDeviceList = new ArrayList<>();
WifiP2pManager.PeerListListener peerListListener = new WifiP2pManager.PeerListListener() {
@Override
public void onPeersAvailable(WifiP2pDeviceList peersList) {
Toast.makeText(getApplicationContext(), "Peers available", Toast.LENGTH_SHORT).show();
if (!peersList.getDeviceList().equals(peers)) {
peers.clear();
peers.addAll(peersList.getDeviceList());
deviceName = new String[peersList.getDeviceList().size()];
deviceArray = new WifiP2pDevice[peersList.getDeviceList().size()];
for (WifiP2pDevice device : peersList.getDeviceList()) {
listView.clearChoices();
wifiDeviceList.add(device);
}
ArrayAdapter<WifiP2pDevice> mAdapter = new ArrayAdapter<WifiP2pDevice>(getApplicationContext(), android.R.layout.simple_list_item_1, wifiDeviceList) {
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
Toast.makeText(getApplicationContext(), "No Devices Found", Toast.LENGTH_SHORT).show();
TextView view = (TextView) super.getView(position, convertView, parent);
// Replace text with my own
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return view;
}
view.setText("Device name: " + wifiDeviceList.get(position).deviceName + "\n" + "Device address: " + wifiDeviceList.get(position).deviceAddress + "\n" + "Device type: " + wifiDeviceList.get(position).primaryDeviceType);
return view;
}
};
listView.setAdapter(mAdapter);
listView.deferNotifyDataSetChanged();
}
else {
Toast.makeText(getApplicationContext(), "No peers found", Toast.LENGTH_SHORT).show();
}
}
};
Upvotes: 1
Views: 78