Data Exchange between two android devices over hotspot
Asked Answered
F

1

11

I want to exchange data over hotspot between two android devices. I've tried to properly connection.

First, I created a portable hotspot:

Network SSID - my_hotspot
Security - WPA PSK
Password - password

I'm attempting to connect when application is launched. Here is my code<

mWifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);

WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + networkSSID + "\"";   
conf.wepKeys[0] = "\"" + networkPass + "\""; 
conf.wepTxKeyIndex = 0;
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); 
conf.preSharedKey = "\""+ networkPass +"\"";
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);

int res = mWifiManager.addNetwork(conf);
boolean b = setWifiApEnabled(null, true);

I assume it was unsuccessful. Then I'm trying sending data via socket. I've learned from JavaCodeGeeks. I configured SERVER_IP 192.168.49.1, SERVER_PORT:8888.

How to communicate correctly between two Android devices using hotspot?

Frippery answered 21/2, 2014 at 5:39 Comment(0)
D
3

Why don't you use Wi-Fi Direct? It is a p2p protocol. You can share data between two Android devices without any need of hotspot. It uses android.net.wifi.p2p package.

Wi-Fi peer-to-peer (P2P) allows Android 4.0 (API level 14) or later devices with the appropriate hardware to connect directly to each other via Wi-Fi without an intermediate access point (Android's Wi-Fi P2P framework complies with the Wi-Fi Alliance's Wi-Fi Direct™ certification program). Using these APIs, you can discover and connect to other devices when each device supports Wi-Fi P2P, then communicate over a speedy connection across distances much longer than a Bluetooth connection. This is useful for applications that share data among users, such as a multiplayer game or a photo sharing application.

You can find more information on Android developer site about this technology. Here are some useful links:

Android Wi-Fi p2p

android.net.wifi.p2p package

Creating the application

Dumbwaiter answered 26/2, 2014 at 15:0 Comment(5)
Currently i'm using wifi direct, but it does not working stable.Frippery
In hotspot multiple device can be connected and send data which is not possible in P2P . Is there way to send data in hotspot ?Myrtie
@misterandroid First of all, thank you for your answer! Please correct me if I'm wrong: Wi-Fi Direct will disable my GSM cellular network connection on the p2p group owner device, right? If the device was a hotspot then it could still use the GSM connection while communicating with other devices that are connected to it (over hotspot)? I need to have GSM network access on the device....Vernverna
@Vernverna AFAIK Wi-Fi Direct does not block GSM network since it works as some sort of LAN, not to be confused with hotspot. The good thing about Wi-Fi Direct is that you can use it without having an internet connection. Try working while your phone is on flight mode. You'll see it is still functioning.Dumbwaiter
Correct me if I am wrong. In wifi direct, both device should be on same wifi network? How shareit app work, sender open wifi and receiver create hotspot and both device can transfer data between them. Anyone can share how shareit works. ThanksAvan

© 2022 - 2024 — McMap. All rights reserved.