调用相机,拍照但未通过'保存'

时间:2015-04-26 20:53:05

标签: android android-intent camera

下面的代码是一个包含2个按钮和imageview的活动。我打开相机意图,相机打开,我拍照并选择确认按钮'在原生相机应用程序。

点击'确认' /'保存'相机崩溃,我的应用代码在onActivityResult重新输入,我看到RESULT_OK为-1。

有人知道可能是什么问题,或者我是如何追踪这个问题的?我可以在这里提交任何日志,除了相机应用程序界面中的那个,我看不到任何错误。

它是否是存储权限,我认为相机正试图存储点o' save'那就崩溃了。

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在相机失败后重新输入代码的位置......

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

权限

>     <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" />

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

以下是; camera.putExtra("crop", "true");

Android工作室真的很烦人,它不会将应用程序中的代码跟踪到相机应用程序,因此您无法看到它,这是猜测工作。

如果这不起作用我该如何裁剪?