简体   繁体   English

如何使用wifi将数据发送到安装在其他Android设备上的同一个应用程序

[英]How to send data to the same application installed on other android device using wifi

i have an application on my android device like "A" and same application installed on the other android device like "B", now i want to send data from app "A" to app "B" using WIFI service. 我在我的Android设备上有一个应用程序,如“A”和安装在其他Android设备上的相同应用程序,如“B”,现在我想使用WIFI服务从应用程序“A”发送数据到应用程序“B”。 so please suggest me how can i implement this feature. 所以请建议我如何实现此功能。

i tried many times to get help from google but all is vain. 我多次尝试从谷歌获得帮助,但一切都是徒劳的。 it is possible from WIFI direct or NFC. 它可以从WIFI直接或NFC。

You could use a simple p2p architecture. 您可以使用简单的p2p架构。

You will need to use this , this and a pair of streams that works with the kind of data you need to send, like this . 您将需要使用thisthis和一对与您需要发送的数据类型相关的流,如下所示

On sender side: 在发件人方面:

Socket s = new Socket(IP,PORT);
s.connect();
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
dos.write("hello".toByteArray());

Then on receiver side: 然后在接收方:

ServerSocket ss = new ServerSocket(PORT);
Socket s = ss.accept(); //This call will block execution, use separate thread
DataInputStream dis = new DataInputStream(s.getInputStream);
byte[] data = dis.read();

With this you can send and receive bytes, just use the stream that works with your data type. 使用此功能,您可以发送和接收字节,只需使用适用于您的数据类型的流。

Of course, once connection is established, both clients could send/write, just make the appropiate Input/Output Stream. 当然,一旦建立连接,两个客户端都可以发送/写入,只需制作适当的输入/输出流。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获得全部 <uses-permission> 设备(Android)上安装的其他特定应用程序的安装? - How to get all <uses-permission> of other particular application installed on the device (Android)? Android使用GCM和PHP将通知从设备发送到其他设备 - Android send notification from device to other device using GCM and PHP 如何在android中使用FCM向单个设备发送数据消息 - How to send data messages to single device using FCM in android 如何在未安装电子邮件应用程序的情况下从android应用程序发送电子邮件 - How to send Email from android application without installed an email application 将相同的SQLitedatabase数据与应用程序中的任何设备一起使用 - Using same SQLitedatabase data with any device in application 如何使用蓝牙将数据从设备获取到android应用程序? - How to get the data from a device to an android application using bluetooth? 我们如何在Android中将数据从一个应用程序发送到另一应用程序? - How can we send data from one application to other application in android? 使用WiFi Direct连接Android设备 - Connecting android device using WiFi Direct 如何从一个 android 应用程序向其他 android 应用程序发送通知? - How to send notification from one android application to other android application? 错误“未在Android设备上安装应用程序。” - error “application not installed on android device.”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM