<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Adrian Smith&#039;s Blog &#187; android</title>
	<atom:link href="http://www.17od.com/tag/android/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.17od.com</link>
	<description></description>
	<lastBuildDate>Sun, 20 Nov 2011 20:04:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>UPM for Android 1.2 Released</title>
		<link>http://www.17od.com/2010/08/09/upm-for-android-1-2-released/</link>
		<comments>http://www.17od.com/2010/08/09/upm-for-android-1-2-released/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 18:07:50 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[upm]]></category>

		<guid isPermaLink="false">http://www.17od.com/?p=351</guid>
		<description><![CDATA[Universal Password Manager for Android 1.2 has been released. The easiest way to install it is from the Android Market. Alternatively the apk can be downloaded from SourceForge. The source is also available there. From the release notes&#8230; Long-clicking on an account now brings up a context menu allowing you to copy username, copy password, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://upm.sourceforge.net">Universal Password Manager</a> for Android 1.2 has been released. The easiest way to install it is from the Android Market. Alternatively the apk can be downloaded from <a href="https://sourceforge.net/projects/upm/files/UPM/upm-android-1.2/">SourceForge</a>. The source is also available there.</p>
<p>From the release notes&#8230;</p>
<ul>
<li>Long-clicking on an account now brings up a context menu allowing you to copy username, copy password, launch URL or edit account</li>
<li>Added the ability to trust self signed certificates and certificates that have a different Common Name to the website hostname</li>
<li>Increased the font size on the Account Details activity</li>
<li>Fixed a bug on the main Accounts page so that it recovers gracefully when the database is closed unexpectedly</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.17od.com/2010/08/09/upm-for-android-1-2-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UPM 1.1 Released</title>
		<link>http://www.17od.com/2010/03/30/upm-1-1-released/</link>
		<comments>http://www.17od.com/2010/03/30/upm-1-1-released/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 18:55:10 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[upm]]></category>

		<guid isPermaLink="false">http://www.17od.com/?p=305</guid>
		<description><![CDATA[With this release UPM on Android reaches feature parity with the desktop version. The main features included with this release are, Shared Database support Delete Database support Lots of bugs fixes and improvements The shared database feature was the primary focus of 1.1. With this it&#8217;s now possible to sync your password database with the [...]]]></description>
			<content:encoded><![CDATA[<p>With this release <a href="http://upm.sourceforge.net/">UPM on Android</a> reaches feature parity with the desktop version. The main features included with this release are,</p>
<ul>
<li>Shared Database support</li>
<li>Delete Database support</li>
<li>Lots of bugs fixes and improvements</li>
</ul>
<p>The shared database feature was the primary focus of 1.1. With this it&#8217;s now possible to sync your password database with the desktop version. For full details on how to setup and use database sharing see the <a href="http://upm.sourceforge.net/userguide.html">user guide</a>. </p>
<p>You can upgrade from the Android Marketplace or <a href="https://sourceforge.net/projects/upm/files/UPM/upm-android-1.1/UPM-Android-1.1.apk/download">download the APK</a> directly from Sourceforge.</p>
<p>If you have any problems post please use the <a href="https://sourceforge.net/projects/upm/forums/forum/517034">Help Forum</a>.</p>
<p><strong>UPDATE: When you upgrade you may get an error telling you UPM is no longer available when you try to start it. To fix this you should restart your phone and recreate any shortcut you have to UPM on your Home screen.</strong></p>
<p><strong>For those who are interested this seems to be a problem with Android 1.5 and how it handles a change to the main Activity after an upgrade. If you have any experience or details on this problem I&#8217;d be interested hear about it.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.17od.com/2010/03/30/upm-1-1-released/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Multipart form upload on Android</title>
		<link>http://www.17od.com/2010/02/18/multipart-form-upload-on-android/</link>
		<comments>http://www.17od.com/2010/02/18/multipart-form-upload-on-android/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 19:49:55 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.17od.com/?p=280</guid>
		<description><![CDATA[Android 1.5 includes Apache HttpClient 4 for the purposes of making HTTP requests. Unfortunately HttpClient 4 (or the version included with Android anyway) doesn&#8217;t appear to support multipart form uploads. As it happens writing a solution from scratch (at the HTTP layer that is) is pretty straight forward. The main challenge is understanding how the [...]]]></description>
			<content:encoded><![CDATA[<p>Android 1.5 includes <a href="http://hc.apache.org/httpcomponents-client/index.html">Apache HttpClient 4</a> for the purposes of making HTTP requests. Unfortunately HttpClient 4 (or the version included with Android anyway) doesn&#8217;t appear to support multipart form uploads.</p>
<p>As it happens writing a solution from scratch (at the HTTP layer that is) is pretty straight forward. The main challenge is understanding how the POST request should be structured. Once you know that it&#8217;s simply a matter of putting all the pieces together.</p>
<p>The connection is managed using the <strong>java.net.HttpURLConnection</strong> class. There&#8217;s a few properties that need to set on the connection to ensure it can be written to and read from,</p>
<pre><code>HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);</code></pre>
<p>A special header informs the server that this will be a multipart form submission.</p>
<pre><code>conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=xxxxxxxxxx");</code></pre>
<p>The &#8220;boundry&#8221; can be any string. In this example it&#8217;s <code>xxxxxxxxxx</code>. It&#8217;s used in the body of the request to seperate each field being submitted.</p>
<p>Next comes the main body of the request. Each field being submitted follows the same pattern. For example, to submit a text file called &#8220;helloworld.txt&#8221; with the contents &#8220;Hello World&#8221; and using the boundry string <code>xxxxxxxxxx</code> here&#8217;s what the request would look like,</p>
<pre><code>--xxxxxxxxxx
Content-Disposition: form-data; name="filetoupload"; filename="helloworld.txt"
Content-Type: text/plain

Hello World
--xxxxxxxxxx--</code></pre>
<p>The final <code>--</code> is important. It tells the server it&#8217;s the end of the submission.</p>
<p>Here&#8217;s a full method that&#8217;s used to upload a file to a URL. It can optionally take a username and password which is used to perform BASIC authentication.</p>
<pre><code>    public static void put(String targetURL, File file, String username, String password) throws Exception {

        String BOUNDRY = "==================================";
        HttpURLConnection conn = null;

        try {

            // These strings are sent in the request body. They provide information about the file being uploaded
            String contentDisposition = "Content-Disposition: form-data; name=\"userfile\"; filename=\"" + file.getName() + "\"";
            String contentType = "Content-Type: application/octet-stream";

            // This is the standard format for a multipart request
            StringBuffer requestBody = new StringBuffer();
            requestBody.append("--");
            requestBody.append(BOUNDRY);
            requestBody.append('\n');
            requestBody.append(contentDisposition);
            requestBody.append('\n');
            requestBody.append(contentType);
            requestBody.append('\n');
            requestBody.append('\n');
            requestBody.append(new String(Util.getBytesFromFile(file)));
            requestBody.append("--");
            requestBody.append(BOUNDRY);
            requestBody.append("--");

            // Make a connect to the server
            URL url = new URL(targetURL);
            conn = (HttpURLConnection) url.openConnection();

            // Put the authentication details in the request
            if (username != null) {
                String usernamePassword = username + ":" + password;
                String encodedUsernamePassword = Base64.encodeBytes(usernamePassword.getBytes());
                conn.setRequestProperty ("Authorization", "Basic " + encodedUsernamePassword);
            }

            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setUseCaches(false);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDRY);

            // Send the body
            DataOutputStream dataOS = new DataOutputStream(conn.getOutputStream());
            dataOS.writeBytes(requestBody.toString());
            dataOS.flush();
            dataOS.close();

            // Ensure we got the HTTP 200 response code
            int responseCode = conn.getResponseCode();
            if (responseCode != 200) {
                throw new Exception(String.format("Received the response code %d from the URL %s", responseCode, url));
            }

            // Read the response
            InputStream is = conn.getInputStream();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] bytes = new byte[1024];
            int bytesRead;
            while((bytesRead = is.read(bytes)) != -1) {
                baos.write(bytes, 0, bytesRead);
            }
            byte[] bytesReceived = baos.toByteArray();
            baos.close();

            is.close();
            String response = new String(bytesReceived);

            // TODO: Do something here to handle the 'response' string

        } finally {
            if (conn != null) {
                conn.disconnect();
            }
        }

    }</code></pre>
<p>There&#8217;s nothing in this code particular to Android so it will work in any java application.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.17od.com/2010/02/18/multipart-form-upload-on-android/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Identifying Performance Issues on Android</title>
		<link>http://www.17od.com/2010/02/09/identifying-performance-issues-on-android/</link>
		<comments>http://www.17od.com/2010/02/09/identifying-performance-issues-on-android/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 20:06:37 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[android]]></category>

		<guid isPermaLink="false">http://www.17od.com/?p=256</guid>
		<description><![CDATA[While application performance is always in the back of your mind when developing PC applications it becomes much more important when developing on a mobile platform. The hardware is slower and the user expectations are much higher. This problem came to the fore for me recently as I was porting UPM to the Android platform. [...]]]></description>
			<content:encoded><![CDATA[<p>While application performance is always in the back of your mind when developing PC applications it becomes much more important when developing on a mobile platform. The hardware is slower and the user expectations are much higher.</p>
<p>This problem came to the fore for me recently as I was porting <a href="http://upm.sourceforge.net/">UPM</a> to the Android platform. Since UPM is a Java application I was able to reuse quite a bit of the code with little or no modification (all bar the SWING code actually).</p>
<p>During the porting process I found that opening the password database on the Android Emulator took about 12 seconds. This was a sub-second operation on the PC version so there was obviously a problem. Using <a href="http://developer.android.com/guide/developing/tools/traceview.html">Traceview</a>, the profiling tool that comes with the <a href="http://developer.android.com/sdk/index.html">Android SDK</a>, the problem soon became apparent.</p>
<p>UPM stores all it&#8217;s data in an encrypted file. This file is read into memory where it&#8217;s decrypted. Here&#8217;s the code that was reading in the file&#8230;</p>
<pre><code>FileInputStream fis = new FileInputStream(databaseFile);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i = 0;
while ((i = fis.read()) != -1) {
    baos.write(i);
}
byte[] fullDatabase = baos.toByteArray();
baos.close();
fis.close();</code></pre>
<p>Looking at it now it&#8217;s obviously bad code from a performance point of view as it&#8217;s reading in the file byte by byte. The reason I never replaced it was that it simply wasn&#8217;t a problem when running on a PC. The database file it reads is only a few kilobytes in size so it ran in under a second.</p>
<p>After identifying the bad code I replaced it with the following which runs in under a second.</p>
<pre><code>InputStream is = new FileInputStream(file);

// Get the size of the file
long length = file.length();

// Create the byte array to hold the data
byte[] bytes = new byte[(int)length];

// Read in the bytes
int offset = 0;
int numRead = 0;
while (offset < bytes.length &#038;&#038; (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
    offset += numRead;
}

// Ensure all the bytes have been read in
if (offset < bytes.length) {
    throw new IOException("Could not completely read file " + file.getName());
}

is.close();</code></pre>
<p>The lesson here is that Android, and mobile platforms in general, require you think a little bit more about elements of your design and code than you might normally.</p>
<p>Some useful Android links:<br />
<a href="http://developer.android.com/guide/practices/design/performance.html">Designing for Performance</a><br />
<a href="http://developer.android.com/guide/practices/design/responsiveness.html">Designing for Responsiveness</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.17od.com/2010/02/09/identifying-performance-issues-on-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UPM 1.0 for Android</title>
		<link>http://www.17od.com/2010/01/29/upm-1-0-for-android/</link>
		<comments>http://www.17od.com/2010/01/29/upm-1-0-for-android/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 08:49:48 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[upm]]></category>

		<guid isPermaLink="false">http://www.17od.com/?p=211</guid>
		<description><![CDATA[There&#8217;s nothing like the feeling of relief the day after a software release. Even when it&#8217;s only something small you&#8217;re still putting your creation out into the big bad world to be pored over. Over the past few weeks I&#8217;ve been working on a version of UPM for Android. This was mainly an exploratory exercise [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s nothing like the feeling of relief the day after a software release. Even when it&#8217;s only something small you&#8217;re still putting your creation out into the big bad world to be pored over.</p>
<p>Over the past few weeks I&#8217;ve been working on a version of <a href="http://sourceforge.net/projects/upm/">UPM</a> for Android. This was mainly an exploratory exercise so that I could get a feel for Android but it&#8217;s nice to have something useful at the end of it.</p>
<p>UPM is cross platform, easy to use password manager. It runs on Windows, OS X (native L&#038;F), Linux and now Android. It&#8217;s available on the <a href="http://www.android.com/market/">Android Market</a> or by <a href="https://sourceforge.net/projects/upm/files/">direct download</a>.</p>
<p>I hope you find it useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.17od.com/2010/01/29/upm-1-0-for-android/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>

