如何开始通过Wi-Fi热点连接的本地网络连接programmically在Android? [英] How to start a local network connection programmically via Wi-Fi hotspot on Android?

查看:222
本文介绍了如何开始通过Wi-Fi热点连接的本地网络连接programmically在Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用启动本地网络连接,内置的Wi-Fi热点的Andr​​oid设备。 有没有办法来完成它? 而如何在两个设备之间进行通信?

I want to start a local network connection using the built-in Wi-Fi hotspot on Android devices. Is there a way to accomplish it? And how to communicate between two devices?

编辑: 我想programmically做到这一点。然后,我可以在设备之间传输自己的数据。

I want to do it programmically. Then I can transfer my own data between devices.

推荐答案

我没有这样做过,所以我的回答是一切的理论。

I haven't done this before, so my answer is all theoretical.

我想你需要做的是声明一个设备的服务器,并与已知的名称手动启动它的热点。

I think what you need to do is declare one device the server and start its hotspot manually with a known name.

启动/停止内置的Wi-Fi / USB绑定从code?(根据这个问题, ,则无法启动热点编程)。

Start / stop built-in Wi-Fi / USB tethering from code? (According to this question, you can't start hotspot programatically).

一旦你的热点设置,你启动服务器应用程序,并等待传入​​的连接。服务器应用程序可以显示你的IP地址或主机名。

Once you have the hotspot set up, you start up the server app and wait for incoming connections. The server app can show you the ip address or hostname.

在客户端,你可以做一个简单的检查,看看热点名称为各地并自动连接到它,如果你找到它。看到这个链接,连接到网络:

On the clients, you can do a simple check and see if the hotspot name is around and automatically connect to it if you find it. See this link for connecting to a network:

使用WifiManager连接到一个网络

Using WifiManager to connect to a network

至于你的第二个问题,如何进行沟通 - 你需要建立设备之间的连接。对于这一点,你需要的服务器的IP地址。做最简单的事情是手动显示了服务器的用户界面的IP地址,然后输入它在客户端和preSS连接。然后,将建立一个已知端口到服务器的连接,并可以发送客户端和服务器之间的消息。

As for your second question, how to communicate - you need to establish a connection between the devices. For this, you need the ip address of the server. The simplest thing to do would be to show the ip address on the server UI and then manually enter it on the clients and press connect. It would then establish a connection to the server on a known port and you can send messages between client and server.

有关的参考,我发现 NanoHttpd ,这是一个网络服务器为Android。它采用的ServerSocket 侦听传入的连接。

For reference, I found NanoHttpd, which is a webserver for Android. It uses ServerSocket to listen for incoming connections.

这篇关于如何开始通过Wi-Fi热点连接的本地网络连接programmically在Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆