Get Devices connected to same wifi network in android programmatically? - java

I am developing an app in which the first thing i need is how to get devices that are connected to my wifi network or same wifi network .ie ip adress,device name etc.
I don't have any idea how to do that have searched alot but there are no examples available.
I have done one thing that i will ping 255 ips and whichever will respond will be the connected ips but the problem here is that there are virtual ips already assigned to some websites so i need to detect only the real device ip addresses.
I want to do the same thing as done in the app WifiTalkie

Follow Any one of the following:
Way1:
If you mean you want to see all the devices connected to your current WiFi connection (and you are not trying to do Ad Hoc networking), then you are essentially wanting to run a network scanner.
There are a bunch of these around. This one has the source available on github
http://rorist.github.com/android-network-discovery/
Way2:
Refer How to detect all the Devices connected in a WiFi network from Android App

Related

Is it possible to use both the Wi-Fi (wlan) and Cellular Data 4G/LTE (rmnet) interface simultaneously on Android?

I am working in an application that requires an Android device to connect to a Wi-Fi network. This Wi-Fi network does not have internet access - it is a Wi-Fi network created by a end-device and used only to communicate with it using TCP sockets. I would like to be able to access the cellular data internet connection on the Android device WHILE communicating with this device over Wi-Fi and I wanted to know if this is possible.
Here is what I know so far:
It is possible to get list of all interfaces available on the device and their corresponding IP addresses via the Android NetworkInterface API.
There is an option in the Developer Settings in Android to keep cellular data interface up even when Wi-Fi is connected.
It is possible to provide the local address for the Socket to bind to when creating a Socket()
With these in mind:
When I am connected to the Wi-Fi network with the SIM card in the device and LTE enabled I am able to get wlan0 interface with a "local" IP address in the format 192.168.x.x and rmnet0 interface with a non-local IP address.
However, depending on the device, I am only ever able to access ONE of them at a time.
For example, on a Pixel 2 XL running Oreo 8.1, LTE Enabled, Cellular Data Always On enabled:
I am unable to communicate over Wi-Fi AT ALL. Any Sockets created with the Wi-Fi local address time out.
On a Galaxy Tab S2 SM-T818W running Nougat 7.1, LTE Enabled, Cellular Data Always On enabled:
I am able to communicate over Wi-Fi but not able access the cellular data interface.
The only way I am able to access the wlan0 interface on the Pixel 2 XL is by calling requestNetwork from Android's ConnectivityManager API and requesting Network with TRANSPORT_WIFI capabilities but this defeats the purpose since now all communication and sockets will be bound only to the Wi-Fi network.
I know that when USB tethering is enabled, it is possible to access devices on the Virtual USB "Ethernet Network" interface which shows up as eth0 with either the wlan0 interface or even the rmnet0 interface by specifying local addresses on the Socket connection calls. It just appears to be a problem with Wi-Fi and cellular data.
I wanted to know if this is an inherent and intended Android limitation or is there a way to access both interfaces at the same time that I am missing.
Appreciate your help. Please let me know if it would be better for me to provide specific code snippets, I wasn't sure since it would make this post quite long.
Best,

Finding exact device in the LAN Java / Android

I'm developing a Java application which should listen on specific port on computer using Sockets.
The another app, which will run on Android device connected to the same WiFi, should find this computer with my Java program.
How can I find the computer in the network?
I've tried it in the small LAN (where are all devices connected to 192.168.*.*) using InetAddress.getByName(ipAddress).isReachable(); but in the bigger network (like eduroam or my school WiFi) I'm not able to scan whole network.
Is there another option how to connect two devices to each other apart from using Sockets and scanning whole network?
I'm not sure I understand your entire system requirements, but I'm thinking you could create a very small database at a hosting site (such as this) and have your PC periodically upload its private IP address to that database.
Then, when you need to connect to the PC on your android device, you query the database and determine the PC's current address, then connect to the device.

How to find specific desktop's ip address on network?

I'm coding an app which consist of two pieces. Desktop and android. There is one desktop and several android devices. (don't know the count.) I want to communicate android devices between desktop with TCP. However, android devices doesn't know desktop's lan ip address.
I thouht 2 ways:
1-Desktop app changes the local ip address on start. So android devices know the ip address. (I coded with that ip address)
2-Desktop app always tries to connect ip addresses (192.168.0.1 - 192.168.0.255) to sent desktop's ip address. And when an android device connect to the network accept the connection then know desktop's ip.
But there is some problems in both ways.
On first, you must be administrator to changing lan ip. So run command as admin with java is a problem. Because if I do this, when user start the program, uac always asks for it.
On second, I think there will be performance issues because of app always tries to connect. Exept this, when android device connect and dhcp gives it 192.168.0.5 , but loop is on 192.168.0.150. So android device have to wait for connection.
Is there a better way than these?
Look at this post Network discovery in Java using multicasting
I think this would be the best way to do it.
The server will listen for a broadcast message from client
the client sends a broadcast request asking for server ip
server receives request and replies back with server ip.
You can use the hostname. If the network is properly configured, the host name will point to the correct ip even if it changes

connecting two mobile phones over different network and then real time video streaming

I'm developing an application in which i want to connect two android phones over different networks and then want to stream user's video to one another with their own video e-g a user can see their own video and also the video of the friend who is connected with him over network.I want to do this thing without a server..Is it possible ??
I think this is possible see nanohttpd and you will have to connect both device using your app in same network and stream to a port listen to port

Is it possible to transfer data directly between two android devices to other users in the same network?

Let's say I have two android mobile devices, connected to the same wireless network, and that network hasnt external/internet access.
Without third party software, is it possible to transfer data through wifi without knowing the ip from each other and without creating an hotspot? Something like we do on Windows (if 2 pcs are on same network, they can share information directly without internet access)
Starting with the basics, I would like to develop an application, where android phones on same network appears on a list , and then a user choose on of them and writes something - and if the other user have the same app running, appears that on his phone (and then he can reply of course - basically, a chat.
I know this make no practical sense, but believe makes all the sense for what I need to do (it's not a chat of course). If anyone knows anything, please help me - i found nothing.
Thanks in advance.
If you want to send data or messages from one phone to another using the network you will eventually need the IP address of the recipient phone. However, If you don't care about targeting specific phones you could always send UDP broadcast packets that each device on the network should receive.
If you don't want to manually specify an IP you'll need to create a discovery protocol that a phone uses to discover all the other phones on the network. You could do this buy scanning all available IP addresses and checking to see if they are a valid android phone. Or you could have each phone broadcast its presence on the network using a UDP broadcast packet sent to a predefined port.
Once you have discovered all the phones on the network its really up to you to decide how you want to send the data between phones and there are hundreds of examples of how to send data between devices/computers/processes using sockets.

Categories

Resources