Send Broadcast UDP but not receive it on other Android devices

后端 未结 2 695
臣服心动
臣服心动 2020-12-04 20:03

I am trying to develop an app that sends some broadcast messages and receives some answers from the other android devices. I am having some trouble receiving the UDP message

2条回答
  •  佛祖请我去吃肉
    2020-12-04 20:47

    I came across your post when trying to solve a similar issue. Did you get your stuff working?

    In my case, I had been trying to get a Nexus 7 (first gen with Jelly Bean 4.3) and Nexus One (Gingerbread 2.3.6) talking to each other via UDP. Initially my app, running on both devices, would successfully link up but only with one-way communication from the phone to the tablet. I had only one permission in place in the manifest: INTERNET. Communication from the tablet to the phone started working once I had added the ACCESS_NETWORK_STATE permission to the manifest.

    So, for some reason, the Nexus 7 is happy with just the INTERNET permission for both sending and receiving UDP packets (well, my particular implementation of it, at least). The Nexus One will send with only the INTERNET permission but will not receive unless the ACCESS_NETWORK_STATE permission is given as well.

    Your code looks similar to mine (I don't recognize your "UTILS." calls, however). In my case, though, for the purposes of testing, I've hard-coded the broadcast address (192.168.n.255). I'm on an access point while you're on an adhoc network. Perhaps that has some effect as well.

提交回复
热议问题