Reputation: 4968
in my app i want use the camera for capturing image and send to a server.
When the user opens the Camera part of my app, i want to show him the default camera of the device he is using. At present following is the two line code which i am using to capture image
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_RECEIPT);
When i run this code in a HTC device, after capturing the image it showed a preview of the image with a done and retake button. When i click done it moves to the previous activity.
when i use the code in a moto device, after capturing the image it showed a preview of the image with a insert, retake and cancel. When i click done it moves to the previous activity.
Like this it will be differing for all devices. So when i click the done or insert or any other button positive button of any devices i want to start the uploading process.
How to proceed this please help me....
Upvotes: 0
Views: 1861
Reputation: 15984
You can use below code to solve your problem...
protected void startCameraActivity()
{
// TODO Auto-generated method stub
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );
startActivityForResult( intent, 0 );
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch( resultCode )
{
case 0:
break;
case -1:
onPhotoTaken();
break;
}
}
protected void onPhotoTaken()
{
///write code here what you want to done after capture the image using device camera
}
@Override
protected void onRestoreInstanceState( Bundle savedInstanceState)
{
if( savedInstanceState.getBoolean( add_project1.PHOTO_TAKEN ) )
{
onPhotoTaken();
}
}
@Override
protected void onSaveInstanceState( Bundle outState )
{
outState.putBoolean( add_project1.PHOTO_TAKEN, _taken );
}
Upvotes: 7
Reputation: 432
Actually the problem Arrives when we run this code on the Google nexus 1 device as it captures the images then when we click the done button exception arises..that is null pointer in Uri SelectedImage = data.getData();
Upvotes: 0
Reputation: 13096
I'm not sure if the question is only about how to upload the image after the capture.. but if it is just it, I'll provide you a solution to handle it after you get back from the capture intent to your activity.
You can specify a path to save your image when you start the capture intent:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), "image.jpg");
outputFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, TAKE_RECEIPT);
You can then handle the upload in your onActivityResult:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == TAKE_RECEIPT) {
if (resultCode == Activity.RESULT_OK) {
// user took a picture, upload it
// outputFileUri contains the uri to your file
// you should delete it when the upload completes
} else if (resultCode == Activity.RESULT_CANCELED) {
//user canceled - do nothing
}
}
}
Upvotes: 0