I am using an APP called FileDrop, which seems to me to have the same feature set that you are looking for.
Here's how it works: 4.1 the phone becomes GO and generates a Wi-Fi password so that the older phone can connect to it using outdated Wi-Fi, like connecting to a Wi-Fi access point. You can also use QR scanning instead of manually entering a password.
I hope you can get a sample code from them.
Sorry for the real help.
source share