Reputation: 51
The Android Dev has some easy code describing how to start the camcorder via Intents.
Now this is good if you just want to start up the camera and wait for the user to press the red "REC" button.
But I want to call the camcorder via Intent and tell it to start recording programmatically.
How to I do that? Do I pass some kind of start() method in the Intent command?
(if it can't be done, please show me a simple code bit that can be set up to record video automatically - I have been searching the web, but all codesnippets regarding this issue don't work)
private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
private Uri fileUri;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// create Intent to take a picture and return control to the calling application
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
// start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
Upvotes: 5
Views: 9775
Reputation: 899
I've found a workaround on a rooted device. First, start the recording the usual way with the Intent (using startActivity()
, not startActivityForResult()
). Second, send the CAMERA key code with 'input keyevent 27'. Its magic! It starts the recording. You probably should press back (code 4) after the end of the recording.
The whole keys sequence is:
CAMERA
: starts the recording (the timer appears on screen). To send a bit later after sending the
intent for safety,DPAD_DOWN
, DPAD_RIGHT
and finally DPAD_CENTER
are
needed to validate the shootage!BACK
to return to your activity.Upvotes: 0
Reputation: 873
For this you should use MediaRecorder
class.
Please have a look at this :
http://developer.android.com/reference/android/media/MediaRecorder.html
Upvotes: 1