1

I want to create a mobile hotspot in an android device, I already implemented the hotspot code and is working now, but.. I cannot configure the name and the password of that hotspot using java.

What I am doing wrong?

here is my code.

private WifiManager wifiManager;
private WifiManager.LocalOnlyHotspotReservation mReservation;



@RequiresApi(api = Build.VERSION_CODES.O)
private void turnOnHotspot() {
    WifiManager manager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return;
    }

    manager.startLocalOnlyHotspot(new WifiManager.LocalOnlyHotspotCallback() {

        @Override
        public void onStarted(WifiManager.LocalOnlyHotspotReservation reservation) {
            reservation.getWifiConfiguration().SSID = "android"; //this doesn't do anything
            reservation.getWifiConfiguration().preSharedKey = "12345678"; //this doesn't do anything

            super.onStarted(reservation);
            Log.d(TAG, "Wifi Hotspot is on now");
            mReservation = reservation;
        }

        @Override
        public void onStopped() {
            super.onStopped();
            Log.d(TAG, "onStopped: ");
        }

        @Override
        public void onFailed(int reason) {
            super.onFailed(reason);
            Log.d(TAG, "onFailed: ");
        }
    }, new Handler());
}




private void turnOffHotspot() {
    if (mReservation != null) {
        mReservation.close();
        Log.d(TAG, "Wifi Hotspot is off now");
    }
}
felipe
  • 11
  • 1

0 Answers0