Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm new to Android Studio and I'm using the functionality of Local Only Hotspot to turn on and off programmatically the hotspot (found this two post for reference: How to turn on/off wifi hotspot programmatically in Android 8.0 (Oreo);)How to turn on Wifi-Hotspot programmatically on Android >= 7.1 (including sharing the internet access)?


Java
private void turnOnHotspot() {
        wifiManager.startLocalOnlyHotspot(new 
          WifiManager.LocalOnlyHotspotCallback() 
         {
            @Override
            public void onStarted(WifiManager.LocalOnlyHotspotReservation reservation) {
                super.onStarted(reservation);
                hotspotReservation = reservation;
                String key = hotspotReservation.getWifiConfiguration().preSharedKey;
                String ussid = hotspotReservation.getWifiConfiguration().SSID;
                System.out.println("KEY: "+ key);
                System.out.println("USSID: "+ ussid);
                currentConfig = hotspotReservation.getWifiConfiguration();
                System.out.println("STARTED THE HOTSPOT");
            }
            @Override
            public void onStopped() {
                super.onStopped();
                System.out.println("STOPPED THE HOTSPOT");
            }

            @Override
            public void onFailed(int reason) {
                super.onFailed(reason);
                System.out.println("FAILED THE HOTSPOT");
            }
        }, new Handler());
    }
    private void turnOffHotspot() {
        active = false;
        if (hotspotReservation != null) {
            hotspotReservation.close();
            System.out.println("CLOSE HOTSPOT");
        }
    }


What I have tried:

But from what I gather from other older posts and documentation, this method gives a local network without internet access and a random SSID and Password that cannot be personalised.
I need to connect only one device to this hotspot and to share the mobile data (to have internet access, but I didn't find anything that could have help me. Is there another alternative? Or P2P is the better solution?
Posted
Updated 18-Jun-21 0:46am
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900