Android Studio: is possible to have hotspot with internet access? (Local Only Hotspot)

Viewed 368

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)? .

     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");
    }
}

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 to share the mobile data (to have internet access), but I didn't find anything that could have help me. Is there another alternative?

0 Answers
Related