
Cell phone even agent is actually very simple, hand to teach you to change the code
The old iron who has been engaged in Android development know that sometimes you need to configure the proxy directly in the app. Here to give everyone a trick, with WifiManager this magic tool can easily get it done. But be careful, now many models of system permissions control strict, you have to make sure that the device has root privileges or test machine did not lock the bootloader.
// Get the WifiManager instance first
val wifiManager = context.getSystemService(Context.WIFI_SERVICE) as WifiManager
// Create the proxy configuration object
val proxyInfo = ProxyInfo.buildDirectProxy("proxy IP", port number)
// Set the global proxy (requires system privileges)
wifiManager.setGlobalProxy(proxyInfo)
Here's where to draw the line:Proxy IP and portYou have to use a reliable one, don't just look for free proxies. Like our own ipipgo, their agent pool is very large, more than 200 countries around the world have nodes, especially suitable for the need to stabilize the agent of the scene.
Practical guide to stepping on the pit
Newbies are most likely to fall into the permissions issue. Remember to add this permission statement in AndroidManifest.xml:
We recommend using a static residential IP when testing, why? Because dynamic IP sometimes switch too fast, debugging up easy to break. ipipgo's static residential package of 35 dollars a month, do functional testing is completely enough.
QA session (FAQ dislike here)
Q: The code runs but the agent doesn't work?
A: First check three things: 1. IP and port right 2. device network is normal 3. whether to open other proxy tool conflict
Q: How do I choose a package for my enterprise business?
A: crawler or data collection of such high-frequency requests, directly on the dynamic residential enterprise version, 9 more than 1 G flow, much more cost-effective than buying a single IP.
| Business Type | Recommended Packages |
|---|---|
| APP TESTING | Static homes |
| data acquisition | Dynamic Residential Enterprise Edition |
| Long-term fixed requirements | TK Line |
Agent Configuration Advanced Play
If you need to dynamically switch IPs, it is recommended that you access ipipgo's API. their interface call is particularly simple, direct get request can get a fresh proxy. Code to add a timed task, half an hour to change the IP, the perfect solution to the problem of IP blocking.
// Example code (remember to replace your own API key)
val client = OkHttpClient()
val request = Request.Builder()
.url("https://api.ipipgo.com/getip?key=YOUR_KEY&type=dynamic")
.build()
One last thing: remember to turn off the proxy after testing! Otherwise, when users use your app, they will somehow go through proxy traffic, which will be embarrassing. Use the following line of code to restore the default settings:
wifiManager.setGlobalProxy(null)

