network programming - How to receive UDP broadcasts on an Android device -
how can make android phone receive udp broadcasts?
at moment testing app using tablet , phone. problem tablet can work server, not phone.
the scenario of app problem is: - client sending broadcast in local network - server receiving broadcast , sending response client directly
i pretty sure think know what's wrong app works when server running on tablet , phone can't receive broadcasts standard.. how around this?
i have tried implementing following code server make receive broadcasts:
wifimanager wifi = (wifimanager)getsystemservice(context.wifi_service); if (wifi != null){ toast.maketext(getapplicationcontext(), "wifilock create!", toast.length_long).show(); wifimanager.wifilock lock = wifi.createwifilock("mylock"); lock.acquire(); }
also, have following permissions in app:
<uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.write_external_storage" /> <uses-permission android:name="android.permission.access_wifi_state" /> <uses-permission android:name="android.permission.access_network_state"/> <uses-permission android:name="android.permission.change_wifi_state" /> <uses-permission android:name="android.permission.wake_lock" /> <uses-permission android:name="android.permission.write_settings"/> <uses-permission android:name="android.permission.change_wifi_multicast_state"/> <uses-permission android:name="android.permission.change_wifi_multicast_state" />
does know how can solved? in advance
by default android block broadcast wifi messages save power. must create wifilock object , aquire lock allow broadcast messages. see here more info: wifilocks
Comments
Post a Comment