Android crashing after camera Intent

后端 未结 8 1414
半阙折子戏
半阙折子戏 2020-12-04 15:13

I have an app published and one of the fundamental features is to allow the user to take a picture, and then save that photo in a specific folder on their External Storage.

8条回答
  •  难免孤独
    2020-12-04 15:25

    Hello all i know answer has been given but as this is also one of the easiest solution solution i have ever found

    Here is an example, which is itself bothering about the device!

    AndroidCameraUtils - Download the project and from library project by including it below is the code snippet you can use !

    private void setupCameraIntentHelper() {
    mCameraIntentHelper = new CameraIntentHelper(this, new CameraIntentHelperCallback() {
        @Override
        public void onPhotoUriFound(Date dateCameraIntentStarted, Uri photoUri, int rotateXDegrees) {
            messageView.setText(getString(R.string.activity_camera_intent_photo_uri_found) + photoUri.toString());
    
            Bitmap photo = BitmapHelper.readBitmap(CameraIntentActivity.this, photoUri);
            if (photo != null) {
                photo = BitmapHelper.shrinkBitmap(photo, 300, rotateXDegrees);
                ImageView imageView = (ImageView) findViewById(de.ecotastic.android.camerautil.sample.R.id.activity_camera_intent_image_view);
                imageView.setImageBitmap(photo);
            }
        }
    
        @Override
        public void deletePhotoWithUri(Uri photoUri) {
            BitmapHelper.deleteImageWithUriIfExists(photoUri, CameraIntentActivity.this);
        }
    
        @Override
        public void onSdCardNotMounted() {
            Toast.makeText(getApplicationContext(), getString(R.string.error_sd_card_not_mounted), Toast.LENGTH_LONG).show();
        }
    
        @Override
        public void onCanceled() {
            Toast.makeText(getApplicationContext(), getString(R.string.warning_camera_intent_canceled), Toast.LENGTH_LONG).show();
        }
    
        @Override
        public void onCouldNotTakePhoto() {
            Toast.makeText(getApplicationContext(), getString(R.string.error_could_not_take_photo), Toast.LENGTH_LONG).show();
        }
    
        @Override
        public void onPhotoUriNotFound() {
            messageView.setText(getString(R.string.activity_camera_intent_photo_uri_not_found));
        }
    
        @Override
        public void logException(Exception e) {
            Toast.makeText(getApplicationContext(), getString(R.string.error_sth_went_wrong), Toast.LENGTH_LONG).show();
            Log.d(getClass().getName(), e.getMessage());
        }
    });
    }
    
    @Override
    protected void onSaveInstanceState(Bundle savedInstanceState) {
        super.onSaveInstanceState(savedInstanceState);
        mCameraIntentHelper.onSaveInstanceState(savedInstanceState);
    }
    
    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        mCameraIntentHelper.onRestoreInstanceState(savedInstanceState);
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        mCameraIntentHelper.onActivityResult(requestCode, resultCode, intent);
    }
    }
    

    NOTE:- I tried many examples for camera utils and ofcourse there are another ways to handle it but for beginners and person who are not too much familier with the core concepts would be more comfort with this project. THanks!

提交回复
热议问题