通过 wi-fi 连接两部 Android 手机(无需笔记本电脑或接入点)并发送文件

发布于 2024-11-07 05:52:47 字数 260 浏览 6 评论 0 原文

是否可以通过 wi-fi 连接两部 Android 手机,而不使用蓝牙/GSM/CDMA/IR?此外,没有任何笔记本电脑或 Wi-Fi 接入点或 Wi-Fi 路由器。

我认为,可以在两部手机上创建一些 SSID,对 IP 地址进行静态配置。 android 会连接到另一个 android wi-fi 吗?

如果它们要连接,我如何将文件从一部手机发送到另一部手机?有 ftp 客户端和服务器吗?或者我可以 ssh 到其他手机吗?或者telnel/netcat?也许http?

Is it possible to connect two android phones by wi-fi, without using a bluetooth/GSM/CDMA/IR? Also, there is no any laptop or wi-fi access points or wi-fi routers.

I think, that it is possible to create some SSID on both phones, do a static configure of IP addresses. Will android connect to another's android wi-fi?

If they will be connected, how can I send a file from one phone to second? Is there a ftp-client and server? or Can I ssh to other phone? Or telnel/netcat? Maybe http ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

停顿的约定 2024-11-14 05:52:47

这称为临时网络,之前已被询问过:

Android 可以进行点对点临时网络吗?

Android Wifi 直接多连接临时

Android ad-hoc/接入点连接功能

更新:

简短回答:ad暂不支持 hoc在 Android 上,所以这不起作用。

您可以使用蓝牙以点对点方式连接两部 Android 手机。

更新 2:

Android 4.0 ICS 包中的 API 14 支持通过 Wifi 进行直接设备到设备连接 android.net.wifi.p2p。您可以通过 FEATURE_WIFI_DIRECT 测试设备功能。

This is called ad hoc network and has been asked before:

Can Android do peer-to-peer ad-hoc networking?

Android Wifi direct multiple connection ad-hoc

Android ad-hoc / access point connection capabilities

Update:

Short answer: ad hoc is not yet supported on Android so this would not work.

You can use Bluetooth to connect two Android phones in a p2p fashion.

Update 2:

Direct device-to-device connection over Wifi is supported under API 14 in Android 4.0 ICS in package android.net.wifi.p2p. You can test devices capability via FEATURE_WIFI_DIRECT.

愿与i 2024-11-14 05:52:47

这实际上可以通过 SDK V 14 实现。正如 文档所述:

  1. 为 Wi-Fi Direct Intents 创建广播接收器
  2. 设置权限
  3. 在 onCreate() 中设置接收器
  4. 设置意图过滤器
  5. 在 onResume() 中注册接收器

我在下面包含了一些关键代码结构来实现这一点。但请阅读文档以获取更多信息。

这是广播接收器权限的示例

public class WiFiDirectBroadcastReceiver extends BroadcastReceiver {

    private WifiP2pManager manager;
    private Channel channel;
    private MyWiFiActivity activity;

    public WiFiDirectBroadcastReceiver(WifiP2pManager manager, Channel channel,
            MyWifiActivity activity) {
        super();
        this.manager = manager;
        this.channel = channel;
        this.activity = activity;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
            int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
            if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
                // Wifi Direct is enabled
            } else {
                // Wi-Fi Direct is not enabled
            }
        } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
            // Call WifiP2pManager.requestPeers() to get a list of current peers
        } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
            // Respond to new connection or disconnections
        } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
            // Respond to this device's wifi state changing
        }
    }
}

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

This is actually possible with SDK V 14. As the documents state:

  1. Create a broadcast receiver for Wi-Fi Direct Intents
  2. Set up permissions
  3. Set up the receiver in onCreate()
  4. Set up an intent filter
  5. Register the receiver in onResume()

I've included some of the key code constructs below to make this happen. But read the documentation for more information.

Here's a sample Broadcast Receiver

public class WiFiDirectBroadcastReceiver extends BroadcastReceiver {

    private WifiP2pManager manager;
    private Channel channel;
    private MyWiFiActivity activity;

    public WiFiDirectBroadcastReceiver(WifiP2pManager manager, Channel channel,
            MyWifiActivity activity) {
        super();
        this.manager = manager;
        this.channel = channel;
        this.activity = activity;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
            int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
            if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
                // Wifi Direct is enabled
            } else {
                // Wi-Fi Direct is not enabled
            }
        } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
            // Call WifiP2pManager.requestPeers() to get a list of current peers
        } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
            // Respond to new connection or disconnections
        } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
            // Respond to this device's wifi state changing
        }
    }
}

Permissions:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
灼疼热情 2024-11-14 05:52:47

如果您只是想使用该功能,而不是在自己的应用程序中实现它,请查看Superbeam, Send! 或快速文件传输,主要使用 WiFi direct。

这里有一些链接。

If you just wanna use that feature and not implement it in an own app, have a look at Apps like Superbeam, Send! or Fast File Transfer, which mainly use WiFi direct.

Here are some links.

划一舟意中人 2024-11-14 05:52:47

尝试通过 wifi 连接 FTPDroid 和 Turbo Client。或者设置 VPN 并通过 SSH、FTP 和/或 SFTP 远程连接所有设备。

Try connecting with FTPDroid and Turbo Client over wifi. Either that, or set up a VPN and connect all of your devices remotely via SSH, FTP and/or SFTP.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文