Print Shortlink

Dive into Android development – VII

In the earlier post we discussed the use of intents to perform call up and sms operations. In this post let’s discuss invoking camera and voice recorders using Intents. You’ll have two buttons Camera and Voice record clicking which will perform the appropriate actions.

On clicking the camera button you’ll create an Intent with the ACTION_IMAGE_CAPTURE action present in the MediaStore class as shown below.

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivity(cameraIntent);

The above code will launch the camera application and you can click a picture now.

On clicking the voice record button you’ll create an Intent with the RECORD_SOUND_ACTION action present in the Media class as shown below.

Intent recordIntent=new Intent(android.provider.MediaStore.Audio.Media.RECORD_SOUND_ACTION);
startActivity(recordIntent);

The above code will launch the Voice Recorder application. You can start recording the voice now.

One of the challenges I have faced in working with Camera and Voice recorder is the control coming back to our application. It varies with the application. I have a Samsung Galaxy S device, where the default voice recorder application doesn’t return back to my application after the job. I have to press the back button to get back to my application.

Leave a Reply