21

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 ?

Valery Viktorovsky
  • 6,487
  • 3
  • 39
  • 47
osgx
  • 90,338
  • 53
  • 357
  • 513
  • 2
    possible duplicate of [Can Android do peer-to-peer ad-hoc networking?](http://stackoverflow.com/questions/1932150/can-android-do-peer-to-peer-ad-hoc-networking) – Peter Knego May 13 '11 at 15:09

4 Answers4

18

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.

Community
  • 1
  • 1
Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • Thanks! Can you comment the second part of Q - about how to send file after the ad-hoc is configured? – osgx May 13 '11 at 15:10
  • At the moment ad hoc can not be configured – Peter Knego May 13 '11 at 15:11
  • Bluetooth is too slow and short. Ad hoc is not supported in gui, but I can do it by hand (with editing config files on j-b-ed phone) – osgx May 13 '11 at 15:19
  • 1
    Of course jailbreaked Android phone is basically a linux device so it can do many things. But you can not write an app that does this. And it probably needs root access too. – Peter Knego May 13 '11 at 15:21
  • @PeterKnego after connecting to the adhoc network created on my laptop is it possible to send data to a udp server running on the laptop? just asking for the guidlines... – John x Jan 21 '13 at 20:11
  • @osgx "but I can do it by hand " Please can you post the procedure that would be helpful – Megharaj Feb 05 '13 at 05:55
  • Megharaj, sorry, it was only theoretical assumption that it is possible. I have nor recipe neither jailbreaked android. – osgx Feb 05 '13 at 18:06
  • then wats about flash transfer application in android ? – Jay Vyas May 07 '14 at 04:55
3

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" />
PearsonArtPhoto
  • 38,970
  • 17
  • 111
  • 142
1

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.

ddavison
  • 28,221
  • 15
  • 85
  • 110
Andy
  • 11
  • 1
0

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.

jmarcosSF
  • 69
  • 1
  • 8