Andreas Nerlich
Beers by the river (@ The Lucky Shag) http://t.co/d55KKf8d (my latest tweet, posted )
Showing only articles tagged as 'android'
our android application (22 Mar 2011) - tagged as android, dev

now that it is no longer expected of me to keep what we've been working on in the last couple of months hush hush, here are some infos for the time being:

  • DriveNow on engadget.com
  • DriveNow on N24.de
  • DriveNow on BMWBlog.com
  • more infos coming soon....

    drive-now.com 
    comments (0)
     
    android run-tests failures not recognized by hudson/jenkins continuous integration (26 Jan 2011) - tagged as dev, android

    you may have noticed, if you have hudson ci build an android test application, that the build succeeds even though you might have failed unit tests. at least this was our case given the following configuration:

    • Android SDK Tools Revision 8
    • Hudson CI with the Android Emulator Plugin
    • Hudson build job for android test application executing ANT target run-tests

    for Android SDK Tools Revision 8, ANT target runt-tests is defined within tools/ant/test_rules.xml. one can adjust this file, but recommended is to override targets from within your android application or your android test application. in our case (the run-tests case), this is done by adding the following (customized targets originally defined in test_rules.xml) to your android test application build.xml just before the <setup/> element.

    <macrodef name="run-tests-helper-custom">
        <attribute name="emma.enabled" default="false" />
        <element name="extra-instrument-args" optional="yes" />
        <sequential>
            <echo>Running tests (custom configuration, project specific)...</echo>
            <exec executable="${adb}" failonerror="true" outputproperty="tests.output">
                <arg line="${adb.device.arg}" />
                <arg value="shell" />
                <arg value="am" />
                   <arg value="instrument" />
                <arg value="-r" />
                <arg value="-w" />
                <arg value="-e" />
                   <arg value="coverage" />
                   <arg value="@{emma.enabled}" />
                <extra-instrument-args />
                <arg value="${manifest.package}/${test.runner}" />
            </exec>
        	<echo message="${tests.output}"/>
    	<fail message="Tests failed!!!">
                <condition>
                    <contains string="${tests.output}" substring="Failure" />
                </condition>
    	</fail>
        </sequential>
    </macrodef>
    
    <!-- Override in order to use custom run-tests-helper-custom macro -->
    <target name="run-tests" depends="-install-tested-project, install"
                description="Runs tests from the package defined in test.package property">
        <run-tests-helper-custom />
    </target>
    

    the adjustment boils down to in having a <fail/> message with an associated condition. this will allow hudson to recognize whether tests have failed or succeeded and mark the build status appropriately.

    comments (0)
     
    reading the body of an incoming sms (android) (29 Nov 2010) - tagged as dev, android

    i simply had to blog this just because it is so simple, it worked the first time and because it is, well pretty cool...at least for a geek like myself ;-)

    public class SmsReceptor extends BroadcastReceiver {
    
      private static final String TAG = SmsReceptor.class.getName();
    
      @Override
      public void onReceive(Context context, Intent intent) {
    
        Bundle intentExtras = intent.getExtras();
    
        if (intentExtras != null) {
          Object[] pdus = (Object[]) intentExtras.get("pdus");
          StringBuffer smsBody = new StringBuffer();
          SmsMessage[] smsMessages = new SmsMessage[pdus.length];
          for (int i = 0; i < smsMessages.length; i++) {
            smsMessages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
            smsBody.append(smsMessages[i].getMessageBody());
          }
          Log.i(TAG, String.format("Received following SMS: '%s'", smsBody));
          Toast.makeText(context, smsBody, Toast.LENGTH_LONG).show();
        }
      }
    
    }
    
    AndroidManifest.xml needs to include the receiver and associated permission:
    
    <receiver android:name=".receiver.SmsReceptor" android:enabled="true">
    	<intent-filter>
    		<action android:name="android.provider.Telephony.SMS_RECEIVED" />
    	</intent-filter>
    </receiver>
    
    
    and
    <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
    
    comments (0)
     
    getting android sources for eclipse (10 Nov 2010) - tagged as dev, android
    so far the eclipse tooling is pretty good for developing android applications. however, by default, the sources for the library dependency android.jar are not available. for one, it can make debugging your app that much trickier.

    thanks to this article, i found a very handy script for easily getting the source code applicable to one's android.jar version. more detailed info here.

    #!/bin/sh 
    
    SRC_DIR=/tmp/android-api
    
    print_syntax() {
       echo "Syntax:\\n\\t$(basename $0) [option]"
       echo "\\nOptions:"
       echo "\\t-l prints available versions"
       echo "\\t-v builds jar file with sources of specified version"
       echo "\\t-c cleans up the sources from the temp directory\\n"
       exit 1
    }
    
    error() {
       echo "Error:" $1
       exit 1
    }
    
    download_sources() {
        if [[ ! -d $SRC_DIR ]]; then
            git clone git://git.source.android.com/platform/frameworks/base $SRC_DIR
        fi
    }
    
    if ! which git > /dev/null ; then
        error "git not installed (or not in the PATH)"
    fi
    
    if ! which jar > /dev/null ; then
        error "jar not installed (or not in the PATH)"
    fi
    
    if [[ "$1" == "-l" ]]; then
        download_sources
        cd $SRC_DIR
        git tag -l
        exit 0;
    fi
    
    if [[ "$1" == "-c" ]]; then
        rm -rf $SRC_DIR
        exit 0;
    fi
    
    if [[ "$1" == "-v"  && ! -z "$2"  ]]; then
        JAR_FILE=$(pwd)/$2-src.jar
        download_sources
        cd $SRC_DIR
        if ! git tag -l | grep $2 ; then
            echo "Version \\"$2\\" not found"
            exit 1;
        fi
        git checkout $2
        touch $JAR_FILE
        find . -depth 2 -name "java" -type d -exec jar uf $JAR_FILE -C {} . \\;
        exit 0
    fi
    
    print_syntax
    
    attaching sources to android.jar in eclipse 
    comments (0)
     

    i built this blogging engine with groovy & grails | source code