I’m writing an android application which should send out broadcast packets over WiFi.
Currently I can get the IP address of the device from WifiManager.getConnectionInfo().getIpAddress() and guess the broadcast address by simply replacing the last digit with 0. But I really don’t like this solution.
What would be the proper way?
You need to replace with
255not with0.If you are targeting SDK 9 or later you can use
getBroadcast(), otherwise you need to overide the numbers in IP address.Example code: