Programmatically add wifi networks on Android


Question

I have a list of about 100 WiFi SSIDs and passwords that I've extracted from my old phone and I want to add them to the new phone that runs Android 10 and I couldn't find any useful information on the net as everything seems outdated and not working.



A bit about my phone: it's a OnePlus 7 with OxygenOS 10.0.1, rooted with TWRP and Magisk. The wifi networks come from an old OnePlus One with Cyanogenmod wich is not rooted. I obtained the passwords following https://www.reddit.com/r/Android/comments/86zkzf/restoring_wifi_passwords_from_old_device/



The closest thing I've found is this: https://github.com/steinwurf/adb-join-wifi but it works only one network at the time and it doesn't work very well, often passwords aren't added and I have problem escaping the SSID and passwords.



I've also tried to look for wpa_supplicant.conf but apparently it's not used anymore, instead I've found a file called WifiConfigStore.xml but I'm not sure if it can be edited manually or it needs a program, I tried to use wpa_cli but I get an error at startup, I looked for apps but nothing like I need.



I believe the way to go is through WifiConfigStore.xml but its format looks non trivial so that I'm not confident to update it manually plus there's the change it's managed by a service and any change I make will be erased.



How can I add programmatically my networks? Is there an adb command, a file I could edit on the phone or an app that can help me with this?


Answer

I've also had the same problem with losing all WiFi networks when upgrading LineageOS, so I've written a tool which will convert your old wpa_supplicant.conf to new WifiConfigStore.xml (and I'm not using Google accounts or other "upload all my stuff to some cloud" privacy nightmares)



You can find it here: https://github.com/mnalis/android-wifi-upgrade



Even with just SSID/passwords list and without original wpa_supplicant.conf file, file format for WifiConfigStore.xml is not really complex (it is just very verbose). With minimal programming you can use template in my code used for filling it to replace $SSID and other variables in order to generate it from your list).



Note that it will require root (or recovery rom with full adb or filemanager access) on your new android device in order to actually upload newly created WifiConfigStore.xml to the phone.


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes