1. bozhi91's Avatar
    I'm trying to enable the wifi Access-Point on android device programmatically. The access-pint is already created and works fine. I only want to enable/disable it by code. The code doesn't work very well. The AP is enabled(by code) but I can't connect to the AP from any other device. However, if I disable and then enable the AP manually, then I can connect to the AP. Here's my code:

    final class WifiApManager {
        private static final int WIFI_AP_STATE_FAILED = 4;
        private final WifiManager mWifiManager;
        private final String TAG = "Wifi Access Manager";
        private Method wifiControlMethod;
        private Method wifiApConfigurationMethod;
        private Method wifiApState;
        public WifiApManager( Context context) throws SecurityException, NoSuchMethodException {
            context           = Preconditions.checkNotNull(context);
            mWifiManager      = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            wifiControlMethod = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,boolean.class);
            wifiApConfigurationMethod = mWifiManager.getClass().getMethod("getWifiApConfiguration",null);
            wifiApState = mWifiManager.getClass().getMethod("getWifiApState");
        public boolean setWifiApState( WifiConfiguration config, boolean enabled) {
            config = Preconditions.checkNotNull(config);
            try {
                if (enabled) {
                return (Boolean) wifiControlMethod.invoke(mWifiManager, config, enabled);
            } catch (Exception e) {
                Log.e(TAG, "", e);
                return false;
        public WifiConfiguration getWifiApConfiguration() {
                return (WifiConfiguration)wifiApConfigurationMethod.invoke(mWifiManager, null);
            catch(Exception e)
                return null;
        public int getWifiApState() {
            try {
                return (Integer)wifiApState.invoke(mWifiManager);
            } catch (Exception e) {
                Log.e(TAG, "", e);
                return WIFI_AP_STATE_FAILED;
    All the permissions are granted in the manifest file and I don't see any error logs in the console. Can you tell me if I'm missing something?

    09-17-2019 02:52 AM

Similar Threads

  1. Note 10 audio zoom in feature
    By mustang7757 in forum Samsung Galaxy Note 10 & Note 10+ (2019)
    Replies: 20
    Last Post: 09-24-2019, 10:03 PM
  2. Google update can't sign in now
    By ansa82 in forum Samsung Galaxy Note 9
    Replies: 4
    Last Post: 09-17-2019, 08:08 AM
  3. My LTZ android tablet can see all my neighbours wifi but not my home one.
    By Android Central Question in forum Ask a Question
    Replies: 6
    Last Post: 09-16-2019, 08:36 PM
  4. What is com.android.vending.setup.PLAY_SETUP_SERVICE
    By Android Central Question in forum Ask a Question
    Replies: 1
    Last Post: 09-16-2019, 07:43 PM