Changing WiFi network on Android

Hi! I need to change my WiFi network in my app, but I don’t know how. Can you tell me how? If I haven’t searched enough, it’s okay if you let me know. Thanks!

@KTibow ====

though i think i have already answered to that here
that is easy: you use the WifiManager API
create an instance of it
list all wifiSpots
put them in a list
disconnect from all
connect to what you want
(of course you need the wep code)

Can you give me an example?

I’m pinging you, @akenaton. Can you give me an example?

@KTibow ===
example here for scanning:
dont forget permissions (3)

Thanks! Do you know what libraries to import, @akenaton?

@KTibow ===

import java.util.List;/// FOR LISTING
import android.content.Context;// for creating the WIFIM instance
import android.content.BroadcastReceiver;////for creating the receiver
import android.content.Intent;///for adding an intent to it
import android.content.IntentFilter;///// for filtering the receipts
import;/// for scanning
import;/// FRAGMENT
import;/// For the key WEP
import;///for creating a new wifi config
1 Like

Thanks for sharing!! I don’t know much about this. You may refer any wifi guide. It might be helpful to you. Looking for some more responses.

I don’t understand if you have still problems with the listing, bur here is my code.

import java.util.List;
import android.content.Context;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;

// This example scans for available access points and ad hoc networks. 

WifiManager wifi;
WifiScanReceiver wifiReceiver;
Activity act;
Context mC;

  void onCreate(Bundle savedInstanceState) {
  act = this.getActivity();
  mC= act.getApplicationContext();
  IntentFilter intentFilter = new IntentFilter();
  wifiReceiver = new WifiScanReceiver();
  mC.registerReceiver(wifiReceiver, intentFilter);
  wifi = (WifiManager) act.getApplicationContext().getSystemService(Context.WIFI_SERVICE);

class WifiScanReceiver extends BroadcastReceiver {
  public void onReceive(Context c, Intent intent) {
    List<ScanResult> wifiScanList = wifi.getScanResults();
    for (int i = 0; i < wifiScanList.size(); i++) {
      String info = ((wifiScanList.get(i)).toString());