I am creating an app which sends an intent which triggers an activity in another phone. Both the phones are connected in the same network and also the number of peers will be variable. How can I implement this using wifi p2p. I want to broadcast this intent as well as listen to such broadcasts by other users of the app.
Asked
Active
Viewed 665 times
1 Answers
0
WiFi P2P has only fixed set of broadcasts that can be received across device namely
WIFI_P2P_STATE_CHANGED_ACTION
WIFI_P2P_PEERS_CHANGED_ACTION
WIFI_P2P_CONNECTION_CHANGED_ACTION
WIFI_P2P_THIS_DEVICE_CHANGED_ACTION
You should define some sort application level protocol like after connecting if I receive MessageA
I will use local broadcast manager to send IntentA
to my other components. If I want other users to perform ActionB
I will send them MessageB
etc. Just a thought.
You could use this wifi p2p wrapper to make your life more easier. You can keep your messages and its parameters as classes and send the class.

dumb_terminal
- 1,815
- 1
- 16
- 27
-
is there any other way for implementing this because not every phone supports wifi direct. I had thought about the way you said but the prob is i dont know where to start from. I have no idea how to send messages to a network connected using wifi router locally. – orangespark May 15 '16 at 06:04
-
Well wifi direct is available from sdk 14 which should cover 90% of the phones on market. below that you could use bluetooth. example [link](https://github.com/simonguest/android-btxfr), you could add a feature even for NFC file sharing [link](http://developer.android.com/training/beam-files/index.html). You definitely have to follow Adapter or Strategy design pattern to use appropriate file sharing tactics based on different device. – dumb_terminal May 15 '16 at 06:13
-
Can you tell me where i can learn how to use wifi connection for sending messagesin local network? I am stuck right now i dont know where to go. – orangespark May 18 '16 at 03:28