Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect two android phones with wi-fi (without laptop or access point) and send file

Tags:

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 ?

like image 497
osgx Avatar asked May 13 '11 14:05

osgx


People also ask

How can I transfer files between two Android phones using Wi-Fi?

Tap the Share icon and then select Nearby Share. At the Nearby Share screen, wait for any nearby devices to appear, then tap the name of the device to which you want to share the file. Any nearby device that has Nearby Share activated displays a notification prompting the user to make their device visible.

How do I share files over the same Wi-Fi?

To share a file or folder over a network in File Explorer, do the following: Right-click (or long-press) a file, and then select Show more options > Give access to > Specific people. Select a user on the network to share the file with, or select Everyone to give all network users access to the file.


2 Answers

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.

like image 106
Peter Knego Avatar answered Oct 24 '22 18:10

Peter Knego


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" />
like image 42
PearsonArtPhoto Avatar answered Oct 24 '22 17:10

PearsonArtPhoto