[英]Connect two android phones with wi-fi (without laptop or access point) and send file
Is it possible to connect two android phones by wi-fi, without using a bluetooth/GSM/CDMA/IR?是否可以通过 wi-fi 连接两部安卓手机,而不使用蓝牙/GSM/CDMA/IR? Also, there is no any laptop or wi-fi access points or wi-fi routers.此外,没有任何笔记本电脑或 Wi-Fi 接入点或 Wi-Fi 路由器。
I think, that it is possible to create some SSID on both phones, do a static configure of IP addresses.我认为,可以在两部手机上创建一些 SSID,对 IP 地址进行静态配置。 Will android connect to another's android wi-fi? android 会连接到另一个 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?是否有 ftp 客户端和服务器? or Can I ssh to other phone?或者我可以 ssh 到其他手机吗? Or telnel/netcat?还是电话/网猫? Maybe http ?也许http?
This is called ad hoc network and has been asked before:这称为ad hoc 网络,之前曾被问过:
Can Android do peer-to-peer ad-hoc networking? Android 可以进行点对点的点对点网络吗?
Android Wifi direct multiple connection ad-hoc Android Wifi Direct 多连接点对点
Android ad-hoc / access point connection capabilities Android ad-hoc/接入点连接功能
Update:更新:
Short answer: ad hoc is not yet supported on Android so this would not work.简短回答:Android 尚不支持 ad hoc,因此这不起作用。
You can use Bluetooth to connect two Android phones in a p2p fashion.您可以使用蓝牙以 p2p 方式连接两部 Android 手机。
Update 2:更新 2:
Direct device-to-device connection over Wifi is supported under API 14 in Android 4.0 ICS in package android.net.wifi.p2p . android.net.wifi.p2p包中的 Android 4.0 ICS 中的 API 14 支持通过 Wifi 的直接设备到设备连接。 You can test devices capability via FEATURE_WIFI_DIRECT .您可以通过FEATURE_WIFI_DIRECT测试设备功能。
This is actually possible with SDK V 14 .这实际上可以通过SDK V 14 实现。 As the documents state:正如文件所述:
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" />
If you just wanna use that feature and not implement it in an own app, have a look at Apps like Superbeam , Send!如果您只是想使用该功能而不是在自己的应用程序中实现它,请查看Superbeam 、 Send等应用程序! or Fast File Transfer, which mainly use WiFi direct.或快速文件传输,主要使用 WiFi 直连。
Here are some links.这里有一些链接。
Try connecting with FTPDroid and Turbo Client over wifi.尝试通过 wifi 连接 FTPDroid 和 Turbo Client。 Either that, or set up a VPN and connect all of your devices remotely via SSH, FTP and/or SFTP.要么,要么设置 VPN 并通过 SSH、FTP 和/或 SFTP 远程连接所有设备。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.