<?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>lexanderA &#187; Android</title>
	<atom:link href="http://lexandera.com/tag/android/feed/" rel="self" type="application/rss+xml" />
	<link>http://lexandera.com</link>
	<description>A blog about the web, mobile web, semantic web and mobile semantic web.</description>
	<lastBuildDate>Sun, 06 Jun 2010 18:27:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Replacing menus with dashboards</title>
		<link>http://lexandera.com/2009/09/replacing-menus-with-dashboards/</link>
		<comments>http://lexandera.com/2009/09/replacing-menus-with-dashboards/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 09:00:23 +0000</pubDate>
		<dc:creator>Aleksander Kmetec</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Ideas]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[dashboard]]></category>
		<category><![CDATA[Menu]]></category>
		<category><![CDATA[tabs]]></category>
		<category><![CDATA[url field]]></category>
		<category><![CDATA[UX]]></category>

		<guid isPermaLink="false">http://lexandera.com/?p=485</guid>
		<description><![CDATA[Is it just me, or do most dialogs on Android seem to be removed really, really far away from the main parts of applications?
Not sure what I&#8217;m talking about?
Let&#8217;s take a look at the browser, for example. Just entering a new URL requires you to go through 3 different screens:

By the time you can start [...]]]></description>
			<content:encoded><![CDATA[<p>Is it just me, or do most dialogs on Android seem to be removed really, really far away from the main parts of applications?</p>
<p>Not sure what I&#8217;m talking about?</p>
<p>Let&#8217;s take a look at the browser, for example. Just entering a new URL requires you to go through 3 different screens:</p>
<p><a href="http://lexandera.com/wp-content/uploads/2009/09/1_current.png"><img class="alignnone size-full wp-image-498" src="http://lexandera.com/wp-content/uploads/2009/09/1_current_small.png" alt="" width="714" height="180" /></a></p>
<p>By the time you can start typing it feels like you&#8217;re already in a different application<sup class='footnote'><a href='#fn-485-1' id='fnref-485-1'>1</a></sup>. Switching to a different window also involves going to a special part of the application designed to handle this single task.</p>
<p>This pattern is not limited just to the browser. Entering an address in the maps application or searching the list of your contacts also involves going through several steps.</p>
<p>Back to the browser&#8230;</p>
<p>If you take a look the UI of a regular browser you can immediately see a number of frequently used elements such as the location bar, the back button and tabs for switching between windows. Those UI elements are always visible and usable with a single click. On mobile devices things are a bit different. Because of limited screen sizes most of browser&#8217;s UI is either eating away precious screen real estate (like on the iPhone) or is hidden behind a menu button (like on Android).</p>
<p>Except that because of the nature of menus, many of those features are not hidden just behind the menu button, but also behind an item on that menu.</p>
<p>Now, just as I&#8217;m typing this, <a class="zem_slink" title="Marissa Mayer" rel="wikipedia" href="http://en.wikipedia.org/wiki/Marissa_Mayer">Marissa Mayer</a> is on the stage at <a class="zem_slink" title="TechCrunch50" rel="homepage" href="http://www.TechCrunch50.com">TechCrunch50</a> introducing <a href="http://fastflip.googlelabs.com/">Google fast flip</a> and talking about how Google is obsessed with speed and shaving milliseconds off of repetitive interactions. So what can can we do to speed up interaction with Google&#8217;s mobile browser?</p>
<p>First, we need to understand what&#8217;s wrong with menus.</p>
<p>A typical menu is a list of actions available for that application, but most of those actions can&#8217;t be performed from the menu itself. Instead, selecting an item takes you somewhere else where that action can finally be performed. In essence, a menu keeps asking the question &#8220;What do you want to do?&#8221; over and over again and the user then needs to explicitly say that he wants to go to to the place where he can type in an URL or go to the place where he can switch to a different window, etc.</p>
<p>How do we handle this situation where we know that in many applications the user&#8217;s answer to the menu&#8217;s question is going to be the same most of the time?</p>
<p>Like it is the case usually these days, the solution can already be found on the iPhone. No real surprise there. The iPhone doesn&#8217;t have built-in support for application menus which could be copied, but it does have this:</p>
<p><a href="http://lexandera.com/wp-content/uploads/2009/09/music_dashboard.png"><img class="alignnone size-full wp-image-499" src="http://lexandera.com/wp-content/uploads/2009/09/music_dashboard.png" alt="" width="211" height="159" /></a></p>
<p>What you&#8217;re looking at is a special dashboard for controlling music playback, which can be brought up by pressing the home button twice.</p>
<p>With a bit of bad luck &#8211; or bad judgment &#8211; this could have easily been implemented as a list of items such as &#8220;adjust volume&#8221; and &#8220;control playback&#8221;, with each of them leading to a new screen where that action could be performed. But instead its designers made it possible to perform common actions directly from the pop-up and added a &#8220;Music&#8221; button that takes you to that other app where the rest of the playback controls are.</p>
<p>So let&#8217;s take this dashboard pattern and apply it to Android&#8217;s browser menu:</p>
<p><a href="http://lexandera.com/wp-content/uploads/2009/09/2_alt1.png"><img class="alignnone size-full wp-image-500" title="2_alt1_small" src="http://lexandera.com/wp-content/uploads/2009/09/2_alt1_small.png" alt="2_alt1_small" width="544" height="180" /></a></p>
<p>While some features (like bookmarks) still remain hidden behind a menu button, the two most commonly used ones are immediately presented in usable form. The &#8220;go&#8221; button is replaced by an actual location bar and the &#8220;Windows&#8221; button is replaced by thumbnails of windows. You now no longer need to announce first that you want to go to a different page or switch to a different tab; you can perform that action directly instead.</p>
<p>A quick before/after comparison:</p>
<div>
<table id="c0m_" border="0" cellspacing="0" cellpadding="3" bordercolor="#000000">
<tbody style="font-size:90%;">
<tr>
<td style="border-bottom: 1px solid grey;"><strong>Action</strong></td>
<td style="border-bottom: 1px solid grey;"><strong>Before</strong></td>
<td style="border-bottom: 1px solid grey;"><strong>After</strong></td>
</tr>
<tr>
<td>Loading a web page</td>
<td>press &#8220;menu&#8221; → press &#8220;go&#8221; → focus URL field (3 steps)</td>
<td>press &#8220;menu&#8221; → focus URL field (2 steps)</td>
</tr>
<tr>
<td>Switching to a different window</td>
<td>press &#8220;menu&#8221; → press &#8220;tabs&#8221; → select tab (3 steps)</td>
<td>press &#8220;menu&#8221; → select tab (2 steps)</td>
</tr>
</tbody>
</table>
</div>
<p>Removing a single step here and there may not seem like much, but it adds up. Making a typo in the URL or working with several windows suddenly becomes just a little bit less frustrating. A simple improvement that can be achieved simply by ignoring the established meaning of the word &#8220;menu&#8221;.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/pixy.gif?x-id=6586ad72-cb6a-4cc4-902f-85df0363cdfb" alt="" /><span class="zem-script more-related pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-485-1'>Sure, if you have a phone with a physical keyboard you can just start typing and invoke the default action without going through menus, but what if your phone uses an onscreen keyboard or if you want to use some other action? <span class='footnotereverse'><a href='#fnref-485-1'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://lexandera.com/2009/09/replacing-menus-with-dashboards/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>The Future of Mobile Browsers</title>
		<link>http://lexandera.com/2009/07/the-future-of-mobile-browsers/</link>
		<comments>http://lexandera.com/2009/07/the-future-of-mobile-browsers/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 15:39:25 +0000</pubDate>
		<dc:creator>Aleksander Kmetec</dc:creator>
				<category><![CDATA[Ideas]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Mobile web]]></category>
		<category><![CDATA[Semantic Web]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Browsers]]></category>
		<category><![CDATA[semantic]]></category>
		<category><![CDATA[Semantic tagging]]></category>
		<category><![CDATA[Web browser]]></category>

		<guid isPermaLink="false">http://lexandera.com/?p=436</guid>
		<description><![CDATA[Not that long ago, while my coworkers were attending a conference in London, I was spending my time wandering around the city in full tourist mode, trying to find a shop I had read about on the Internet but that didn&#8217;t seem to actually exist in real life. Although I was pretty sure I was [...]]]></description>
			<content:encoded><![CDATA[<p>Not that long ago, while my coworkers were attending a conference in London, I was spending my time wandering around the city in full tourist mode, trying to find a shop I had read about on the Internet but that didn&#8217;t seem to actually exist in real life. Although I was pretty sure I was on the right street I couldn&#8217;t find it and nobody I asked about it had the slightest idea about where it could be located.</p>
<p>This problem should be easily solvable in our age of ubiquitous connectivity, right? All I had to do was take out my mobile phone, fire up the web browser, check the shop&#8217;s website for the address and locate it using Google maps. How hard could that be? Very hard, as it turned out.</p>
<p>The experience of trying to perform this task was so horribly bad that in the end I wound up walking to Apple store a couple of streets away and waiting in line for a display iMac so that I could find the information I needed, copy it to a piece of paper and finally walk back. Yes, that was in fact a better alternative to trying to accomplish anything using a mobile browser.</p>
<p>A year and a half has passed since, but things haven&#8217;t changed much for the better. Even though connection speeds have gotten better and hardware is now much faster, the gap between mobile devices and computers is still huge and browsing the web on a mobile device can still be rather frustrating experience. Unlike computers, which these days have large displays running at high resolutions and are coupled with mice which give users pixel-accurate cursor control, mobile devices still have tiny touch screens and pointer accuracy of around 400 square pixels&#8230; if you&#8217;re lucky enough to have pointy fingers.</p>
<p>And despite their differences we use both types of devices for accessing the same websites.</p>
<p>So you&#8217;d probably think that browsers running on mobile devices with their tiny screens, clumsy keyboards and imprecise pointer control would be the ones getting all the usability improvements and fancy automated features. But you&#8217;d be wrong. What&#8217;s curious to me is that despite the fact that mobile devices are the ones with highly obvious usability problems, desktop browsers &#8211; which are already much easier to use &#8211; are the ones getting all the improvements. <a href="http://www.teesoft.info/content/view/68/1/lang,en/">Autopager</a>, <a href="http://adblockplus.org/en/">Adblock</a>, <a href="http://www.greasespot.net/">Greasemonkey</a>, <a href="http://userstyles.org/stylish/">Stylish</a>, <a href="http://lab.arc90.com/experiments/readability/">Readability</a>/<a href="http://www.tidyread.com/">Tidyread</a>, Bookmarklets, <a href="http://www.microsoft.com/windows/internet-explorer/features/easier.aspx">Web slices</a>, <a href="http://www.microsoft.com/windows/internet-explorer/features/faster.aspx">Accelerators</a> and many others are features mobile users can only wish for<sup class='footnote'><a href='#fn-436-1' id='fnref-436-1'>1</a></sup>.</p>
<p>What about usability features specific to mobile browsers? Apart form the &#8220;.com&#8221; button on iPhone&#8217;s virtual keyboard I really can&#8217;t think of any. As a matter of fact, I&#8217;m having a difficult time thinking of a single user-facing feature available in today&#8217;s mobile browsers that wasn&#8217;t already present in Netscape Navigator in the mid 90s<sup class='footnote'><a href='#fn-436-2' id='fnref-436-2'>2</a></sup>.</p>
<p>So what can we do to bring mobile browsers into the modern times?</p>
<p><strong>1. The single most important feature need by mobile browsers is support for extensions.</strong></p>
<p>When was the last time you tried out an interesting mobile browser extension? I&#8217;d say never. Since most mobile browsers have no support for extensions whatsoever, you couldn&#8217;t do it even if you wanted to.</p>
<p>Once it&#8217;s possible to easily extend the browser anyone can start experimenting and adding features, but without that the existing browser is a dead end. Developers who want to add even a tiniest feature need to re-implement the whole browser functionality around the page rendering component. And I know from personal experience that doing this and then sneaking code for additional functionality in through the back door is a truly awful way of adding features. Not only is it a lot of work for the developer, but it&#8217;s also rather inconvenient and unlikely for users to try out a new browser.</p>
<p><strong>2. Mobile browsers need to become content aware.</strong></p>
<p>Now that the miracle of copy&amp;paste has finally arrived to the world of mobile phones, performing some tasks like moving an address from the browser into the maps application has become slightly easier. But is this really enough to keep us happy for the next few years? Even on desktop computers where performing such a task takes only a second, copying from the browser and pasting into another app is no longer considered good enough.</p>
<p>Internet Explorer 8 now supports accelerators (so does Firefox, via IE8 Activities add-on) which perform such tasks for you. They are not perfect, of course. One problem is that all accelerators are offered every time, even if they make no sense in the given context:</p>
<div id="attachment_438" class="wp-caption alignnone" style="width: 304px"><img class="size-full wp-image-438 " title="IE8 Accelerators" src="http://lexandera.com/wp-content/uploads/2009/06/ie8-accelerators.png" alt="IE8 Accelerators" width="294" height="159" /><p class="wp-caption-text">Suggested accelerators don&#39;t always make sense</p></div>
<p>This same problem will be bigger on mobile devices &#8211; once and if they gain support for accelerators. I predict that more accelerators will be needed due to the limited nature of the devices, but displaying them all won&#8217;t work very well on small screens. Which is where content awareness comes into play. If the browser knew what kind of content you just selected it could present you only with options which make sense at that moment. Even better &#8211; most of the time selecting the text could be skipped altogether since the browser would already know where something starts and ends and could attach accelerators to that piece of content in advance. It could even grab new accelerators online if it determines using them would make sense.</p>
<p>There are several ways content awareness could be implemented. Microformats and RDFa immediately spring to mind, but since they are about as common in the wild as pink flying giraffes, some other solutions would need to be found. Alternatives might include external content descriptions and extraction rules (possibly <a href="/2009/04/crowdsourcing-the-semantic-web/">crowdsourced</a>), downloadable sets of algorithms for detection, data extracted by services like <a href="http://developer.yahoo.com/yql/">YQL open data tables</a> or <a href="http://en.wikipedia.org/wiki/Natural_language_processing">NLP</a> services&#8230; But more about that some other time.</p>
<p>What I believe is important is that this content recognition should be performed by a centralized framework and available to all extensions so they don&#8217;t need to do their own parsing. Some basic work in this direction has been done with the Operator toolbar and Firefox&#8217;s support for Microformats, but in my opinion such functionality is much more needed in mobile browsers.</p>
<p><strong>3. Browsers need to start detecting and exposing available extensions</strong></p>
<p>You&#8217;re visiting a page that contains several events which can be added to your calendar and a table which can be displayed as a chart. Someone has created an alternative stylesheet which removes the huge header and there is also a mobile widget which allows you to interact with he same service in a more mobile-friendly way. But you&#8217;re never going to know about them and use them if your browser doesn&#8217;t notify you about their existence and make it easy to install and use them.</p>
<p><strong>4.  We need support for client-side content modification<br />
</strong><br />
Some might disagree, but I believe we do.</p>
<p>How many times have you had to zoom in just so you could click the link to the next page in a sequence of pages, or pan around to find where that huge header ends and content starts? You don&#8217;t need to put up with any of this if you&#8217;re browsing the web on a computer. All sorts of common annoyances can be solved by simple tweaks, and extensions for desktop browsers have been making it possible to do this for years. By augmenting, modifying and filtering content they not only make it easier to access content you&#8217;re interested in, but also <a href="/2009/05/the-future-is-in-the-ability-to-ignore/">make it possible to ignore</a> irrelevant parts of pages.</p>
<p>&#8211;</p>
<p>These are just some ideas about what the future of mobile browsers could look like. You might not agree with me on whether content awareness and even content modification are going to be important factors in the future of mobile browsing, but there&#8217;s one thing which is difficult to disagree with: a lot of work still needs to be done in order to turn mobile browsing into a user-friendly experience.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/pixy.gif?x-id=a3e797fb-ff75-4032-b8f9-e128d814ee9d" alt="" /><span class="zem-script more-related pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-436-1'>While iPhone&#8217;s browser does support bookmarklets, they&#8217;re still a royal pain to set up. <span class='footnotereverse'><a href='#fnref-436-1'>&#8617;</a></span></li>
<li id='fn-436-2'>I wanted to list pinch-to-zoom here but I realized it&#8217;s more of an OS feature than a browser feature. <span class='footnotereverse'><a href='#fnref-436-2'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://lexandera.com/2009/07/the-future-of-mobile-browsers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How is Mosembro different from OilCan?</title>
		<link>http://lexandera.com/2009/02/how-is-mosembro-different-from-oilcan/</link>
		<comments>http://lexandera.com/2009/02/how-is-mosembro-different-from-oilcan/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 03:42:24 +0000</pubDate>
		<dc:creator>Aleksander Kmetec</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Mosembro]]></category>
		<category><![CDATA[Microformat]]></category>
		<category><![CDATA[OilCan]]></category>

		<guid isPermaLink="false">http://lexandera.com/?p=286</guid>
		<description><![CDATA[



Image via Wikipedia



If you looked at OilCan &#8211; a Greasemonkey-like browser extension for Android &#8211; and Mosembro, you&#8217;d quickly realize that they have a lot in common. Both are experimental browser extensions which run on Android, both aim to make websites friendlier, both support installable actions written in JavaScript, and both make it possible for [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl class="wp-caption alignright" style="width: 212px;">
<dt class="wp-caption-dt"><a href="http://en.wikipedia.org/wiki/Image:Android-logo.svg"><img title="Alternate logo." src="http://upload.wikimedia.org/wikipedia/en/thumb/c/c2/Android-logo.svg/202px-Android-logo.svg.png" alt="Alternate logo." width="202" height="202" /></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;">Image via <a href="http://en.wikipedia.org/wiki/Image:Android-logo.svg">Wikipedia</a></dd>
</dl>
</div>
</div>
<p>If you looked at <a href="http://www.jsharkey.org/blog/2008/12/15/oilcan-greasemonkey-on-steroids-for-android/">OilCan</a> &#8211; a <a class="zem_slink" title="Greasemonkey" rel="homepage" href="http://www.greasespot.net">Greasemonkey</a>-like browser extension for <a class="zem_slink" title="Android" rel="homepage" href="http://code.google.com/android/">Android</a> &#8211; and <a href="/mosembro/">Mosembro</a>, you&#8217;d quickly realize that they have a lot in common. Both are experimental browser extensions which run on Android, both aim to make websites friendlier, both support installable actions written in JavaScript, and both make it possible for those scripts to modify web pages and launch other applications. And since looking at OilCan&#8217;s source code has allowed me to avoid reinventing the wheel at several occasions, some pretty obvious similarities can also be spotted at the source code level.</p>
<p>So, with so many things in common, how are they different at all?</p>
<p>The main difference, I believe, is what causes user scripts to be triggered. A typical OilCan script is triggered by a web page&#8217;s URL and is executed only once. Its goal is to change the content or functionality of a very specific document. Mosembro scripts, on the other hand, are triggered by embedded microformats and can be executed dozens of times for each page, while not caring about which page they were executed on.</p>
<p>I could say at this point that OilCan&#8217;s approach to invoking scripts could be compared to function calls in programming languages and Mosembro&#8217;s approach compared to what is done in aspect oriented programming, with functionality implemented by actions attached to bits of semantic content being <a href="http://en.wikipedia.org/wiki/Cross-cutting_concern">cross-cutting concerns</a>, but I&#8217;m not sure about it, so I won&#8217;t. ;-)</p>
<p>Also, because Mosembro is very narrowly focused on adding functionality to web pages based on semantic data embedded in them it can also provide additional infrastructure, like microformat parsers and action menus, which wouldn&#8217;t exactly fit in with a more general purpose framework. And finally, there&#8217;s the integrated support for site-level search.</p>
<p>So, there you have it. While it&#8217;s true that both apps have a lot in common, it&#8217;s their unique features that really matter.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Zemified by Zemanta" href="http://reblog.zemanta.com/zemified/c8ae4d89-28da-43e3-8556-0ee417dbfa47/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/reblog_e.png?x-id=c8ae4d89-28da-43e3-8556-0ee417dbfa47" alt="Reblog this post [with Zemanta]" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://lexandera.com/2009/02/how-is-mosembro-different-from-oilcan/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Intercepting page loads in WebView</title>
		<link>http://lexandera.com/2009/02/intercepting-page-loads-in-webview/</link>
		<comments>http://lexandera.com/2009/02/intercepting-page-loads-in-webview/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 05:20:38 +0000</pubDate>
		<dc:creator>Aleksander Kmetec</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[WebView examples]]></category>
		<category><![CDATA[WebView]]></category>
		<category><![CDATA[WebViewClient]]></category>

		<guid isPermaLink="false">http://lexandera.com/?p=213</guid>
		<description><![CDATA[It is time for another WebView example. This time on how you can intercept any attempts at loading a web page and redirect the user to a different URL instead.
This can be achieved simply by registering a WebViewClient which overrides the shouldOverrideUrlLoading() method in which you tell the WebView to load a different URL from [...]]]></description>
			<content:encoded><![CDATA[<p>It is time for another <a href="http://code.google.com/android/reference/android/webkit/WebView.html">WebView</a> example. This time on how you can intercept any attempts at loading a web page and redirect the user to a different URL instead.</p>
<p>This can be achieved simply by registering a <a href="http://code.google.com/android/reference/android/webkit/WebViewClient.html">WebViewClient</a> which overrides the <a href="http://code.google.com/android/reference/android/webkit/WebViewClient.html#shouldOverrideUrlLoading(android.webkit.WebView,%20java.lang.String)">shouldOverrideUrlLoading</a>() method in which you tell the WebView to load a different URL from the one the user had requested.</p>
<p>The example below loads lexandera.com first, but when the user clicks any link on the page, he is redirected to yahoo.com:</p>
<pre name="code" class="java">

WebView browser = (WebView)findViewById(R.id.browser);
browser.setWebViewClient(new WebViewClient() {
    /* On Android 1.1 shouldOverrideUrlLoading() will be called every time the user clicks a link,
     * but on Android 1.5 it will be called for every page load, even if it was caused by calling loadUrl()! */
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {
        /* intercept all page load attempts and load yahoo.com instead */
        String myAlternativeURL = &quot;http://yahoo.com&quot;;
        if (!url.equals(myAlternativeURL)) {
            view.loadUrl(myAlternativeURL);
            return true;
        }

        return false;
    }
});

browser.loadUrl(&quot;http://lexandera.com/&quot;);
</pre>
<p><del datetime="2009-08-25T05:42:59+00:00">Please note that calling <a href="http://code.google.com/android/reference/android/webkit/WebView.html#loadUrl(java.lang.String)">loadUrl</a>() does not trigger the shouldOverrideUrlLoading() method, which means that we do not need to worry about endless recursion when calling loadUrl() from within shouldOverrideUrlLoading()! </del></p>
<p><strong>UPDATE</strong>: The above statement is no longer true for Android 1.5! Calling <a href="http://code.google.com/android/reference/android/webkit/WebView.html#loadUrl(java.lang.String)">loadUrl</a>() will now also trigger the shouldOverrideUrlLoading() method! This means that you need to make sure that you are not creating an infinite loop when calling loadUrl() from shouldOverrideUrlLoading()!</p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/ed91eca5-2c5e-4b86-8b88-8af5a1b703f7/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=ed91eca5-2c5e-4b86-8b88-8af5a1b703f7" alt="Reblog this post [with Zemanta]"></a></div>
]]></content:encoded>
			<wfw:commentRss>http://lexandera.com/2009/02/intercepting-page-loads-in-webview/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Extracting HTML from a WebView</title>
		<link>http://lexandera.com/2009/01/extracting-html-from-a-webview/</link>
		<comments>http://lexandera.com/2009/01/extracting-html-from-a-webview/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 19:30:33 +0000</pubDate>
		<dc:creator>Aleksander Kmetec</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Semantic Web]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[WebView examples]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[WebView]]></category>
		<category><![CDATA[WebViewClient]]></category>

		<guid isPermaLink="false">http://lexandera.com/?p=200</guid>
		<description><![CDATA[Here&#8217;s another Android WebView tutorial for those of you who are looking for a way to get the source code of a page loaded in a WebView instance.
This example is a bit more complicated than previous ones, so let me explain it step by step:

First, a class called MyJavaScriptInterface is defined. It implements a single [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s another Android <a href="http://code.google.com/android/reference/android/webkit/WebView.html">WebView</a> tutorial for those of you who are looking for a way to get the source code of a page loaded in a WebView instance.</p>
<p>This example is a bit more complicated than previous ones, so let me explain it step by step:</p>
<ul>
<li>First, a class called MyJavaScriptInterface is defined. It implements a single public method showHTML() which displays a dialog with the HTML it receives as a parameter.</li>
<li>Then, an instance of this class is registered as a JavaScript interface called HTMLOUT. The showHTML() method can now be accessed from JavaScript like this: window.HTMLOUT.showHTML(&#8216;&#8230;&#8217;) </li>
<li>In order to call showHTML() when the page finishes loading, a <a href="http://code.google.com/android/reference/android/webkit/WebViewClient.html">WebViewClient</a> instance which overrides <a href="http://code.google.com/android/reference/android/webkit/WebViewClient.html#onPageFinished%28android.webkit.WebView,%20java.lang.String%29">onPageFinished</a>() is added to the WebView. When the page finises loading, this method will inject a piece of JavaScript code into the page, using <a href="http://lexandera.com/2009/01/injecting-javascript-into-a-webview/">the method I described in an earlier post</a>.</li>
<li>Finally, a web page is loaded.</li>
</ul>
<pre name="code" class="java">

final Context myApp = this;

/* An instance of this class will be registered as a JavaScript interface */
class MyJavaScriptInterface
{
    @SuppressWarnings(&quot;unused&quot;)
    public void showHTML(String html)
    {
        new AlertDialog.Builder(myApp)
            .setTitle(&quot;HTML&quot;)
            .setMessage(html)
            .setPositiveButton(android.R.string.ok, null)
        .setCancelable(false)
        .create()
        .show();
    }
}

final WebView browser = (WebView)findViewById(R.id.browser);
/* JavaScript must be enabled if you want it to work, obviously */
browser.getSettings().setJavaScriptEnabled(true);

/* Register a new JavaScript interface called HTMLOUT */
browser.addJavascriptInterface(new MyJavaScriptInterface(), &quot;HTMLOUT&quot;);

/* WebViewClient must be set BEFORE calling loadUrl! */
browser.setWebViewClient(new WebViewClient() {
    @Override
    public void onPageFinished(WebView view, String url)
    {
        /* This call inject JavaScript into the page which just finished loading. */
        browser.loadUrl(&quot;javascript:window.HTMLOUT.showHTML(&#039;&lt;head&gt;&#039;+document.getElementsByTagName(&#039;html&#039;)[0].innerHTML+&#039;&lt;/head&gt;&#039;);&quot;);
    }
});

/* load a web page */
browser.loadUrl(&quot;http://lexandera.com/files/jsexamples/gethtml.html&quot;);
</pre>
<p><strong>WARNING</strong><br />
Unfortunately, this approach suffers from a major security hole: if your JavaScript can call showHTML(), then so can JavaScript from every other page that might get loaded into the WebView. Use with care.</p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/bb22593d-ec9d-4064-9842-2bcb7fae4d4f/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=bb22593d-ec9d-4064-9842-2bcb7fae4d4f" alt="Reblog this post [with Zemanta]"></a></div>
]]></content:encoded>
			<wfw:commentRss>http://lexandera.com/2009/01/extracting-html-from-a-webview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding alert() support to a WebView</title>
		<link>http://lexandera.com/2009/01/adding-alert-support-to-a-webview/</link>
		<comments>http://lexandera.com/2009/01/adding-alert-support-to-a-webview/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 20:54:09 +0000</pubDate>
		<dc:creator>Aleksander Kmetec</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[WebView examples]]></category>
		<category><![CDATA[WebChromeClient]]></category>
		<category><![CDATA[WebView]]></category>

		<guid isPermaLink="false">http://lexandera.com/?p=191</guid>
		<description><![CDATA[As promised earlier, here is an example of how to add support for alert() function to a WebView in your Android application:


final WebView browser = (WebView)findViewById(R.id.browser);
/* JavaScript must be enabled if you want it to work, obviously */
browser.getSettings().setJavaScriptEnabled(true);

final Context myApp = this;

/* WebChromeClient must be set BEFORE calling loadUrl! */
browser.setWebChromeClient(new WebChromeClient() {
    [...]]]></description>
			<content:encoded><![CDATA[<p>As promised earlier, here is an example of how to add support for alert() function to a WebView in your <a class="zem_slink" href="http://code.google.com/android/" title="Android" rel="homepage">Android</a> application:</p>
<pre name="code" class="java">

final WebView browser = (WebView)findViewById(R.id.browser);
/* JavaScript must be enabled if you want it to work, obviously */
browser.getSettings().setJavaScriptEnabled(true);

final Context myApp = this;

/* WebChromeClient must be set BEFORE calling loadUrl! */
browser.setWebChromeClient(new WebChromeClient() {
    @Override
    public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result)
    {
        new AlertDialog.Builder(myApp)
            .setTitle(&quot;javaScript dialog&quot;)
            .setMessage(message)
            .setPositiveButton(android.R.string.ok,
                    new AlertDialog.OnClickListener()
                    {
                        public void onClick(DialogInterface dialog, int which)
                        {
                            result.confirm();
                        }
                    })
            .setCancelable(false)
            .create()
            .show();

        return true;
    };
});

/* load a web page which uses the alert() function */
browser.loadUrl(&quot;http://lexandera.com/files/jsexamples/alert.html&quot;);
</pre>
<p>Code for adding support for confirm() and prompt() is almost identical and can be found in <a href="http://code.google.com/p/mosembro/source/browse/trunk/src/com/lexandera/mosembro/Mosembro.java?spec=svn12&amp;r=12#137">Mosembro&#8217;s source code</a>. </p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/62e34ae6-3382-45cb-b4f5-f08a367c4a80/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=62e34ae6-3382-45cb-b4f5-f08a367c4a80" alt="Reblog this post [with Zemanta]"></a></div>
]]></content:encoded>
			<wfw:commentRss>http://lexandera.com/2009/01/adding-alert-support-to-a-webview/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Android WebChromeClient</title>
		<link>http://lexandera.com/2009/01/android-webchromeclient/</link>
		<comments>http://lexandera.com/2009/01/android-webchromeclient/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 03:30:16 +0000</pubDate>
		<dc:creator>Aleksander Kmetec</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[WebView examples]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[WebChromeClient]]></category>
		<category><![CDATA[WebView]]></category>

		<guid isPermaLink="false">http://lexandera.com/?p=179</guid>
		<description><![CDATA[My blog stats are telling me that many visitors are arriving here looking for examples on how to implement WebChromeClient on Android. I don&#8217;t (yet) have a nice article about how to do it, but you can have a look at how I implemented WebChromeClient in Mosembro, if you came here for that reason. Just [...]]]></description>
			<content:encoded><![CDATA[<p>My blog stats are telling me that many visitors are arriving here looking for examples on how to implement <a href="http://code.google.com/android/reference/android/webkit/WebChromeClient.html">WebChromeClient</a> on <a class="zem_slink" title="Android" rel="homepage" href="http://code.google.com/android/">Android</a>. I don&#8217;t (yet) have a nice article about how to do it, but you can <a href="http://code.google.com/p/mosembro/source/browse/trunk/src/com/lexandera/mosembro/Mosembro.java">have a look at how I implemented WebChromeClient in Mosembro</a>, if you came here for that reason. Just use your browser&#8217;s search functionality and look for &#8220;new WebChromeClient&#8221;.</p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/b89819f7-2769-4fb9-91f8-ab40a0b3e67b/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=b89819f7-2769-4fb9-91f8-ab40a0b3e67b" alt="Reblog this post [with Zemanta]"></a></div>
]]></content:encoded>
			<wfw:commentRss>http://lexandera.com/2009/01/android-webchromeclient/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Caller id 2.0</title>
		<link>http://lexandera.com/2009/01/caller-id-20/</link>
		<comments>http://lexandera.com/2009/01/caller-id-20/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 00:31:27 +0000</pubDate>
		<dc:creator>Aleksander Kmetec</dc:creator>
				<category><![CDATA[Ideas]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Address book]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Caller ID]]></category>
		<category><![CDATA[Ribbit]]></category>
		<category><![CDATA[Unknown number]]></category>

		<guid isPermaLink="false">http://lexandera.com/?p=165</guid>
		<description><![CDATA[Have you ever returned a missed phone call from an unknown number only to discover that the person on the other side had dialed the wrong number? Or have you at least wondered at one point who it could be calling you, when all your phone was displaying was a number you&#8217;ve never seen before? [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever returned a missed phone call from an unknown number only to discover that the person on the other side had dialed the wrong number? Or have you at least wondered at one point who it could be calling you, when all your phone was displaying was a number you&#8217;ve never seen before? If you answered yes to any of these questions, then you&#8217;ll probably like the idea I&#8217;m about to describe.</p>
<p>Thanks to the fact that you can replace any piece of software on an <a class="zem_slink" href="http://www.android.com" title="Android" rel="homepage">Android</a> phone &#8211; even the dialer, the list of missed calls and the notification window that pops up when you get an incoming call &#8211; it would be possible to replace those standard components with smarter ones which know how to fetch more information about the caller. So, instead of displaying &#8220;0315551234&#8243;, your phone could check the phone listings, your addressbook on Facebook, the list of everyone in your company and other sources to find out who&#8217;s calling. It could even fetch the person&#8217;s profile picture and display it next to their name. This way you could see all sorts of info about someone you haven&#8217;t added to your phone&#8217;s address book yet. Or, if it turns out that the call is coming form a telemarketer, it could simply drop it immediately.</p>
<p><a href="http://www.ribbit.com/everyday/">Ribbit mobile</a> appears to be doing something similar with their <a href="http://www.ribbit.com/everyday/tour/caller_id_2.0.php">caller id 2.0</a>. But somebody really needs to integrate a realtime version of this functionality directly into the phone software. And with Android, that&#8217;s actually possible! It might even be <a href="http://news.digitaltrends.com/news-article/17252/bt-to-buy-ribbit">worth millions</a>&#8230;</p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/fae841a9-ad8c-4149-b52a-55dd89126482/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=fae841a9-ad8c-4149-b52a-55dd89126482" alt="Reblog this post [with Zemanta]"></a></div>
]]></content:encoded>
			<wfw:commentRss>http://lexandera.com/2009/01/caller-id-20/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The new face of mobile</title>
		<link>http://lexandera.com/2009/01/the-changing-face-of-mobile/</link>
		<comments>http://lexandera.com/2009/01/the-changing-face-of-mobile/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 05:31:36 +0000</pubDate>
		<dc:creator>Aleksander Kmetec</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[caffeine]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[Mobile web]]></category>

		<guid isPermaLink="false">http://lexandera.com/?p=132</guid>
		<description><![CDATA[A terrible, sad and cruel thing happened to me this morning. In an attempt to get a quick caffeine fix, I grabbed my last can of energy drink and just as I was about to open it, the ring snapped off with the can remaining firmly closed. Oh, the horror!
At first, I tried replicating what [...]]]></description>
			<content:encoded><![CDATA[<p>A terrible, sad and cruel thing happened to me this morning. In an attempt to get a quick caffeine fix, I grabbed my last can of energy drink and just as I was about to open it, the ring snapped off with the can remaining firmly closed. Oh, the horror!</p>
<p>At first, I tried replicating what the ring does by pushing on the same part of the can with the handle of a spoon. That didn&#8217;t work. Then I did the same thing again, except this time I tried hitting the handle with a meat mallet instead of pushing it down with my finger. That didn&#8217;t work either. Then I considered making a hole in the can with a knife, but decided against it at the last moment, as I really wasn&#8217;t in the mood for some early morning bleeding. It wasn&#8217;t until 5 minutes later, with the can back in the refrigerator, that I thought of the solution.</p>
<p>What do you use, when you&#8217;re dealing with an unopened can? A can opener, of course! It worked beautifully.</p>
<p>In retrospect, it all seems silly. But at that time, the connection between a malfunctioning can of energy drink and a can opener wasn&#8217;t clear to me at all, as I had never thought of opening a drink this way.</p>
<p>And normally, this would be it. I would fill my system with caffeine and go about my daily life without blogging about it. Except, this is not the only time something like this happened to me over the weekend.</p>
<p>While commenting on <a href="http://www.torgo.com/blog/2009/01/2009-predictions.html">Daniel Appelquist&#8217;s predictions for 2009</a> the other day, I described myself as someone who had only recently developed interest in mobile. Which is completely false.</p>
<p>I wrote my first (and only) <a class="zem_slink" title="Wireless Application Protocol" rel="wikipedia" href="http://en.wikipedia.org/wiki/Wireless_Application_Protocol">WAP</a> pages using <a class="zem_slink" title="Wireless Markup Language" rel="wikipedia" href="http://en.wikipedia.org/wiki/Wireless_Markup_Language">WML</a> back in 2000. If you never created anything using WML, you should be glad, as you saved yourself some completely wasted time. That attempt at creating a separate mobile markup language was a long walk down a dead end street to nowhere. Then, at one point, I worked on an SMS based quiz. People would send in a message to start the quiz, to which the system would respond by sending them a question, and if they answered correctly, they would be entered into a drawing for prizes. I even bought a book titled &#8220;Learning wireless Java&#8221;, downloaded the J2ME SDK and created some MIDlets.</p>
<p>But all of this didn&#8217;t come to mind. Because that was the old idea mobile.</p>
<p>Mobile today is not about SMS messages and sandboxed Java applets anymore.  It&#8217;s about native Android and iPhone apps; it&#8217;s about beautiful design; it&#8217;s about mobile web, AJAX, web apps that look and behave like native apps; it&#8217;s about bigger screens, location awareness, voice recognition, augmented reality, and I could go on and on and on.</p>
<p>Today&#8217;s idea of mobile is so different in fact, that I completely failed to make a mental connection between it and my experience with the old idea of mobile.</p>
<p>So, if you are a web person (like me), who spent the last decade thinking that maybe you should get into mobile, don&#8217;t worry, as you haven&#8217;t missed anything. If you are someone who spent the last decade only in mobile, on the other hand, you probably missed a lot.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/pixy.gif?x-id=ab2bbace-dc69-4867-9282-ad70d579cf62" alt="" /><span class="zem-script more-related pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
]]></content:encoded>
			<wfw:commentRss>http://lexandera.com/2009/01/the-changing-face-of-mobile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing Mosembro</title>
		<link>http://lexandera.com/2009/01/introducing-mosembro/</link>
		<comments>http://lexandera.com/2009/01/introducing-mosembro/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 05:44:32 +0000</pubDate>
		<dc:creator>Aleksander Kmetec</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Mosembro]]></category>
		<category><![CDATA[Semantic Web]]></category>
		<category><![CDATA[Microformat]]></category>
		<category><![CDATA[Proof of concept]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[user interface]]></category>
		<category><![CDATA[Web browser]]></category>

		<guid isPermaLink="false">http://lexandera.com/?p=94</guid>
		<description><![CDATA[
Mosembro, short for &#8220;mobile semantic browser&#8221;, is a proof-of-concept web browser for the Android mobile platform, which has integrated support for microformats. It was my entry for the Android developer challenge (but was called SmartBrowser back then), and while it wasn&#8217;t one of the 50 finalists who made it to the second round, it did [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://lexandera.com/mosembro"><img class="alignnone size-full wp-image-95" title="Mosembro logo" src="http://lexandera.com/wp-content/uploads/2009/01/mosembro-logo.png" alt="Mosembro logo" width="260" height="49" /></a></p>
<p>Mosembro, short for &#8220;mobile semantic browser&#8221;, is a proof-of-concept web browser for the <a class="zem_slink" title="Android" rel="homepage" href="http://code.google.com/android/">Android</a> mobile platform, which has integrated support for <a class="zem_slink" title="Microformat" rel="wikipedia" href="http://en.wikipedia.org/wiki/Microformat">microformats</a>. It was my entry for the Android developer challenge (but was called SmartBrowser back then), and while it wasn&#8217;t one of the 50 finalists who made it to the second round, it did finish in the top 25% of all entries, which is pretty good, I suppose.</p>
<p>The goal of this project is very simple: to make a better mobile browser with the help of embedded semantic metadata.</p>
<p>What does it do? It scans any loaded web page for microformats and inserts special links into it, based on any microformats it may have found. These links then enable the user to quickly perform tasks like looking up an address on a map or adding an event to his calendar. While manually performing these tasks is very simple on a computer, it can be pretty tedious on a mobile device without a proper keyboard, mouse, or even without the ability to copy and paste text.</p>
<p>Full feature list, demo videos, downloads and source code are available at the <a href="/mosembro/">Mosembro project page</a>.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Zemified by Zemanta" href="http://reblog.zemanta.com/zemified/5e1d55c4-4b63-435b-bec0-d87eb594abf6/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/reblog_e.png?x-id=5e1d55c4-4b63-435b-bec0-d87eb594abf6" alt="Reblog this post [with Zemanta]" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://lexandera.com/2009/01/introducing-mosembro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Injecting JavaScript into a WebView</title>
		<link>http://lexandera.com/2009/01/injecting-javascript-into-a-webview/</link>
		<comments>http://lexandera.com/2009/01/injecting-javascript-into-a-webview/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 06:05:21 +0000</pubDate>
		<dc:creator>Aleksander Kmetec</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[WebView examples]]></category>
		<category><![CDATA[WebChromeClient]]></category>
		<category><![CDATA[WebView]]></category>
		<category><![CDATA[WebViewClient]]></category>

		<guid isPermaLink="false">http://lexandera.com/?p=64</guid>
		<description><![CDATA[Back in early &#8216;08, while the Androd developer challenge was in full swing, a fairly common question which went without a satisfactory answer was: &#8220;How can I manipulate the contents of a WebView?&#8221;. I now finally have the answer, thanks to a couple of lines of code I stumbled upon while looking at the source [...]]]></description>
			<content:encoded><![CDATA[<p>Back in early &#8216;08, while the <a href="http://code.google.com/android/adc.html">Androd developer challenge</a> was in full swing, a fairly common question which went without a satisfactory answer was: &#8220;How can I manipulate the contents of a WebView?&#8221;. I now finally have the answer, thanks to a couple of lines of code I stumbled upon while looking at the source of <a href="http://www.jsharkey.org/" title="Jeffrey Sharkey" rel="homepage" class="zem_slink">Jeffrey Sharkey</a>&#8217;s <a href="http://www.jsharkey.org/blog/2008/12/15/oilcan-greasemonkey-on-steroids-for-android/">OilCan</a>.</p>
<p>The solution is actually very simple: wait for the original page to finish loading, then inject your own JavaScript code into it by calling webview.loadUrl(&#8220;javascript:your-code-here&#8221;) when your webvew&#8217;s onPageFinished() event is triggered. Loading an URL beginning with &#8220;javascript:&#8221; is the exact same approach used by <a href="http://en.wikipedia.org/wiki/Bookmarklet" title="Bookmarklet" rel="wikipedia" class="zem_slink">bookmarklets</a>.</p>
<p>Here&#8217;s a simple example which loads a page and then sets its text color to red:</p>
<pre name="code" class="java">

final WebView webview = (WebView)findViewById(R.id.browser);
/* JavaScript must be enabled if you want it to work, obviously */
webview.getSettings().setJavaScriptEnabled(true);

/* WebViewClient must be set BEFORE calling loadUrl! */
webview.setWebViewClient(new WebViewClient() {
    @Override
    public void onPageFinished(WebView view, String url)
    {
        webview.loadUrl(&quot;javascript:(function() { &quot; +
                &quot;document.getElementsByTagName(&#039;body&#039;)[0].style.color = &#039;red&#039;; &quot; +
                &quot;})()&quot;);
    }
});

webview.loadUrl(&quot;http://code.google.com/android&quot;);
</pre>
<p>That&#8217;s it.</p>
<p>Please note though that <em>alert()</em> and <em>confirm()</em> JavaScript functions will not work unless you also register a <a href="http://code.google.com/android/reference/android/webkit/WebChromeClient.html">WebChromeClient</a> which implements the required methods.</p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/75a6582e-c459-4c4e-848b-e48a050ab4c9/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=75a6582e-c459-4c4e-848b-e48a050ab4c9" alt="Reblog this post [with Zemanta]"></a></div>
]]></content:encoded>
			<wfw:commentRss>http://lexandera.com/2009/01/injecting-javascript-into-a-webview/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
