0

I have an activity A. Starting an activity B from A. In activity B, I capture an image with camera present in the device and at the end of that activity come back to Activity A. In this activity have to display the captured image. How to accomplish this task? Running on version 2.3.3...Have had a look here Capture Image from Camera and Display in Activity but the same NullPointerException...Running on LG device.

Community
  • 1
  • 1
Kunal Shah
  • 489
  • 1
  • 4
  • 21

1 Answers1

0

You can pass the URL of the captured image from Activity B to Activity A using intent.putExtras methos.

Refer Passing string array between android activities

For Capturing image refer below code

public class Camera extends Activity 
{
     private static final int CAMERA_REQUEST = 1888;
     private String selectedImagePath;
     WebView webview;
     String fileName = "capturedImage.jpg";
     private static Uri mCapturedImageURI; 

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
            webview=(WebView)findViewById(R.id.webView1);
    }

    public void TakePhoto()
    {   
            ContentValues values = new ContentValues();  
            values.put(MediaStore.Images.Media.TITLE, fileName);  
            mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
            Intent cameraIntent = new Intent(ACTION_IMAGE_CAPTURE);
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI); 
            startActivityForResult(cameraIntent, CAMERA_REQUEST);
    }       
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        if (resultCode == RESULT_OK)
            {
              if (requestCode == CAMERA_REQUEST) 
              { 
                selectedImagePath = getPath(mCapturedImageURI);
                 //Save the path to pass between activities
              }
            }
    }

    public String getPath(Uri uri) {
        String[] projection = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(uri, projection, null, null, null);
        int column_index = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    }

}
Community
  • 1
  • 1
Ponmalar
  • 6,871
  • 10
  • 50
  • 80