can any one suggest me how to get all network connected to my wifi . i want to identify specific network among them and then that all specific network should display in listview.
Asked
Active
Viewed 148 times
0
-
you means you need to display list of all wifi available in your range ? right? – Amit Prajapati Mar 24 '17 at 05:02
-
Thanks for rep , ya exactly among that i want choose one of vender . – Mangesh Gahukar Mar 24 '17 at 05:06
-
from that you want to connect any wifi with password right ? – Amit Prajapati Mar 24 '17 at 05:12
-
no, I want choose one wifi vender and then I want to take IP address of it and then I want communicate with it through udp wit – Mangesh Gahukar Mar 24 '17 at 05:17
-
similar like chat ? you need to communicate in group or single person. – Amit Prajapati Mar 24 '17 at 05:19
-
ya it will be single. see what I am doing is there will some wifi devices connected to same router so by my android app I want detect that all wifi devices In one listView get their IP Addresses and I want to communicate them through UDP massage . so how come I detect all IP's – Mangesh Gahukar Mar 24 '17 at 05:27
-
Possible duplicate of [how to get available wifi networks and display them in a list in android](http://stackoverflow.com/questions/18741034/how-to-get-available-wifi-networks-and-display-them-in-a-list-in-android) – Vladyslav Matviienko Mar 24 '17 at 06:31
-
no above query is related to scanning list of available network router around our device but my question is I want to scan all device connected to router to which my is already been connected . so anyone suggest in this regard ? – Mangesh Gahukar Mar 24 '17 at 06:44
1 Answers
0
Here is sample how to get wifi connected devices ip
https://github.com/SupunArunoda/ChatWithoutInternet
private WifiApiManager wifiApManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_file_sharing);
wifiApManager = new WifiApiManager(this);
listView = (ListView) findViewById(R.id.listView2);
username = (String) getIntent().getExtras().get("name");
SelectClient sendImage = new SelectClient();
sendImage.execute((Void) null);
}
//Asynchronous class to select Client
private class SelectClient extends AsyncTask<Void, Void, Boolean> {
@Override
protected Boolean doInBackground(Void... params) {
final ArrayList<ClientScanResult> clients = wifiApManager.getClientList(false);
runOnUiThread(new Runnable() {
@Override
public void run() {
ClientScanResult clientScanResult;
values = new String[clients.size()];
for (int i = 0; i < clients.size(); i++) {
clientScanResult = clients.get(i);
values[i] = "IpAddress: " + clientScanResult.getIpAddress();//store client's ip addresses in values array
}
adapter = new ArrayAdapter<>(ClientSelectActivity.this, R.layout.list_white_text, R.id.list_content, values);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
i = new Intent(ClientSelectActivity.this, PrivateChatActivity.class);
i.putExtra("ipAddress",clients.get(position).getIpAddress());
i.putExtra("name", username);
startActivity(i);//start activity from this activity to PrivateChatActivity
}
});
}
});
return true;
}
}
//class to manage WiFi technology
public class WifiApiManager {
private final WifiManager mWifiManager;
public WifiApiManager(Context context) {
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
}
public ArrayList<ClientScanResult> getClientList(boolean onlyReachables) {
return getClientList(onlyReachables, 300);
}
//function to return available clients
public ArrayList<ClientScanResult> getClientList(boolean onlyReachables, int reachableTimeout) {
BufferedReader br = null;
ArrayList<ClientScanResult> result = null;
try {
result = new ArrayList<>();
br = new BufferedReader(new FileReader("/proc/net/arp"));
String line;
while ((line = br.readLine()) != null) {
String[] splitted = line.split(" +");
if ((splitted != null) && (splitted.length >= 4)) {
// Basic sanity check
String mac = splitted[3];
if (mac.matches("..:..:..:..:..:..")) {
boolean isReachable = InetAddress.getByName(splitted[0]).isReachable(reachableTimeout);
if (!onlyReachables || isReachable) {
result.add(new ClientScanResult(splitted[0], splitted[3], splitted[5], isReachable));
}
}
}
}
} catch (Exception e) {
Log.e(this.getClass().toString(), e.getMessage());
} finally {
try {
br.close();
} catch (IOException e) {
Log.e(this.getClass().toString(), e.getMessage());
}
}
return result;
}
}

Amit Prajapati
- 13,525
- 8
- 62
- 84
-
Thanks for replay, I have checked with above code but that's not to which I intended to work . I need list of devices connected to my router to which my mobile already been connected so do you have any suggestion in this regard . – Mangesh Gahukar Mar 24 '17 at 07:16
-
Please follow this link it larger project you need to understand form scratch, it work fine what actually you need. https://github.com/Marlinski/Rumble – Amit Prajapati Mar 24 '17 at 07:26
-
I need list of device IP or Vendor name connected to my router to which mobile wifi already been connected . – Mangesh Gahukar Mar 24 '17 at 07:41