How to create an Android App using Google’s App Inventor

Today we’re going to take a look at Google’s App Inventor feature that offers programming-novices a nice possibility to enter the fabulous world of Android App programming without deeper knowledge of the API or complex SDK installations. So lets build some stuff .. Prerequisites Java 6 JDK App Inventors Extras Software A Google App Inventor Beta Account – request one here What we are going to build We are building a simple GUI with a Textbox and a button A click on the button starts an event that queries the acceleration sensor for coordinates If the sensor is active and enabled then the coordinates are displayed in the text box ...

August 4, 2010 · 4 min · 749 words · Micha Kops

Sensor Fun: Creating a simple audio recorder/player

Sound recording and playback is really simple using the MediaRecorder and MediaPlayer classes .. see the example below .. Sample App First some layout .. a button to start/stop recording and a button to play the recorded stuff (main.xml): <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/output" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="" /> <Button android:text="@+string/record" android:id="@+id/btRecord" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> <Button android:text="@+string/play" android:id="@+id/btPlay" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> </LinearLayout> Adjusting the externalized strings in the strings.xml <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">Soundrecorder Tutorial</string> <string name="record">Record!</string> <string name="play">Play</string> </resources> ...

May 2, 2010 · 4 min · 766 words · Micha Kops

Sensor Fun: Using the accelerometer on Android

Here is an example on how to use the accelerometer in your Android application. If you want to simulate the acceleration on the emulator I highly recommend the Sensor Simulator on the OpenIntents website. The following example app displays the coordinates received by the sensor. The Acceleration App The activity – AccelerationActivity.java package com.hascode.android; import android.app.Activity; import android.content.Context; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.os.Bundle; import android.widget.TextView; public class AccellerationActivity extends Activity { private TextView result; private SensorManager sensorManager; private Sensor sensor; private float x, y, z; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); sensor = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER).get(0); result = (TextView) findViewById(R.id.result); result.setText("No result yet"); } private void refreshDisplay() { String output = String .format("x is: %f / y is: %f / z is: %f", x, y, z); result.setText(output); } @Override protected void onResume() { super.onResume(); sensorManager.registerListener(accelerationListener, sensor, SensorManager.SENSOR_DELAY_GAME); } @Override protected void onStop() { sensorManager.unregisterListener(accelerationListener); super.onStop(); } private SensorEventListener accelerationListener = new SensorEventListener() { @Override public void onAccuracyChanged(Sensor sensor, int acc) { } @Override public void onSensorChanged(SensorEvent event) { x = event.values[0]; y = event.values[1]; z = event.values[2]; refreshDisplay(); } }; } ...

April 27, 2010 · 2 min · 280 words · Micha Kops