# Changing WiFi network on Android

**URL:** <https://discourse.processing.org/t/changing-wifi-network-on-android/12352>\
**Category:** Processing for Android\
**Created:** [June 28, 2019, 1:58am UTC](https://discourse.processing.org/t/changing-wifi-network-on-android/12352 "2019-06-28T01:58:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![KTibow](https://avatars.discourse-cdn.com/v4/letter/k/3e96dc/32.png) [@KTibow](https://discourse.processing.org/u/KTibow)\
**Post date:** [June 28, 2019, 1:58am UTC](https://discourse.processing.org/t/changing-wifi-network-on-android/12352/1 "2019-06-28T01:58:05Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [June 30, 2019, 4:53pm UTC](https://discourse.processing.org/t/changing-wifi-network-on-android/12352/2 "2019-06-30T16:53:59Z")

</div>

@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)

---

<div class="post-metadata">

**Author:** ![KTibow](https://avatars.discourse-cdn.com/v4/letter/k/3e96dc/32.png) [@KTibow](https://discourse.processing.org/u/KTibow)\
**Post date:** [July 5, 2019, 3:12am UTC](https://discourse.processing.org/t/changing-wifi-network-on-android/12352/3 "2019-07-05T03:12:03Z")

</div>

Can you give me an example?

---

<div class="post-metadata">

**Author:** ![KTibow](https://avatars.discourse-cdn.com/v4/letter/k/3e96dc/32.png) [@KTibow](https://discourse.processing.org/u/KTibow)\
**Post date:** [July 6, 2019, 2:13pm UTC](https://discourse.processing.org/t/changing-wifi-network-on-android/12352/5 "2019-07-06T14:13:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [July 7, 2019, 9:35am UTC](https://discourse.processing.org/t/changing-wifi-network-on-android/12352/6 "2019-07-07T09:35:38Z")

</div>

@KTibow ===  
example here for scanning:  
[https://developer.android.com/guide/topics/connectivity/wifi-scan](https://developer.android.com/guide/topics/connectivity/wifi-scan)  
dont forget permissions (3)

---

<div class="post-metadata">

**Author:** ![KTibow](https://avatars.discourse-cdn.com/v4/letter/k/3e96dc/32.png) [@KTibow](https://discourse.processing.org/u/KTibow)\
**Post date:** [July 7, 2019, 1:45pm UTC](https://discourse.processing.org/t/changing-wifi-network-on-android/12352/7 "2019-07-07T13:45:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [July 7, 2019, 1:56pm UTC](https://discourse.processing.org/t/changing-wifi-network-on-android/12352/8 "2019-07-07T13:56:41Z")

</div>

@KTibow ===

```auto
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 android.net.wifi.ScanResult;/// for scanning
import android.net.wifi.WifiManager;///FIRSTLY
import android.app.Activity;/// FRAGMENT
import android.net.wifi.WifiConfiguration.KeyMgmt;/// For the key WEP
import android.net.wifi.WifiConfiguration;///for creating a new wifi config

```

---

<div class="post-metadata">

**Author:** ![westernira](https://avatars.discourse-cdn.com/v4/letter/w/439d5e/32.png) [@westernira](https://discourse.processing.org/u/westernira)\
**Post date:** [November 30, 2019, 6:22am UTC](https://discourse.processing.org/t/changing-wifi-network-on-android/12352/9 "2019-11-30T06:22:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [November 30, 2019, 9:48am UTC](https://discourse.processing.org/t/changing-wifi-network-on-android/12352/10 "2019-11-30T09:48:41Z")

</div>

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

```auto
import java.util.List;
import android.content.Context;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.app.Activity;

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

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

@Override
  void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  act = this.getActivity();
  mC= act.getApplicationContext();
  IntentFilter intentFilter = new IntentFilter();
  intentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
  wifiReceiver = new WifiScanReceiver();
  mC.registerReceiver(wifiReceiver, intentFilter);
  wifi = (WifiManager) act.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
  wifi.startScan();
}

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());
      println(info+"\n");
    }
  }
}

```
