0

My code below is an activity with 2 buttons and a imageview. I fire the camera intent, the camera opens, i take a picture and select 'confirm button' in native camera app.

On clicking 'confirm'/'save' the camera crashes and my app code is re-entered at onActivityResult and i see that RESULT_OK is -1.

Anybody know what might be the issue or indeed how i can track the issue? Any logs i can submit here, i can see no errors except the one in the camera app screen.

Could it be permissions for storage, im presuming the camera is trying to store at the point o 'save' and thats when it crashes.

public class NewUser_Activity extends Activity {


        /** The Constant PICK_IMAGE. */
        private static final int PICK_IMAGE = 0;

        /** The Constant PICK_IMAGE_FROM_GALLERY. */
        private static final int PICK_IMAGE_FROM_GALLERY = 1;

        /** The btn cancel. */
        private Button btnPhotoCamera,btnPhotoGallery,btnCancel;

        /** The img view. */
        private ImageView imgView;

        /** The u. */
        private Uri u;

        /* (non-Javadoc)
         * @see android.app.Activity#onCreate(android.os.Bundle)
         */
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_newuser);

            imgView=(ImageView)findViewById(R.id.imgDisplayImage);
            btnPhotoCamera=(Button)findViewById(R.id.btnPhotoCamera);
            btnPhotoGallery=(Button)findViewById(R.id.btnPhotoGallery);
            btnCancel=(Button)findViewById(R.id.btnCancel);

            btnPhotoCamera.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {

                    Intent camera=new Intent();
                    camera.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
                    camera.putExtra("crop", "true");

                    File f=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

                    u = Uri.fromFile(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"myFile.jpg"));
                    camera.putExtra(MediaStore.EXTRA_OUTPUT, u);
                    startActivityForResult(camera, PICK_IMAGE);
                }
            });

    /* (non-Javadoc)
     * @see android.app.Activity#onActivityResult(int, int, android.content.Intent)
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        if (resultCode==RESULT_OK )
        {
            if(requestCode == PICK_IMAGE) {

                InputStream is=null;
                try {
                    is = this.getContentResolver().openInputStream(u);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
                Bitmap bmp= BitmapFactory.decodeStream(is);
                imgView.setImageBitmap(bmp);
                Log.i("Inside", "PICK_IMAGE");
            }

            if (requestCode == PICK_IMAGE_FROM_GALLERY) {
                Uri selectedImage = data.getData();
                String[] filePathColumn = { MediaStore.Images.Media.DATA };
                Log.d("data",filePathColumn[0]);
                Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
                cursor.moveToFirst();
                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                String picturePath = cursor.getString(columnIndex);
                cursor.close();
                imgView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
                Log.i("Inside", "PICK_IMAGE_FROM_GALLERY");
            }
        }
    }
}

LogCat at point where code is re-entered after camera fails...

04-27 11:30:59.541    3561-3561/com.etsy.android.sample I/art﹕ Late-enabling -Xcheck:jni
04-27 11:30:59.590    3561-3561/com.etsy.android.sample W/ActivityThread﹕ Application com.etsy.android.sample is waiting for the debugger on port 8100...
04-27 11:30:59.590    3561-3561/com.etsy.android.sample I/System.out﹕ Sending WAIT chunk
04-27 11:30:59.659    3561-3572/com.etsy.android.sample I/art﹕ Debugger is active
04-27 11:30:59.791    3561-3561/com.etsy.android.sample I/System.out﹕ Debugger has connected
04-27 11:30:59.791    3561-3561/com.etsy.android.sample I/System.out﹕ waiting for debugger to settle...
04-27 11:31:02.794    3561-3561/com.etsy.android.sample I/System.out﹕ debugger has settled (1464)
04-27 11:31:02.850    3561-3941/com.etsy.android.sample D/OpenGLRenderer﹕ Use EGL_SWAP_BEHAVIOR_PRESERVED: true
04-27 11:31:02.864    3561-3561/com.etsy.android.sample D/Atlas﹕ Validating map...
04-27 11:31:02.893    3561-3941/com.etsy.android.sample I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:379>: xxxx: 01/14/15, xxxx, Ixxxdc
04-27 11:31:02.894    3561-3941/com.etsy.android.sample I/OpenGLRenderer﹕ Initialized EGL, version 1.4
04-27 11:31:02.924    3561-3941/com.etsy.android.sample D/OpenGLRenderer﹕ Enabling debug mode 0
04-27 11:31:07.794    3561-3561/com.etsy.android.sample W/art﹕ Before Android 4.1, method void com.etsy.android.grid.ExtendableListView.rememberSyncState() would have incorrectly overridden the package-private method in android.widget.AdapterView
04-27 11:31:07.794    3561-3561/com.etsy.android.sample W/art﹕ Before Android 4.1, method void com.etsy.android.grid.ExtendableListView.fillGap(boolean) would have incorrectly overridden the package-private method in android.widget.AbsListView
04-27 11:31:07.794    3561-3561/com.etsy.android.sample W/art﹕ Before Android 4.1, method int com.etsy.android.grid.ExtendableListView.getFooterViewsCount() would have incorrectly overridden the package-private method in android.widget.AbsListView
04-27 11:31:07.794    3561-3561/com.etsy.android.sample W/art﹕ Before Android 4.1, method int com.etsy.android.grid.ExtendableListView.getHeaderViewsCount() would have incorrectly overridden the package-private method in android.widget.AbsListView
04-27 11:31:07.794    3561-3561/com.etsy.android.sample W/art﹕ Before Android 4.1, method void com.etsy.android.grid.ExtendableListView.invokeOnItemScrollListener() would have incorrectly overridden the package-private method in android.widget.AbsListView
04-27 11:31:07.794    3561-3561/com.etsy.android.sample W/art﹕ Before Android 4.1, method void com.etsy.android.grid.ExtendableListView.reportScrollStateChange(int) would have incorrectly overridden the package-private method in android.widget.AbsListView
04-27 11:31:07.801    3561-3561/com.etsy.android.sample D/StaggeredGridActivityFragment﹕ onScroll firstVisibleItem:0 visibleItemCount:0 totalItemCount:0
04-27 11:31:07.801    3561-3561/com.etsy.android.sample D/StaggeredGridActivityFragment﹕ onScroll lastInScreen - so load more
04-27 11:31:07.891    3561-3561/com.etsy.android.sample D/TilesAdapter﹕ getPositionRatio:0 ratio:1.4147916247938617
...
04-27 11:31:07.947    3561-3561/com.etsy.android.sample D/TilesAdapter﹕ getView position:2 h:1.4237136790554512
04-27 11:31:07.963    3561-3561/com.etsy.android.sample D/StaggeredGridActivityFragment﹕ onScroll firstVisibleItem:0 visibleItemCount:3 totalItemCount:3
...
04-27 11:31:10.209    3561-3561/com.etsy.android.sample D/StaggeredGridActivityFragment﹕ onScroll firstVisibleItem:0 visibleItemCount:3 totalItemCount:3

Permissions

>     <uses-permission android:name="android.permission.INTERNET" />
>     <uses-permission android:name="android.permission.CAMERA" />
>     <uses-permission android:name="android.permission.RECORD_VIDEO" />
>     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
>     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Fearghal
  • 10,569
  • 17
  • 55
  • 97
  • I'm a little confused by the question, since RESULT_OK is -1, so it seems the camera app is not crashing, but is telling you that it resulted correctly. Is there anything in logcat? – WoogieNoogie Apr 27 '15 at 01:12
  • Nothing in logcat that i can see. The camera does crash-'camera has stopped working'. The camera closes and we return to my code (as i called the camera intent) with result_ok = -1 – Fearghal Apr 27 '15 at 08:43

2 Answers2

0

Check out that post: Summary: Take a picture utilizing Camera Intent and display the photo with correct orientation (works on hopefully all devices)

And find some sample code here: https://github.com/ralfgehrer/AndroidCameraUtil

Community
  • 1
  • 1
Ralf
  • 709
  • 6
  • 14
  • Did you run your code using another device, yet? The camera intent is - to my experience - implemented inconsistently across all android devices of all manufacturers and android versions. So it's hard to pinpoint the issue. Consequently, I shared my solution on github along with a list of tested devices. Feel free to give it a try. – Ralf Apr 27 '15 at 11:34
  • I found the issue just there, thought i updated this thread, maybe updated another by mistake.... - camera.putExtra("crop", "true"); crashes it. whats that about? This is a major drawback with and dev and would have thought it'd be covered. I have to find a proven way to crop now – Fearghal Apr 27 '15 at 11:36
0

It was the following; camera.putExtra("crop", "true");

Android studio is really annoying, it doesn't track my code out of the app to the camera app so you lose visibility to it, this was guess work.

How can i crop if this doesn't work?

Piyush
  • 18,895
  • 5
  • 32
  • 63
Fearghal
  • 10,569
  • 17
  • 55
  • 97