3

In my two to three application I have to used camera activity from application. User taken the picture using camera and set that image on image View.

It works for all devices excepting Droid X. When the user takes the picture from Droid X mobile, application is forced close.

Here is my code for start camera activity:

public void startCameraActivity()
{
    _path = Environment.getExternalStorageDirectory() + "/default.jpg";
    File file = new File( _path );
    Uri outputFileUri = Uri.fromFile( file );

    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    cameraIntent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );
    startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);  
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (requestCode == CAMERA_PIC_REQUEST) {  
        _taken = true;

        bita = BitmapFactory.decodeFile( _path);
        imv.setImageBitmap(bita);
    }  
}        

So what should I do to run camera activity successfully in Droid X? I wasn't able to find what the problem is.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Kutbi
  • 1,154
  • 2
  • 18
  • 32
  • Your problem is outofmemory due to bitmap. Search based on it. – Andro Selva Aug 11 '11 at 05:23
  • do u have any solution regarding this...if u have any solution then please help me.. – Kutbi Aug 11 '11 at 08:50
  • search for bitmap recycle. you will find how to recycle and null bitmap. YOu have to do it accordingly. It is a little complicated to explain. Do some research based on out of memory. – Andro Selva Aug 11 '11 at 09:31
  • A "force close" is always accompanied by an exception stack trace in logcat as to what caused the actual problem. You have differing opinions here about what caused your crash, and posting the exact logcat stack trace you see will allow people to agree on the problem and provide the correct solution. – devunwired Mar 19 '12 at 18:43

1 Answers1

0

The issue here is not a memory issue as Andro has commented on this, and other similar postings.

The issue is simply related to how the Droid X camera intent differs from other devices's.

In my case, I was receiving a NullPointerException when attempting to grab my specified URI that I passed to the camera as using "intent.putExtra( MediaStore.EXTRA_OUTPUT, imageUri );". Some device camera's do not take in this extra properly, and those cases need to be handled separately. (see accepted answer here).

Also in my case, with a Droid X running 2.3.3, the returned intent was null as well. My debugger would detach during the camera intent, indicating that there was something wrong outside of my control. The best I could do is follow the accepted answer here.

So I added a capture for when my desired imageUri is null, and since my returned intent was null, I added logic to grab the most recent photo taken (using this as an example).

if ( imageUri == null ) {

   String[] projection = new String[] { MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.DATA, MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME, MediaStore.Images.ImageColumns.DATE_TAKEN, MediaStore.Images.ImageColumns.MIME_TYPE };
   final Cursor cursor = context.getContentResolver().query( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC" );
   int column_index = cursor.getColumnIndexOrThrow( MediaStore.Images.Media.DATA );
   cursor.moveToFirst();
   fileUri = cursor.getString( column_index );
}

I hope this helps!

Community
  • 1
  • 1
calebisstupid
  • 423
  • 5
  • 13