2

I need to create a wifi access point using custom ssid and password. I looked on the internet and most of the answers use WifiManger#setWifiApEnabled via reflection. But when i checked the source it says that api is deprecated and also inside the method it does not start Access point just gives a warning log.

 @SystemApi
    @Deprecated
    @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
    public boolean setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled) {
        String packageName = mContext.getOpPackageName();

        Log.w(TAG, packageName + " attempted call to setWifiApEnabled: enabled = " + enabled);
        return false;
    }

In method's description it says to use ConnectivityManager#startTethering. It looks like it can start Access Point but i cannot see where i should give my WiFi configuration as that class is for multiple (bluetooth, lte etc) connectivity types.

 @SystemApi
    @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
    public void startTethering(int type, boolean showProvisioningUi,
            final OnStartTetheringCallback callback, Handler handler) {
        Preconditions.checkNotNull(callback, "OnStartTetheringCallback cannot be null.");

        ResultReceiver wrappedCallback = new ResultReceiver(handler) {
            @Override
            protected void onReceiveResult(int resultCode, Bundle resultData) {
                if (resultCode == TETHER_ERROR_NO_ERROR) {
                    callback.onTetheringStarted();
                } else {
                    callback.onTetheringFailed();
                }
            }
        };

        try {
            String pkgName = mContext.getOpPackageName();
            Log.i(TAG, "startTethering caller:" + pkgName);
            mService.startTethering(type, wrappedCallback, showProvisioningUi, pkgName);
        } catch (RemoteException e) {
            Log.e(TAG, "Exception trying to start tethering.", e);
            wrappedCallback.send(TETHER_ERROR_SERVICE_UNAVAIL, null);
        }
    }

Also i want my app to support min api 16 (jellybean) and maximum oreo. Or should i rather force user to setup the Wifi Network ?

pebble
  • 331
  • 2
  • 13

1 Answers1

1

I think its not possible to start a custom wifi hotspot on oreo or later. There is a file transfer app called ShareIt which starts custom wifi hotspot when in receiving mode. If run on oreo, it creates a hotspot of name usually Android-blah with a random password and asks the sender to manually enter that password in order to send that file. May be android is forcing/suggesting its developers to use other wireless technologies (like Wifi direct) to do that kind of operations.

pebble
  • 331
  • 2
  • 13
  • When shareIt starts custom wifi hotspot in receiving mode it also start bluetooth and at sender when user goes for scan for authentication that time it also start bluetooth of sender, so my question is how shareIt doing it with help of bluetooth. – shyam002 Apr 25 '18 at 10:16