user4266159
user4266159

Reputation:

How to Create a Portable Hotspot on Android 6 and connect other devices and share a file like share It..?

I am using this code for creating a hotspot but I don't know how to connect other device to this hotspot automatically..?

public static boolean setHotSpot(String SSID, String passWord) {
    Method[] mMethods = wifiManager.getClass().getDeclaredMethods();

    for (Method mMethod : mMethods) {

        if (mMethod.getName().equals("setWifiApEnabled")) {
            WifiConfiguration wifiConfig = new WifiConfiguration();
            if (passWord == "") {
                wifiConfig.SSID = SSID;
                wifiConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
                wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
                wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
                wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
            } else {
                wifiConfig.SSID = SSID;
                wifiConfig.preSharedKey = passWord;
                wifiConfig.hiddenSSID = true;
                wifiConfig.status = WifiConfiguration.Status.ENABLED;
                wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
                wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
                wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
                wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
                wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
                wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
                wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
            }
            try {
                mMethod.invoke(wifiManager, netConfig, true);
                wifiManager.saveConfiguration();
                return true;

            } catch (Exception e) {

            }
        }
        return false;
    }

}

Upvotes: 0

Views: 226

Answers (1)

Rahul Ravindran
Rahul Ravindran

Reputation: 304

I have found a library called SHAREthem which simulate how SHAREit works. Library facilitates P2P file sharing and transfers between devices using WiFi Hotspot. It also supports app to web sharing if the receiver has no app installed. Hope it helps to you understand technicals involved in file sharing using WiFi Hotspot.

Implementation details :

HotspotController

HC uses Java Reflection since there are NO APIs available on Android for enabling/disabling Hotspots. Functionalities include: Controller creates an OPEN Wifi hotspot configuration with an SSID which can intercepted by Receivers to recognize SHAREthem senders including port and sender names. Restores user Hotspot-Configuration when Share mode is disabled Provides a list of connected WiFi clients. SHAREthem Server

A tiny HTTP server extended from NanoHttpd, serves the sender data to receivers using IP address as hostname and works on port assigned by user or system by default. SHAREthem Service

Android service which manages lifecycle of SHAREthem-server and also handles foreground notification with stop action. UI (Activities)

Android activities to handle share/receive actions

Receiver - provides UI to list the files available to download. Posts a download request to Android Download Manager to start file downloads. Sender - displays IP, Port & connected clients info along with file transfer status for each connected client(Receiver).

Upvotes: 1

Related Questions