Skip to content

An activity that you can subclass to force the connection to a specific wifi network when the activity is started.

License

Notifications You must be signed in to change notification settings

zoltanersek/android-wifi-activity

Repository files navigation

android-wifi-activity

Provides an activity that you can subclass to force the connection to a specific wifi network when the activity is started.

Is necessary add in your AndroidManifest.

 
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
 
   

Use class WifiBaseActivity

public class MainActivity extends WifiBaseActivity {

  private static final int TIMEOUT = 5;

  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected int getSecondsTimeout() {
        return TIMEOUT;
    }

    @Override
    protected String getWifiPass() {
        return "123456";
    }

    @Override
    protected String getWifiSSID() {
        return "MY-WIFI";
    }

}

Use interface WifiBaseListener

  public class MainActivity extends FragmentActivity implements WifiBase.WifiBaseListener {
  
    private static final int TIMEOUT = 5;
    private WifiBase mWifiBase;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mWifiBase = new WifiBase(this);
    }
  
    @Override
    public String getWifiSSID() {
        return "MY-WIFI";
    }

    @Override
    public String getWifiPass() {
        return "123456";
    }

    @Override
    public int getSecondsTimeout() {
        return TIMEOUT;
    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    public Activity getActivity() {
        return this;
    }
  
  }

Attention! This version have incorrect work on hotspot without internet on android Oreo.

About

An activity that you can subclass to force the connection to a specific wifi network when the activity is started.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages