Sniffing HTTP requests from Android Apps

I’ve recently had a requirement to rebuild a clunky and inefficient Android App with only partial access to the codebase (layouts and assets, but no Java/Android code). One of the issues was the App was talking to an online database via HTTP POST and GET. I had details of the HTTP root URLs used, but not the specifics on the parameters or how it was formatted.

So after a bit of digging, I found Drony (Google Play link), a kind of log watcher that can show you the exact nature of the HTTP requests, and from this tool I was able to see the exact format of the keys and values for the parameters to upload and download the right information. Great tool, really saved me a lot of effort (and stopped me having to chase original developers etc.)!

Pedders Way Ultra 15 – Kings Forest 20 mile XC

As training for the PWU, I’d signed up for the Positive Steps Kings Forest Festive Challenge on Sat 28th Nov 15, with other PWU victims Steve Dickens and Vince Butler. Other Thetfordites were there, inc. Sabine Schaefer. It’s a 20 mile, or 32km, flattish cross-country race, in the forest obviously! Was cold (about 2-3 degrees, but sunny with moderate wind – shorts!), but really nice – three laps around an area I’d never investigated, and Julia cycled out to shout at us for a short bit of the race, just when we needed it. Mostly dry, open tracks, and mostly sheltered, although some long straights straight into a cold, harsh wind.

Turned out to be nearer 21 miles (33.2km according to my Garmin 310xt), but I managed to flog it (run) the whole way and came in 7th in 2:45:25, with Vince and Sabine in 8th and 9th respectively just a couple of minutes behind (74 completed 20 miler, 102 did a 1/2 marathon, and 85 did a 10km). Vince should have been up with me, but stopped for a pee, and Sabine should have been ahead of me except she went wrong for a bit, and then both had to run/walk nearer the end. Steve had some issues – not sure his run/walk practice rate for PWU is quite right at 4:1 ratio, or if his feeding regime was just off, but he limped over the line, bent-double, in 4:05 – took him about 10 mins before he could stand straight!

Recovery? Ankles buggered the following day, but back to swim and run sessions a couple of days later. Superb event, and necessary training leading up to PWU.

Pedders Way Ultra 14

My 14th session training for the Pedders Way Ultra! Lovely sunny day, so continued from where PWU 12 left off, just north of Wretham.

Puddles, puddles, puddles...

Puddles, puddles, puddles…

Included about 2km’s of track-wide, deep puddles which were tricky to avoid. No probs on a simple 10km run, but going to have a big effect on a longer race by sapping my energy fast, and soaking my feet in the early stages! Nice to run past Thompson Water, might have to get the bins out on that sometime with @juliayelloly…

Pedders Way Ultra 12

Been out on the trail again, getting bits of the route established in my mind. This time parked in the “No Parking, Ever, For Anyone” car park at Wretham Village Hall, and headed south to the A11 (where the previous run reached), then back north and continued past the car for a few KM’s. Nice route, no litter. Pitfalls to watch out for:

  • Rutted path: Sometimes have to run on a narrow path
  • Path turns to tarmac north of Wretham, could be hard in trail shoes
  • No sign at an obvious junction at end of this section – maps says take dirty right hand fork
  • Have to cross the main Thetford – Norwich train line!

The sun was right in my eyes heading south, but the race isn’t going in that direction 🙂

Great Android code snippets

I’ve been developing a new Android App over the last month, and found/learnt several new ways to do things, mostly from hacking other peoples ideas and code (but isn’t that what everyone does? why reinvent the wheel!) In no particular order…

Loading up PLIST files into Android from assets folder

Using xmlwise, which has a specific ‘plist’ class amongst other useful stuff, loading plist dicts and arrays into a Java map is simple.

public TreeMap getData(Context context) throws XmlParseException, IOException {
    TreeMap<String, Object> tMap = null;
    try {
        //To access files stored in Asset folder you need AssetManager
        AssetManager assetManager = context.getResources().getAssets();
        InputStream inputStream = null;
        BufferedReader br = null;
        try {
           inputStream = assetManager.open("myfile.plist");
           br = new BufferedReader(new InputStreamReader(inputStream));
           StringBuilder sb = new StringBuilder();
           String line;
           while ((line = br.readLine()) != null) {
               sb.append(line);
           }
           tMap = new TreeMap(Plist.fromXml(sb.toString()));
        } catch (IOException e) {
           e.printStackTrace();
        } finally {
           br.close();
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return tMap;
}

Enabling touch and pinch zoom on images in ViewPager

Using TouchImageView from Mike Ortiz, I can overload a standard ImageView and set it as a Drawable to add to the ViewPager adapter. It’s really cool, and by a simple hack of Mike’s code it’s easy to tweak the zoom levels. Double-tap and pinch-control are both implemented and it seems fast and robust. Kudos to Mike.

Adding an Android splash screen, easily…

OK, so not everyone wants one, nor every app need them, but the simplicity of the app I’ve been working on needed some branding to remind the users who brought them this (free) app. First I created an XML resource for the layout (useful if you want a complex splash screen).

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="org.my.package">

    <ImageView
        android:id="@+id/mylogo_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@null"
        android:layout_gravity="center"
        android:src="@drawable/my_logo" />

</LinearLayout>

Then I created a simple class to start on launch, which included a runnable to redirect after short period of time to the main activity.

public class Splash extends Activity {

    //Duration of wait - 1000ms = 1second
    private final int SPLASH_DISPLAY_LENGTH = 1200;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        //This line is useful if using action bar etc. 
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.splash);
        
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent mainIntent = new Intent(Splash.this, MainActivity.class);
                Splash.this.startActivity(mainIntent);
                Splash.this.finish();
            }
        }, SPLASH_DISPLAY_LENGTH);
    }
}

Finally, adding

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

to the android manifest gets rid of the title bar. Haven’t worked out if this AND

requestWindowFeature(Window.FEATURE_NO_TITLE);

(in the Splash class above) are necessary together or if one will override the other.

Pedders Way Ultra 7

Although I’ve been back into the running since early mid-October, I’ve only been doing a few hour-long sessions around town each week, and one longer (1:47) off-road run which included Brandon Parkrun. Yesterday I went to the start of the Pedders Way to see what it was like (Ultra training session 7). Having signed up for this Ultra distance run a while ago, I thought I should check out the route a bit more, and get more used to off-road stuff. See Strava include below…

Starts off in a wee car park near Knettishall, and follows lovely leaf-strewn trails northwards. Can be a bit narrow in some places so potential ankle-twisting, but on the whole easy to follow and run. There’s a stretch of boardwalk near Brettenham that skirts the river, which can be slippery and also flooded (I’ve been caught out by this in the past).

Only downer!? Bastards fly-tipping near the West Harling Road. Rubbish everywhere. Also smells of pigs LOTS throughout this whole area, but then at least it’s semi-natural.

So – I’ve managed to run a paltry 8% of the total run (but did have to run back to where I started, and only had an hour…).