The few past months have been really interesting for me personally and professionally as well. I’ve made the move to a bigger city (London) and started working in a bigger company, in an innovation environment that’s pretty impressive :) I’m really excited to find out how this will improve my developer abilities :)

I was struggling the other day with some basic HTTP calls in Android. The LogCat is not very helpful when you need to monitor your http traffic, especially if you use a third-party library for making the calls and thus you are unable to insert some useful logs where you need them.

The fastest solution I have found is to use Charles and set up a reverse proxy to intercept all the calls made to a specific host. Instead of making the call to the actual server, make the call towards the reverse proxy. This in turn will forward the call to the real domain but will also log the request and response information.

To set this up, enable Reverse Proxies from Charles’ Proxy menu then include the host to which you target your calls in the Recording Settings (the Include tab), for eg. myhostname if the domain is http://myhostname/.

On the Android device you don’t need to modify any wifi settings.

In your service code, you can configure a method to read the base domain for your calls from a resource string, depending if you want to use a reverse proxy and if the application is in debug mode. Something on the line of this:

private static String getDomain() {
		if (Utils.isDebugMode(BaseApplication.getInstance())) {
			// in case you want to use a reverse proxy to sniff the server calls
			final Resources res = BaseApplication.getInstance().getResources();
			if ("yes".equalsIgnoreCase(res.getString(R.string.use_debug_proxy))) {
				return res.getString(R.string.debug_proxy);
			}
		}
		return REAL_DOMAIN;
	}

And the utility method, which simply reads the android:debuggable flag from AndroidManifest.xml, which, if not manually overridden, ADT knows to automatically set to true when you plug in a device with a debuggable usb connection.

	public static boolean isDebugMode(final Context context) {
		final ApplicationInfo info = context.getApplicationInfo();
		final int appFlags = info.flags;
		return (appFlags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
	}

The debug proxy must be set using your computer’s ip and a given proxy, for e.g: http://192.168.0.13:55699.

It’s a fairly simple process but can save you a fair amount of time while debugging. Enjoy! :)