Sample Android Project

1. What's it?

Intercepting HTTPS traffic on Android Devices and Android Emulators is more complicated than iOS.
If you've struggled to config XML settings, let check out this sample project that we've already configured for you:
See HTTPS traffic (https://www.google.com)
Check out the Sample Config section to understand how the config is set up.

2.1 Prepare

    Android Studio 4.0.1
    Pixel 3 Emulator with API 27+ (We suggest that we should create a brand-new Emulator device rather than using the current one. Visit Android Virtual Devices windows in Android Studio)
    Download a sample project at
NetworkConnect.zip
9MB
Binary
NetworkConnect.zip
If you're using Android API 30+, please follow the guideline to trust CA Proxyman Certificate

Automatic Script for Android Emulator

If you run this project on Android Emulator (Google APIs version), you can check out the Automatic Script and Proxyman provides to:
    Set HTTP Proxy, Install, and Trust Proxyman Certificate automatically.
    Then you can skip the step 2.2 and 2.3

2.2 Set Wifi Proxy to Proxyman

    Open your Android Emulator -> Setting app -> Wifi: Make sure your Wifi connection is good. Sometimes, it's "Limited Connection" that you could not set the Wifi Proxy. If it happens, please remove the emulator and create a new one again.
    Click on the Wifi then clicking on Edit Button in two places
    Start set HTTP Proxy that the same IP and Port value from Android Guideline (Proxyman app -> Certificate -> Install Certificate on Android Devices)
Make sure the Proxy Hostname and Port match with the values in (Proxyman app -> Certificate -> Install Certificate on Android Devices)

2.3 Download and Install Proxyman Certificate

    Open Google Chrome on your Android Emulator
    Download the Certificate and select VPN and App Category
If you could not access http://proxy.man/ssl, it means Wifi Proxy doesn't work. Please try to delete your Android Emulator and create a new one in Android Virtual Devices Manager from Android Studio
    Turn OFF / ON the Wifi in Emulators might do the trick
    At this stage, please verify that everything is good before moving to the next stage
If you're using Android API 30+, please follow the guideline to trust CA Proxyman Certificate

2.4 Start the sample project

    After config the Proxy Wifi on your Android Emulator, please make sure to stop the sample app if you're opening
    Make sure Proxyman app is opening
    Start the sample project again in Android Studio and click the Fetch button on the top right navigation bar
    At this stage, you can see HTTPS Traffic on Proxyman -> Select google.com domain and enable SSL
    Try to click the Fetch button again to see HTTPS Content on Proxyman. All done
If you still encounter SSL Error, it means your Android Studio doesn't recognize Proxyman Certificate yet.
Please Stop the app and Start again in Android Studio, then try again!

3. Sample Config

The following is the config that you can intercept HTTPS Traffic from https://google.com
You're only able to see HTTPS content from the www.google.com domain because it's hardcoded in the network-config.
In your real application, please make sure you've added all domains that you're going to intercept. Read more
    AndroidManifest.xml
1
<manifest
2
xmlns:android="http://schemas.android.com/apk/res/android"
3
package="com.example.android.networkconnect"
4
android:versionCode="1"
5
android:versionName="1.0">
6
7
<!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle -->
8
<uses-permission android:name="android.permission.INTERNET" />
9
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
10
11
<application
12
android:label="@string/app_name"
13
android:icon="@drawable/ic_launcher"
14
android:theme="@style/Theme.Sample"
15
android:allowBackup="true"
16
android:networkSecurityConfig="@xml/network_security_config">
17
<activity
18
android:name="com.example.android.networkconnect.MainActivity"
19
android:label="@string/app_name"
20
android:uiOptions="splitActionBarWhenNarrow">
21
22
<intent-filter>
23
<action android:name="android.intent.action.MAIN" />
24
<category android:name="android.intent.category.LAUNCHER" />
25
</intent-filter>
26
</activity>
27
</application>
28
</manifest>
Copied!
    res/xml/network_security_config.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<network-security-config>
3
<!--Set application-wide security config using base-config tag.-->
4
<!--Set domain-specific security config using domain-config tags. -->
5
<!--See https://developer.android.com/training/articles/security-config.html for more information.-->
6
<debug-overrides>
7
<trust-anchors>
8
<!-- Trust user added CAs while debuggable only -->
9
<certificates src="system" />
10
<certificates src="user" />
11
</trust-anchors>
12
</debug-overrides>
13
<base-config cleartextTrafficPermitted="true">
14
<trust-anchors>
15
<certificates src="system" />
16
</trust-anchors>
17
</base-config>
18
19
<domain-config>
20
<domain includeSubdomains="true">www.google.com</domain>
21
<trust-anchors>
22
<certificates src="user"/>
23
<certificates src="system"/>
24
</trust-anchors>
25
</domain-config>
26
</network-security-config>
Copied!

4. Troubleshooting

Depend on Android Emulator and APIs version, you might encounter some errors.
1.After setting the Wifi Proxy in Android Studio, I could not visit http://proxy.man/ssl
=> Please try to restart the Emulator and make sure the Wifi Status in Emulator is "Connected"
=> Delete your Android Emulator and create a new one
2. I get SSL Errors when intercepting HTTPS traffics
=> Sometimes, your Android Emulator doesn't load Proxyman Certificates => Please stop the project and start again.
=> Make sure your domains are listed in res/xml/network_security_config.xml
3. Android Device connection is often dropped and hardly connect
=> Try to add 8.8.8.8 as a DNS on your current Mac Wifi.
Last modified 9mo ago