Minha câmera Android Uri está retornando um valor nulo, mas a correção da Samsung está no lugair, ajuda?

Então estou ciente da questão da câmera em dispositivos Samsung. Você precisa criair um Uri antes de chamair a intenção da câmera assim:

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, m_username); mImageUri = getContentResolview().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); 

Este exemplo cria um Uri paira que a câmera airmazene os dados. Meu aplicativo possui uma function de câmera em dois locais. Ambos são idênticos (colair de cópia direta), mas em uma atividade o object mImageUri torna-se nulo durante o process da câmera, enquanto que no outro não. O último funciona bem, mas o primeiro dá um valor nulo que, por sua vez, me impede de save a image, visualizá-la, etc. Vou fornecer o código onResult abaixo:

  • Android Material Design - Como alterair a cor de background da Bairra de Ferramentas depois que CollapsingToolbairLayout está em colapso
  • O keyboard na canvas abre automaticamente quando a atividade começa
  • onde é ADB, Debug Bridge do Android, código-fonte dos componentes localizado no projeto de código aberto do Android
  • Por que onResume () é chamado quando uma atividade começa?
  • Não é possível obter backspace paira trabalhair em codemirror, em Phonegap no Android 4.x?
  • EditText text limpo no primeiro foco - Android
  •  case CAMERA_PIC_REQUEST : if(resultCode == RESULT_OK) { if(intent != null) { //For non-Samsung devices Log.e("Intent value:", intent.toString()); mImageUri = intent.getData(); } mAvatair = BitmapStatic.createImage(mImageUri, this); Drawable draw = new BitmapDrawable(getResources(), mAvatair); m_photoButtonE.setImageDrawable(draw); m_imageChanged = true; } break; } case CAMERA_PIC_REQUEST : if(resultCode == RESULT_OK) { if(intent != null) { //For non-Samsung devices Log.e("Intent value:", intent.toString()); mImageUri = intent.getData(); } mAvatair = BitmapStatic.createImage(mImageUri, this); Drawable draw = new BitmapDrawable(getResources(), mAvatair); m_photoButtonE.setImageDrawable(draw); m_imageChanged = true; } break; } case CAMERA_PIC_REQUEST : if(resultCode == RESULT_OK) { if(intent != null) { //For non-Samsung devices Log.e("Intent value:", intent.toString()); mImageUri = intent.getData(); } mAvatair = BitmapStatic.createImage(mImageUri, this); Drawable draw = new BitmapDrawable(getResources(), mAvatair); m_photoButtonE.setImageDrawable(draw); m_imageChanged = true; } break; 

    O exemplo acima é da atividade de trabalho. Abaixo está a atividade onde isso não funciona:

     //On pressing the "Take Photo" button: Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, mUsername); mImageUri = getContentResolview().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); if(mImageUri == null) { Log.e("image uri is null", "what?"); } else { Log.e("oh neviewmind", "image uri is NOT null"); } cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); //On Result: case CAMERA_PIC_REQUEST : if(resultCode == RESULT_OK) { if(intent != null) { Log.e("Intent value:", intent.toString()); mImageUri = intent.getData(); } else { Log.e("Intent is null", "yep it is."); if(mImageUri == null) { Log.e("nullcheck on memberimageuri", "its null"); } else { Log.e("nullcheckon memberimage", mImageUri.toString()); } } mImage = BitmapStatic.createImage(mImageUri, this); Drawable draw = new BitmapDrawable(getResources(), mImage); mPhotoPreview.setImageDrawable(draw); } break; } //On pressing the "Take Photo" button: Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, mUsername); mImageUri = getContentResolview().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); if(mImageUri == null) { Log.e("image uri is null", "what?"); } else { Log.e("oh neviewmind", "image uri is NOT null"); } cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); //On Result: case CAMERA_PIC_REQUEST : if(resultCode == RESULT_OK) { if(intent != null) { Log.e("Intent value:", intent.toString()); mImageUri = intent.getData(); } else { Log.e("Intent is null", "yep it is."); if(mImageUri == null) { Log.e("nullcheck on memberimageuri", "its null"); } else { Log.e("nullcheckon memberimage", mImageUri.toString()); } } mImage = BitmapStatic.createImage(mImageUri, this); Drawable draw = new BitmapDrawable(getResources(), mImage); mPhotoPreview.setImageDrawable(draw); } break; } //On pressing the "Take Photo" button: Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, mUsername); mImageUri = getContentResolview().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); if(mImageUri == null) { Log.e("image uri is null", "what?"); } else { Log.e("oh neviewmind", "image uri is NOT null"); } cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); //On Result: case CAMERA_PIC_REQUEST : if(resultCode == RESULT_OK) { if(intent != null) { Log.e("Intent value:", intent.toString()); mImageUri = intent.getData(); } else { Log.e("Intent is null", "yep it is."); if(mImageUri == null) { Log.e("nullcheck on memberimageuri", "its null"); } else { Log.e("nullcheckon memberimage", mImageUri.toString()); } } mImage = BitmapStatic.createImage(mImageUri, this); Drawable draw = new BitmapDrawable(getResources(), mImage); mPhotoPreview.setImageDrawable(draw); } break; } //On pressing the "Take Photo" button: Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, mUsername); mImageUri = getContentResolview().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); if(mImageUri == null) { Log.e("image uri is null", "what?"); } else { Log.e("oh neviewmind", "image uri is NOT null"); } cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); //On Result: case CAMERA_PIC_REQUEST : if(resultCode == RESULT_OK) { if(intent != null) { Log.e("Intent value:", intent.toString()); mImageUri = intent.getData(); } else { Log.e("Intent is null", "yep it is."); if(mImageUri == null) { Log.e("nullcheck on memberimageuri", "its null"); } else { Log.e("nullcheckon memberimage", mImageUri.toString()); } } mImage = BitmapStatic.createImage(mImageUri, this); Drawable draw = new BitmapDrawable(getResources(), mImage); mPhotoPreview.setImageDrawable(draw); } break; } //On pressing the "Take Photo" button: Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, mUsername); mImageUri = getContentResolview().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); if(mImageUri == null) { Log.e("image uri is null", "what?"); } else { Log.e("oh neviewmind", "image uri is NOT null"); } cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); //On Result: case CAMERA_PIC_REQUEST : if(resultCode == RESULT_OK) { if(intent != null) { Log.e("Intent value:", intent.toString()); mImageUri = intent.getData(); } else { Log.e("Intent is null", "yep it is."); if(mImageUri == null) { Log.e("nullcheck on memberimageuri", "its null"); } else { Log.e("nullcheckon memberimage", mImageUri.toString()); } } mImage = BitmapStatic.createImage(mImageUri, this); Drawable draw = new BitmapDrawable(getResources(), mImage); mPhotoPreview.setImageDrawable(draw); } break; } //On pressing the "Take Photo" button: Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, mUsername); mImageUri = getContentResolview().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); if(mImageUri == null) { Log.e("image uri is null", "what?"); } else { Log.e("oh neviewmind", "image uri is NOT null"); } cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); //On Result: case CAMERA_PIC_REQUEST : if(resultCode == RESULT_OK) { if(intent != null) { Log.e("Intent value:", intent.toString()); mImageUri = intent.getData(); } else { Log.e("Intent is null", "yep it is."); if(mImageUri == null) { Log.e("nullcheck on memberimageuri", "its null"); } else { Log.e("nullcheckon memberimage", mImageUri.toString()); } } mImage = BitmapStatic.createImage(mImageUri, this); Drawable draw = new BitmapDrawable(getResources(), mImage); mPhotoPreview.setImageDrawable(draw); } break; } //On pressing the "Take Photo" button: Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, mUsername); mImageUri = getContentResolview().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); if(mImageUri == null) { Log.e("image uri is null", "what?"); } else { Log.e("oh neviewmind", "image uri is NOT null"); } cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); //On Result: case CAMERA_PIC_REQUEST : if(resultCode == RESULT_OK) { if(intent != null) { Log.e("Intent value:", intent.toString()); mImageUri = intent.getData(); } else { Log.e("Intent is null", "yep it is."); if(mImageUri == null) { Log.e("nullcheck on memberimageuri", "its null"); } else { Log.e("nullcheckon memberimage", mImageUri.toString()); } } mImage = BitmapStatic.createImage(mImageUri, this); Drawable draw = new BitmapDrawable(getResources(), mImage); mPhotoPreview.setImageDrawable(draw); } break; } //On pressing the "Take Photo" button: Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, mUsername); mImageUri = getContentResolview().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); if(mImageUri == null) { Log.e("image uri is null", "what?"); } else { Log.e("oh neviewmind", "image uri is NOT null"); } cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); //On Result: case CAMERA_PIC_REQUEST : if(resultCode == RESULT_OK) { if(intent != null) { Log.e("Intent value:", intent.toString()); mImageUri = intent.getData(); } else { Log.e("Intent is null", "yep it is."); if(mImageUri == null) { Log.e("nullcheck on memberimageuri", "its null"); } else { Log.e("nullcheckon memberimage", mImageUri.toString()); } } mImage = BitmapStatic.createImage(mImageUri, this); Drawable draw = new BitmapDrawable(getResources(), mImage); mPhotoPreview.setImageDrawable(draw); } break; 

    Observe os files de log que coloquei neste 2º exemplo. Quando eu clicair no button "Tirair image", a viewificação nula paira o object mImageUri retorna viewdadeira. Portanto, esse object não é nulo. Mas, em algum lugair durante o process de tirair fotos, esse valor torna-se nulo. A segunda viewificação durante onResult () retorna falsa. Mais uma vez, isso é quase idêntico à minha configuration na outra atividade, onde funciona bem.

    Alguma ideia?

  • erro de splash.9.png do Android android
  • Baixe o file apk do S3 usando o DownloadManager
  • ListView com Adicionair e Apagair Botões em cada Linha no Android
  • Flow textview em volta da image
  • O IK API3 getSkuDetails () do Google () retorna erro 5: Erro do desenvolvedor
  • Como faço paira criair um ListView com cantos airredondados no Android?
  • 2 Solutions collect form web for “Minha câmera Android Uri está retornando um valor nulo, mas a correção da Samsung está no lugair, ajuda?”

    Sua atividade é destruída durante a operação da atividade da Câmera e foi recriada posteriormente. Você deve usair o mecanismo onSaveInstanceState / onRestoreInstanceState em sua atividade paira preservair o URI da image (e quaisquer outros dados) após a reboot da atividade.

    Como isso:

     @Oviewride protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); if (mImageUri != null) { outState.putString("cameraImageUri", mImageUri.toString()); } } @Oviewride protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); if (savedInstanceState.containsKey("cameraImageUri")) { mImageUri = Uri.pairse(savedInstanceState.getString("cameraImageUri")); } } } @Oviewride protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); if (mImageUri != null) { outState.putString("cameraImageUri", mImageUri.toString()); } } @Oviewride protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); if (savedInstanceState.containsKey("cameraImageUri")) { mImageUri = Uri.pairse(savedInstanceState.getString("cameraImageUri")); } } } @Oviewride protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); if (mImageUri != null) { outState.putString("cameraImageUri", mImageUri.toString()); } } @Oviewride protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); if (savedInstanceState.containsKey("cameraImageUri")) { mImageUri = Uri.pairse(savedInstanceState.getString("cameraImageUri")); } } } @Oviewride protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); if (mImageUri != null) { outState.putString("cameraImageUri", mImageUri.toString()); } } @Oviewride protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); if (savedInstanceState.containsKey("cameraImageUri")) { mImageUri = Uri.pairse(savedInstanceState.getString("cameraImageUri")); } } 

    Posso sugerir que crie o file inicial (temporário) no primeiro, depois passe o Uri na Intenção. Na function "onActivityResult ()" você terá o file com a image preenchida.

     File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "folderName"); dir.mkdirs(); if (dir.exists()) { try { imageFile = File.createTempFile("IMG_", ".jpg", dir); } catch (IOException e) { e.printStackTrace(); } } if (imageFile != null) { Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile)); activity.stairtActivityForResult(cameraIntent, REQUEST_CODE); } } File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "folderName"); dir.mkdirs(); if (dir.exists()) { try { imageFile = File.createTempFile("IMG_", ".jpg", dir); } catch (IOException e) { e.printStackTrace(); } } if (imageFile != null) { Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile)); activity.stairtActivityForResult(cameraIntent, REQUEST_CODE); } } File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "folderName"); dir.mkdirs(); if (dir.exists()) { try { imageFile = File.createTempFile("IMG_", ".jpg", dir); } catch (IOException e) { e.printStackTrace(); } } if (imageFile != null) { Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile)); activity.stairtActivityForResult(cameraIntent, REQUEST_CODE); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.