Android API Level Detection

Posted: September 24, 2009 in Android, Java, Mobile
Tags: ,

A comment made by had working Xavier(one of the Google engineers) yesterday got me thinking, API Level dtection using ANT,  before today’s regex refactoring:


<var name="var.api.level" value=""/>
 <if>
 <equals arg1="${target}" arg2="android-1"/>
 <then>
 <var name="var.api.level" value="1"/>
 <fail message="this build script version cannto be used with Android 1.0 "/>
 </then>
 <else>
 </else>
 </if>
 <if>
 <equals arg1="${target}" arg2="android-2"/>
 <then>
 <var name="var.api.level" value="2"/>
 <fail message="this build script version cannot be used with android 1.1"/>
 </then>
 <else>
 </else>
 </if>
 <if>
 <equals arg1="${target}" arg2="android-3"/>
 <then>
 <var name="var.api.level" value="3"/>
 </then>
 <else>
 </else>
 </if>
 <if>
 <equals arg1="${target}" arg2="android-4"/>
 <then>
 <var name="var.api.level" value="4"/>
 </then>
 <else>
 </else>
 </if>
 <if>
 <equals arg1="${target}" arg2="android-5"/>
 <then>
 <var name="var.api.level" value="5"/>
 </then>
 <else>
 </else>
 </if>
 <if>
 <equals arg1="${target}" arg2="Google Inc.:Google APIs:3"/>
 <then>
 <var name="var.api.level" value="3"/>
 <propterty name="template.google.maps" value="true"/>
 </then>
 <else>
 </else>
 </if>
 <if>
 <equals arg1="${target}" arg2="Google Inc.:Google APIs:4"/>
 <then>
 <var name="var.api.level" value="4"/>
 <propterty name="template.google.maps" value="true"/>
 </then>
 <else>
 </else>
 </if>
 <if>
 <equals arg1="${target}" arg2="Google Inc.:Google APIs:5"/>
 <then>
 <var name="var.api.level" value="5"/>
 <propterty name="template.google.maps" value="true"/>
 </then>
 <else>
 </else>
 </if>
 <if>
 <equals arg1="${target}" arg2="Motorola Inc.:MB200:3"/>
 <then>
 <var name="var.api.level" value="3"/>
 </then>
 <else>
 </else>
 </if>

Of course it does use the ant-contrib ant task library. Now to refactor using regex patterns. Basically by setting the var.api.level property I can than using flas load the correct code templates at project initialization for example MapView WebView, and etc. I can use the ant-contrib task  propertyregex to select the API level and do some condition testing to only pick the non null value between two regex filters.

Reblog this post [with Zemanta]
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s