How to create a camera action common to all Android devices

in my application I want to use a camera to capture an image and send it to a server.

When a user opens a part of the camera of my application, I want to show him the default camera of the device that he uses. Currently, the following are two string codes that I use to capture an image

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
 startActivityForResult(intent, TAKE_RECEIPT);

When I run this code on an HTC device, after capturing the image, it showed a preview of the image using the done and retake buttons . When I click done , it goes to the previous action.

when I use the code in a moto device, after capturing the image, it showed a preview of the image by inserting, returning and canceling . When I click done , it goes to the previous action.

Similarly, it will be different for all devices. Therefore, when I press the done or insert button or any other button with a positive position on all devices that I want to start the boot process.

How to do this, please help me ....

0
source share
3 answers

You can use the code below 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 );
    }
+7
source

, , . , , .

:

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);

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
        }
    }
}
0

Actually, the problem Comes when we run this code on a Google nexus 1 device because it captures images, then when we click the Exclude button, a condition arises ... it's a null pointer in Uri SelectedImage = data.getData ();

0
source

All Articles