Berichten met label Google Android
Introduction to AIR for mobile
Geplaatst door Walter Treur in Flex / AIR, android, mobility, technical op 6 november 2010
A couple of weeks ago, Adobe released a preview of the new Flash Builder and SDK. One of the new features is support for mobile devices using AIR. For now, only Android 2.2 is capable of running mobile AIR applications, but since Steve has changed the rules again, AIR on iOS is nearby, according to Adobe. Time to take a test drive with a tutorial.
Goal
We will create a simple RSS reader. Not a very exciting example, but already shows some nice features of AIR for mobile. I’ll assume you have experience with Flex or AIR, but I think you will manage with some level of programming experience. If not, feel free to leave a reply if you have any questions or take a look at the full source.
Setup

Download and install the preview release of Flash Builder called Burrito It provides a wizard to start an empty mobile application. By default the wizard creates two mxml files containing a MobileApplication and a View component.
The MobileApplication class is inherited from the Application class used for desktop AIR. The mobile version provides, among other things, an action bar and a navigator. Furthermore its firstView property points to the empty view component. The view component is a normal group, but optimized for mobile use as well.
Article list
Open the main view component (called <projectName>Home.mxml). Create a List component in the main view. Provide positioning constraints to let it occupy the whole screen.
<s:List left="0" top="0" bottom="0" right="0" />To retrieve the feed, create an HTTPService pointing to the RSS feed in the declaration section of the view. Add a resultHandler function to parse the feed-data. Parsing xml data is quite simple. You can just navigate to the DOM-tree as it were a normal ActionScript object. Use the data property of the view to store the articles locally. Using this property will provide some benefits with navigation, which will become clear in a bit.
<fx:Script> <![CDATA[ import mx.rpc.events.ResultEvent; protected function service_resultHandler(event:ResultEvent):void { data = event.result.rss.channel.item; } ]]> </fx:Script>
<fx:Declarations> <s:HTTPService id="service" url="http://lsd.luminis.nl/feed/" result="service_resultHandler(event)" /> </fx:Declarations>
Now there are only a couple of things left to do. Invoke the server and provide the list with the articles and instructions to show them.
Both are quite simple. The feeds are retrieved by invoking the send() method of the service. To automatically retrieve them, this method should be invoked when the view is created so we will use the creationComplete handler.
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" title="Home" creationComplete="service.send()">
Finally, bind the data property to the dataProvider of the list and set its labelField attribute to ‘title’.
<s:List dataProvider="{data}" labelField="title" left="0" top="0" bottom="0" right="0" />
Your view will probably look something like this.
<?xml version="1.0" encoding="utf-8"?> <s:View xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" title="Home" creationComplete="service.send()"> <fx:Script> <![CDATA[ import mx.rpc.events.ResultEvent; protected function service_resultHandler(event:ResultEvent):void { data = event.result.rss.channel.item; } ]]> </fx:Script> <fx:Declarations> <s:HTTPService id="service" url="http://lsd.luminis.nl/feed/" result="service_resultHandler(event)" /> </fx:Declarations> <s:List dataProvider="{data}" labelField="title" left="0" top="0" bottom="0" right="0" /> </s:View>
Emulator

Emulate hardware buttons
Now it is time to run a first test. Click the Run button and select ‘On Desktop’ as launch method in run configuration dialog. Also choose a device to simulate and run the application.
When the emulator is launched it shows a list of articles after a couple of seconds. Now you can select Rotate Right from the Device menu to display the landscape view. You will also notice the list is able to scroll up and down when dragging your mouse pointer (Which of course is the emulated equivalent of a one-finger swipe)
Article details
Next is to create a detailed view showing the full content of an article. Close the emulator and return to Flash Builder. In the views package, create a new component and call it DetailView. Bind the title attribute to data.title. Add a label as well and bind the text property to data.description. Don’t forget to specify the positioning constraints.
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" title="{data.title}"> <s:Label text="{data.description}" left="20" right="20" bottom="20" top="20" /> </s:View>
All view components provide a navigator object. We will use this in the change event handler of the article list. This event is fired when the user selects an article from the list. It looks as follows:
import spark.events.IndexChangeEvent; protected function articleList_changeHandler(event:IndexChangeEvent):void { navigator.pushView(DetailView, data[event.newIndex]); }
It simply instructs the navigator to create a new DetailView and push it on top of of the navigation stack. Furthermore the selected item from the article list is passed on to the data property of the DetailView.
Add the change handler and assign it to the change event of the article list:
<s:List dataProvider="{data}" labelField="title" change="articleList_changeHandler(event)" left="0" top="0" bottom="0" right="0" />

Article list inside the emulator
For performance optimization, AIR destroys the view when a user navigates away and recreates it when he returns. Only the contents of the data property is saved and passed into a recreated view of the same type. This is why we used it to store the articles. Otherwise the user has to wait for a reload when he returns to the main view.
When you launch the new version in the emulator, you will notice the application slides to the detail view when an article is selected. Click Back from the Device menu to simulate a click on the hardware back button.
Last but not least: action buttons
One thing our application is missing, is a button to go to the original webpage showing the full article. This button is placed inside the header of our detail view, next to the title.
To achieve this, add the button inside the actionContent of the detail view. Give the button an icon (I used one from the Tango project) and set the click handler to open the url of the article.
<s:actionContent> <s:Button click="{navigateToURL(new URLRequest(data.link))}" icon="@Embed('/assets/internet-web-browser.png')"/> </s:actionContent>
Of course you might want an additional button to return to the article list instead of using the ‘hardware button’. Place this button inside the navigationContent. This will place the back button at the upper left corner. The click event of this button will invoke the navigation.popView() method to remove the current view from the stack and return to the previous one.
<s:navigationContent> <s:Button click="navigator.popView()" icon="@Embed('/assets/go-previous.png')"/> </s:navigationContent>

Action and navigator buttons
If you launch the application you will notice the buttons are nicely aligned at the top of the screen.
What’s next?
The next step will be to package the application to an apk file so you could install it on an Android device. This is done by the Export Release build wizard inside the Project menu of Flash Builder. It includes the ability to sign your application to allow distribution through the Android Market.
Another nice feature which I will not discuss in detail is to add gesture based navigation. Take a look at this article from Adobe to find out more. The approach discussed should be working for mobile AIR applications as well.
Unfortunately the most interesting benefit of using AIR for mobile didn’t become clear with this tutorial. It would be nice to deploy our application on other mobile plastforms as well. However the cross compiler for iOS isn’t available yet and the same goes for AIR on Windows Phone, BlackBerry or Symbian. We will just have to wait when Adobe is ready so we can fully benefit from the “Write once, run anywhere” promise.
PhoneGap, een alternatief voor native mobiele applicaties
Geplaatst door Erik Sanders in Uncategorized, android, mobility op 17 augustus 2010
PhoneGap, een alternatief voor native mobiele applicaties
PhoneGap is een interessante open source alternatief voor het schrijven van native applicaties voor elk (mobiel) platform dat er is. In het kort komt het erop neer dat PhoneGap zorgt dat je een HTML applicatie met javascript. De specifiek API, zoals location, contact, e.d. worden afgeschermd door een standaard API van PhoneGap.
iPhone
Voor de iPhone kan de HTML applicatie gewoon worden aangeboden via de appstore. Dit is dan ook direct de truc waardoor er voldoende rechten zijn om de hardware aan te spreken. Er zijn al vele applicatie geplaatst in de appstore (zie een selectie in www.phonegap.com/apps). Er is tevens een getting started en er zijn extra plugins beschikbaar
Ondersteunde platformen
Naast iPhone wordt zowel Android, Blackberry, Symbian, Palm, N900 en Windows Mobile. Ook Windows Mobile 7 is zodra dit uitkomt eenvoudig te ondersteunen en ze zullen ook geen blokkade opwerpen in het voordeel van silverlight. Interesante gedachte is natuurlijk ook de iets minder mobiele system met Linux, Windows MacOS hebben ook allemaal een browser.
| IPHONE | ANDROID | BLACKBERRY | SYMBIAN | PALM | |
| GEO LOCATION | √ | √ | √ | √ | √ |
| VIBRATION | √ | √ | √ | √ | √ |
| ACCELEROMETER | √ | √ | OS 4.7 | √ | √ |
| SOUND | √ | √ | √ | √ | √ |
| CONTACT SUPPORT | √ | √ | √ | √ | N/A |
Voor meer informatie zie www.phonegap.com
Online video presentatie: Android & Augmented Reality
Geplaatst door Richard van der Laan in mobility op 8 maart 2010
Op 11 november 2009 gaf Arjan Schaaf op de NLJUG een presentatie over Android en Augmented Reality. De video van deze presentatie is inmiddels online beschikbaar. De gehele presentatie van 50 minuten kan je hier (175mb) downloaden. Maar de eerste tien minuten zijn hieronder gelijk op YouTube te bekijken.
English: The whole presentation can be downloaded here (175mb).
Augmented Reality op mobiele devices heeft een enorme vlucht genomen met de introductie van Google Android. Android biedt out-of-the-box de componenten om met augmented reality aan de slag te gaan. In deze sessie staan we stil bij de frameworks die beschikbaar zijn om augemented reality applicaties / content te deployen op Android. Aan de hand van een voorbeeld applicatie gaan we in op de mogelijkheden om zelf een augmented reality applicatie te ontwikkelen met de faciliteiten die door Android worden geboden. Praktische uitdagingen waarmee wij zijn geconfronteerd worden gedeeld en geven inzicht in de mogelijkheden en onmogelijkheden van het Android platform. Opbouw van de presentatie:
- Introductie over augmented reality: location based vs beeldherkenning;
- Wat is te krijgen in de markt? Layar, Wikitude, etc;
- Wat zijn de mogelijkheden om applicaties te ontwikkelen met de beschikbare frameworks;
- Hoe ontwikkel je zelf een augmented reality applicatie op Android?
De slides van de presentatie zijn te vinden op de NLJUG website.
EZdroid launched
Geplaatst door Arjan Schaaf in Uncategorized op 29 mei 2009

The EZdroid initiative is launched: www.ezdroid.com
We are pleased to announce the launch of EZdroid, the world’s first open-source, collaborative platform for the safe deployment of component-based software applications and content across Android, and other Linux-based mobile devices.
EZdroid was founded by two of Europe’s leading companies in the field of OSS technology; the platform consists of Android, Apache Felix and a number of their own enhancements (e.g. software license-, device- and integrated software-management). EZdroid supports the secure deployment of software applications and content (known as Provisioning) to Android phones and in the future, other Linux-based operating systems. It is available to any organization or individual wishing to make software and content available to Android users world-wide. Further information and a demonstration of the platform is now available and downloadable to Android phones at: http://www.ezdroid.com.
EZdroid’s founders: Luminis BV (www.luminis.nl/en) of The Netherlands and Akquinet GmbH (www.akquinet.com/en) of Germany are now inviting partners and collaborators to become part of the EZdroid community – whether these are developers, wishing to show-case their applications, business partners interested in co-development or an OEM relationship, or organizations which are interested in owning and controlling their own application repository/App Store.
The launch of EZdroid is very significant; it is the world’s first platform, built from open source components, which will allow the mass deployment of applications without proprietary licensing issues. The founders intend to supplement the platform with a validation and quality assurance system – to ensure that applications are safe and do not interfere with Android’s normal operations.
OSGi on Google Android using Apache Felix
Geplaatst door Marcel Offermans in Uncategorized op 25 november 2007
UPDATE: A lot has changed in the world of Android & OSGi since writing this post. For the latest developments around this topic, go to: EZdroid community
Since Android 1.5 it is now possible to run Apache Felix without any changes on the phone!
So I was playing around with the Android Google is building … As somebody involved with OSGi for quite some years and a regular contributor to Apache Felix (the OSGi implementation of the Apache Software Foundation) the objective is clear: this platform needs an OSGi framework and Apache Felix is what it is going to be!
The task at hand can be split in two parts namely, figure out how to run the framework itself and extend it to be able to dynamically load bundles.
The former shouldn’t be a big problem because Apache Felix is easily portable and I personally made it run on a quite a number of JVMs. The later qualifies as tricky because for not yet publicly announced reasons Google chooses to not really provide a real JVM but something similar called dalvik.
One of the biggest differences (apart from added API) is that dalvik doesn’t execute Java bytecode directly but needs its own format. Tools are provided to convert from existing Java bytecode to dalvik alas, the conversion is not done at runtime.
Apache Felix on Google Android
The first step is to find the actual runtime on the emulator to save me going through the hassle of rebuilding and redeploying all the time:
> emulator &
> adb shell
# /system/bin/dalvikvm -Xbootclasspath:/system/framework/core.jar -version
DalvikVM version 0.2.0
Copyright (C) 2007 Google, Inc.
Blah blah blah LICENSE blah blah.
Notice the funny last line – I’m not making this up
.
So for a straight forward scenario all we need is the felix.jar with the added dalvik bytecode:
> dx --dex --output=classes.dex bin/felix.jar > aapt add bin/felix.jar classes.dex > adb push bin/felix.jar /root/felix/bin/felix.jar > adb shell # cd root/felix # /system/bin/dalvikvm -Xbootclasspath:/system/framework/core.jar \ -classpath bin/felix.jar org.apache.felix.main.Main
Voila (well, in reality I needed to patch a little to get to this point because there was a bug or two – I’ll commit the fix to trunk).
Dynamically Loading Bundles on Google Android
The next part is the most critical one because we will need to do something that is officially not supported. We need to be able to load bundles i.e., dynamically load code. There is a way to do something in this direction in the official api but nothing close to the power of what we need (and want) for OSGi — hence, I spend sometime finding a loop-hole. It turns out that the normal ClassLoader approach will throw an exception saying that it is not possible to load java byte code. Fortunately, there is a class available that allows to load classes from dex files.
private static final Constructor m_dexFileClassConstructor;
private static final Method m_dexFileClassLoadClass;
static
{
Constructor dexFileClassConstructor = null;
Method dexFileClassLoadClass = null;
try
{
Class dexFileClass = Class.forName("android.dalvik.DexFile");
dexFileClassConstructor = dexFileClass.getConstructor(
new Class[] { java.io.File.class });
dexFileClassLoadClass = dexFileClass.getMethod("loadClass",
new Class[] { String.class, ClassLoader.class });
}
catch (Exception ex)
{
dexFileClassConstructor = null;
dexFileClassLoadClass = null;
}
m_dexFileClassConstructor = dexFileClassConstructor;
m_dexFileClassLoadClass = dexFileClassLoadClass;
}
private Object m_dexFile = null;
public synchronized Class getDexFileClass(String name, ClassLoader loader)
throws Exception
{
if (m_dexFile == null)
{
if ((m_dexFileClassConstructor != null) &&
(m_dexFileClassLoadClass != null))
{
m_dexFile = m_dexFileClassConstructor.newInstance(
new Object[] { m_file });
}
else
{
return null;
}
}
return (Class) m_dexFileClassLoadClass.invoke(m_dexFile,
new Object[] { name.replace('.','/'), loader });
}
This is the equivalent to using com.sun.* classes because the class is not inside the official package namespace but at any rate:
> dx --dex --output=classes.dex \ bundle/org.apache.felix.shell-1.1.0-SNAPSHOT.jar > aapt add bundle/org.apache.felix.shell-1.1.0-SNAPSHOT.jar classes.dex > adb push bundle/org.apache.felix.shell-1.1.0-SNAPSHOT.jar \ /root/felix/bundle/org.apache.felix.shell-1.1.0-SNAPSHOT.jar > dx --dex --output=classes.dex \ bundle/org.apache.felix.shell.tui-1.1.0-SNAPSHOT.jar > aapt add bundle/org.apache.felix.shell.tui-1.1.0-SNAPSHOT.jar \ classes.dex > adb push bundle/org.apache.felix.shell.tui-1.1.0-SNAPSHOT.jar \ /root/felix/bundle/org.apache.felix.shell-1.1.0-SNAPSHOT.jar
We also need a configuration that will make use of the bundles:
> adb push conf/config.properties /root/felix/conf/config.properties > adb shell # cd root/felix # /system/bin/dalvikvm -Xbootclasspath:/system/framework/core.jar \ -classpath bin/felix.jar org.apache.felix.main.Main Welcome to Felix. ================= -> ps START LEVEL 1 ID State Level Name [ 0] [Active ] [ 0] System Bundle (0.0.0) [ 1] [Active ] [ 1] Apache Felix Shell Service (1.1.0.SNAPSHOT) [ 2] [Active ] [ 1] Apache Felix Shell TUI (1.1.0.SNAPSHOT) -> shutdown
Now, for the added fun and as a prove of concept we are going to use the telnet bundle available form the OBR side. It is a little bit more involved because of an inner jar that needs to be processed as well.
> mkdir unpack && cd unpack > jar -xf ../bundle/telnetd.jar > dx --dex --output=classes.dex \ com/softsell/open/osgi/telnetd/dtw.TelnetD.jar > aapt add com/softsell/open/osgi/telnetd/dtw.TelnetD.jar \ classes.dex > rm classes.dex > jar -cmf META-INF/MANIFEST.MF ../bundle/telnetd.jar * > cd .. && rm -rf unpack > dx --dex --output=classes.dex bundle/telnetd.jar > aapt add bundle/telnetd.jar classes.dex > adb push bundle/telnetd.jar /root/felix/bundle/telnetd.jar > adb shell # cd root/felix # /system/bin/dalvikvm -Xbootclasspath:/system/framework/core.jar \ -classpath bin/felix.jar org.apache.felix.main.Main Welcome to Felix. ================= -> ps START LEVEL 1 ID State Level Name [ 0] [Active ] [ 0] System Bundle (0.0.0) [ 1] [Active ] [ 1] Apache Felix Shell Service (1.1.0.SNAPSHOT) [ 2] [Active ] [ 1] Apache Felix Shell TUI (1.1.0.SNAPSHOT) -> install file:bundle/telnetd.jar Bundle ID: 3 -> start 3 [Listening to Port 6623 with a connectivity queue size of 5]
With a little bit of work we are now able to telnet into our framework (we first have to add an redirect of the port):
> telnet localhost 5554 Trying ::1... Connected to localhost. Escape character is '^]'. Android Console: type 'help' for a list of commands redir add tcp:4711:6623 OK quit
Now the framework should be reachable on localhost under port 4711:
> telnet localhost 4711 Welcome to the SoftSell OSGI Telnet Server Available Services: Felix Enter Choice> Felix Welcome to the OSGI command shell ================================= -> ps ID State Level Name [ 0] [Active ] [ 0] System Bundle (0.0.0) [ 1] [Active ] [ 1] Apache Felix Shell Service (1.1.0.SNAPSHOT) [ 2] [Active ] [ 1] Apache Felix Shell TUI (1.1.0.SNAPSHOT) [ 3] [Active ] [ 1] telnetd (1.0.0) -> shutdown connection closed by foreign host.
Success! With a small patch that enables to load classes from a dex file dynamically we have an OSGi framework working on Google’s Android. I will commit the patch for the bugs soon and the binary as well as the real patch are available from our opensource server.
That’s all for today; happy bundle hacking
