简体   繁体   English

通过蓝牙在不同android上相互交互的应用程序是设计出来的?

[英]Apps that interact with each other through Bluetooth on different android devises?

I want to understand is it possible to make an app that, after installing and running on 2 different devices, connect with each other in a way, for example, there is a button and a text view in the app and when I click the button on my device, it updates the text view in the other device's app, and same the other way round. 我想了解是否可以制作一个在2种不同的设备上安装并运行后可以相互连接的应用程序,例如,该应用程序中有一个按钮和一个文本视图,当我单击该按钮时在我的设备上,它将更新另一台设备的应用程序中的文本视图,反之亦然。

If yes, then please guide me what's it called and where can I read and learn about it. 如果是的话,请指导我这叫什么,以及在哪里可以阅读和了解它。 Thanks in advance :) 提前致谢 :)

Take a look at the section on Connectivity on the Android Developer page. 查看“ Android开发者”页面上“ 连接性 ”部分。 It has a few solutions to this. 它对此有一些解决方案。

In your case, there is a Bluetooth section on communicating between devices. 在您的情况下,有一个蓝牙部分介绍了设备之间的通信。 Essentially you have one device act as a server and another as a client. 本质上,您有一台设备充当服务器,另一台设备充当客户端。

A description of what is involved as a server from that page. 该页面中有关服务器的内容的描述。

Connecting as a server 作为服务器连接

When you want to connect two devices, one must act as a server by holding an open BluetoothServerSocket. 当您要连接两个设备时,必须通过按住打开的BluetoothServerSocket来充当服务器。 The purpose of the server socket is to listen for incoming connection requests and when one is accepted, provide a connected BluetoothSocket. 服务器套接字的目的是侦听传入的连接请求,并在接受请求时提供一个已连接的BluetoothSocket。 When the BluetoothSocket is acquired from the BluetoothServerSocket, the BluetoothServerSocket can (and should) be discarded, unless you want to accept more connections. 从BluetoothServerSocket获取BluetoothSocket时,可以(并且应该)丢弃BluetoothServerSocket,除非您希望接受更多连接。

Now you connect to the server phone with your client phone. 现在,您将使用客户端电话连接到服务器电话。

Connecting as a client 作为客户端连接

In order to initiate a connection with a remote device (a device holding an open server socket), you must first obtain a BluetoothDevice object that represents the remote device. 为了启动与远程设备(具有打开的服务器套接字的设备)的连接,必须首先获取代表远程设备的BluetoothDevice对象。 (Getting a BluetoothDevice is covered in the above section about Finding Devices.) You must then use the BluetoothDevice to acquire a BluetoothSocket and initiate the connection. (上面有关查找设备的部分中介绍了获取BluetoothDevice。)然后,您必须使用BluetoothDevice来获取BluetoothSocket并启动连接。

Another option on newer phones can make use of WiFi Direct which is built for what you're trying to do as well. 较新手机上的另一个选项可以利用WiFi Direct ,该功能也针对您要尝试的功能而构建。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM