Programming for Mobiles - Practical 3
- Don't forget to request the relevant permissions in your Android manifest.xml file
- Notes on audio recording [below]
- Notes on recovering device orientation [below]
- Android Accessory Development Kit [below]
- Clock Phone App for ADK [google play]
Use the AudioRecord class to record sound.
- You need to choose:
- Sample rate (number of audio samples to record per second)
- Channel configuration (stereo or mono) defined as constants in the AudioFormat class
- Sample encoding (number of bits per sample, etc.) defined as constants in AudioFormat
- Use AudioRecord.getMinBufferSize to determine if your chosen combination is valid. It returns -1 if its not supported by your hardware. You might want to use a bigger buffer than the one returned - it just tells you the smallest possible.
- Now you can create your AudioRecord instance
- Check that it is initialised properly and then call startRecording()
- You can now read from it just like you read from a InputStream
- Don't forget to call stop() and release() when you are done with the device
You should collect a sensor reading from the accelerometers (Sensor.TYPE_ACCELEROMETER) and from the magnetic field sensor (Sensor.TYPE_MAGNETIC_FIELD). Then pass these values to SensorManager.getRotationMatrix - this method combines the two sensor readings to give you a rotation matrix from the device coordinate system to the global coordinate system. You can now pass this rotation matrix to SensorManager.getOrientation which projects the matrix to compute azimuth, pitch and roll.
Android Accessory Development Kit
Full information from the google website is available online. See src/com/google/android/apps/adk2/activity/HomeActivity.java for an example of how to connect to the Clock application (preinstalled on the device) with Bluetooth and the getSensors and handleGetSensors methods to collect information