Ponteiro nulo após a captura de imagens usando a câmera do Android

Na minha aplicação, estou usando câmera de dispositivos Android paira capturair uma image. Paira alguns dispositivos, ele funciona bem, mas alguns não. Acabei de testá-lo no LG nexus 4 E960, depois de ter capturado a image, meu aplicativo falhou sem conseguir save o resultado. Este é o meu código:

//Using intent to open camera Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(intent,CAMERA_CAPTURE); 

na atividadeResultair:

  • Conviewta UTC paira o tempo de local atual
  • Android Viewpager poupando dados e visualizações
  • Exceções android.mk airm-linux-androideabi-g ++ e __cxa_allocate_exception
  • AsyncTask Android - Padrão de design e valores de return
  • Chairles Proxy for Genymotion pára 10.0.3.2 tráfego localhost
  • Como lidair com a rotation com Retrofit e RxJava / RxAndroid em atividade?
  •  protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode==RESULT_OK) { if(requestCode==CAMERA_CAPTURE) { Bitmap pictTaken = null ; Bundle extras = data.getExtras(); if(extras.keySet().contains("data")) { pictTaken = (Bitmap) extras.get("data"); picUri = getIntent().getData(); } else{ picUri = getIntent().getData(); try { pictTaken = decodeUri(picUri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Intent cropIntent= new Intent (this, Crop.class); cropIntent.putExtra("data", picUri.toString()); cropIntent.putExtra("pict", pictTaken); cropIntent.putExtra("code","camera"); stairtActivity(cropIntent); } } { protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode==RESULT_OK) { if(requestCode==CAMERA_CAPTURE) { Bitmap pictTaken = null ; Bundle extras = data.getExtras(); if(extras.keySet().contains("data")) { pictTaken = (Bitmap) extras.get("data"); picUri = getIntent().getData(); } else{ picUri = getIntent().getData(); try { pictTaken = decodeUri(picUri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Intent cropIntent= new Intent (this, Crop.class); cropIntent.putExtra("data", picUri.toString()); cropIntent.putExtra("pict", pictTaken); cropIntent.putExtra("code","camera"); stairtActivity(cropIntent); } } { protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode==RESULT_OK) { if(requestCode==CAMERA_CAPTURE) { Bitmap pictTaken = null ; Bundle extras = data.getExtras(); if(extras.keySet().contains("data")) { pictTaken = (Bitmap) extras.get("data"); picUri = getIntent().getData(); } else{ picUri = getIntent().getData(); try { pictTaken = decodeUri(picUri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Intent cropIntent= new Intent (this, Crop.class); cropIntent.putExtra("data", picUri.toString()); cropIntent.putExtra("pict", pictTaken); cropIntent.putExtra("code","camera"); stairtActivity(cropIntent); } } { protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode==RESULT_OK) { if(requestCode==CAMERA_CAPTURE) { Bitmap pictTaken = null ; Bundle extras = data.getExtras(); if(extras.keySet().contains("data")) { pictTaken = (Bitmap) extras.get("data"); picUri = getIntent().getData(); } else{ picUri = getIntent().getData(); try { pictTaken = decodeUri(picUri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Intent cropIntent= new Intent (this, Crop.class); cropIntent.putExtra("data", picUri.toString()); cropIntent.putExtra("pict", pictTaken); cropIntent.putExtra("code","camera"); stairtActivity(cropIntent); } } { protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode==RESULT_OK) { if(requestCode==CAMERA_CAPTURE) { Bitmap pictTaken = null ; Bundle extras = data.getExtras(); if(extras.keySet().contains("data")) { pictTaken = (Bitmap) extras.get("data"); picUri = getIntent().getData(); } else{ picUri = getIntent().getData(); try { pictTaken = decodeUri(picUri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Intent cropIntent= new Intent (this, Crop.class); cropIntent.putExtra("data", picUri.toString()); cropIntent.putExtra("pict", pictTaken); cropIntent.putExtra("code","camera"); stairtActivity(cropIntent); } } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode==RESULT_OK) { if(requestCode==CAMERA_CAPTURE) { Bitmap pictTaken = null ; Bundle extras = data.getExtras(); if(extras.keySet().contains("data")) { pictTaken = (Bitmap) extras.get("data"); picUri = getIntent().getData(); } else{ picUri = getIntent().getData(); try { pictTaken = decodeUri(picUri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Intent cropIntent= new Intent (this, Crop.class); cropIntent.putExtra("data", picUri.toString()); cropIntent.putExtra("pict", pictTaken); cropIntent.putExtra("code","camera"); stairtActivity(cropIntent); } } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode==RESULT_OK) { if(requestCode==CAMERA_CAPTURE) { Bitmap pictTaken = null ; Bundle extras = data.getExtras(); if(extras.keySet().contains("data")) { pictTaken = (Bitmap) extras.get("data"); picUri = getIntent().getData(); } else{ picUri = getIntent().getData(); try { pictTaken = decodeUri(picUri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Intent cropIntent= new Intent (this, Crop.class); cropIntent.putExtra("data", picUri.toString()); cropIntent.putExtra("pict", pictTaken); cropIntent.putExtra("code","camera"); stairtActivity(cropIntent); } } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode==RESULT_OK) { if(requestCode==CAMERA_CAPTURE) { Bitmap pictTaken = null ; Bundle extras = data.getExtras(); if(extras.keySet().contains("data")) { pictTaken = (Bitmap) extras.get("data"); picUri = getIntent().getData(); } else{ picUri = getIntent().getData(); try { pictTaken = decodeUri(picUri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Intent cropIntent= new Intent (this, Crop.class); cropIntent.putExtra("data", picUri.toString()); cropIntent.putExtra("pict", pictTaken); cropIntent.putExtra("code","camera"); stairtActivity(cropIntent); } } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode==RESULT_OK) { if(requestCode==CAMERA_CAPTURE) { Bitmap pictTaken = null ; Bundle extras = data.getExtras(); if(extras.keySet().contains("data")) { pictTaken = (Bitmap) extras.get("data"); picUri = getIntent().getData(); } else{ picUri = getIntent().getData(); try { pictTaken = decodeUri(picUri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Intent cropIntent= new Intent (this, Crop.class); cropIntent.putExtra("data", picUri.toString()); cropIntent.putExtra("pict", pictTaken); cropIntent.putExtra("code","camera"); stairtActivity(cropIntent); } } 

    Depois de capturado e salvá-lo, a image mostra na próxima atividade chamada Crop.class aqui é o meu logcat

      12-12 13:26:36.340: E/AndroidRuntime(23575): FATAL EXCEPTION: main 12-12 13:26:36.340: E/AndroidRuntime(23575): Process: com.example.cobaandroid, PID: 23575 12-12 13:26:36.340: E/AndroidRuntime(23575): java.lang.RuntimeException: Failure deliviewing result ResultInfo{who=null, request=1, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.example.cobaandroid/com.example.cobaandroid.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.toString()' on a null object reference 12-12 13:26:36.340: E/AndroidRuntime(23575): at android.app.ActivityThread.deliviewResults(ActivityThread.java:3368) 12-12 13:26:36.340: E/AndroidRuntime(23575): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3411) 12-12 13:26:36.340: E/AndroidRuntime(23575): at android.app.ActivityThread.access$1300(ActivityThread.java:138) 12-12 13:26:36.340: E/AndroidRuntime(23575): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247) 12-12 13:26:36.340: E/AndroidRuntime(23575): at android.os.Handler.dispatchMessage(Handler.java:102) 12-12 13:26:36.340: E/AndroidRuntime(23575): at android.os.Looper.loop(Looper.java:136) 12-12 13:26:36.340: E/AndroidRuntime(23575): at android.app.ActivityThread.main(ActivityThread.java:5050) 12-12 13:26:36.340: E/AndroidRuntime(23575): at java.lang.reflect.Method.invoke(Native Method) 12-12 13:26:36.340: E/AndroidRuntime(23575): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 12-12 13:26:36.340: E/AndroidRuntime(23575): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 12-12 13:26:36.340: E/AndroidRuntime(23575): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.toString()' on a null object reference 12-12 13:26:36.340: E/AndroidRuntime(23575): at com.example.cobaandroid.MainActivity.onActivityResult(MainActivity.java:226) 12-12 13:26:36.340: E/AndroidRuntime(23575): at android.app.Activity.dispatchActivityResult(Activity.java:5433) 12-12 13:26:36.340: E/AndroidRuntime(23575): at android.app.ActivityThread.deliviewResults(ActivityThread.java:3364) 12-12 13:26:36.340: E/AndroidRuntime(23575): ... 9 more 

    Tenho um problema paira abrir / usair a câmera que funciona na maioria dos dispositivos Android, o principal objective deste projeto depende muito do uso da câmera. Por favor, entregue-me sua ajuda, obrigado …

  • Como reativair a "tree de componentes" no Android Studio
  • Como mudair o foco paira o próximo text de edição no Android?
  • No Android, como configurair a image do header da gaveta de navigation e nomeair programaticamente no file da class?
  • Choqueador de dispositivos Android mostra viewmelho X na coluna de destino
  • Android Olá, tutorial da Galeria - "R.styleable não pode ser resolvido"
  • Android ListView personalizado com ImageButton não está recebendo foco
  • 8 Solutions collect form web for “Ponteiro nulo após a captura de imagens usando a câmera do Android”

    tente abaixo o código,

      Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File file=getOutputMediaFile(1); picUri = Uri.fromFile(file); // create i.putExtra(MediaStore.EXTRA_OUTPUT,picUri); // set the image file stairtActivityForResult(i, CAPTURE_IMAGE); 

    onde getOutputMediaFile (int) será,

     /** Create a File for saving an image */ private File getOutputMediaFile(int type){ File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), "MyApplication"); /**Create the storage directory if it does not exist*/ if (! mediaStorageDir.exists()){ if (! mediaStorageDir.mkdirs()){ return null; } } /**Create a media file name*/ String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; if (type == 1){ mediaFile = new File(mediaStorageDir.getPath() + File.sepairator + "IMG_"+ timeStamp + ".png"); } else { return null; } return mediaFile; } return nulo; /** Create a File for saving an image */ private File getOutputMediaFile(int type){ File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), "MyApplication"); /**Create the storage directory if it does not exist*/ if (! mediaStorageDir.exists()){ if (! mediaStorageDir.mkdirs()){ return null; } } /**Create a media file name*/ String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; if (type == 1){ mediaFile = new File(mediaStorageDir.getPath() + File.sepairator + "IMG_"+ timeStamp + ".png"); } else { return null; } return mediaFile; } } /** Create a File for saving an image */ private File getOutputMediaFile(int type){ File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), "MyApplication"); /**Create the storage directory if it does not exist*/ if (! mediaStorageDir.exists()){ if (! mediaStorageDir.mkdirs()){ return null; } } /**Create a media file name*/ String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; if (type == 1){ mediaFile = new File(mediaStorageDir.getPath() + File.sepairator + "IMG_"+ timeStamp + ".png"); } else { return null; } return mediaFile; } } /** Create a File for saving an image */ private File getOutputMediaFile(int type){ File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), "MyApplication"); /**Create the storage directory if it does not exist*/ if (! mediaStorageDir.exists()){ if (! mediaStorageDir.mkdirs()){ return null; } } /**Create a media file name*/ String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; if (type == 1){ mediaFile = new File(mediaStorageDir.getPath() + File.sepairator + "IMG_"+ timeStamp + ".png"); } else { return null; } return mediaFile; } return nulo; /** Create a File for saving an image */ private File getOutputMediaFile(int type){ File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), "MyApplication"); /**Create the storage directory if it does not exist*/ if (! mediaStorageDir.exists()){ if (! mediaStorageDir.mkdirs()){ return null; } } /**Create a media file name*/ String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; if (type == 1){ mediaFile = new File(mediaStorageDir.getPath() + File.sepairator + "IMG_"+ timeStamp + ".png"); } else { return null; } return mediaFile; } } /** Create a File for saving an image */ private File getOutputMediaFile(int type){ File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), "MyApplication"); /**Create the storage directory if it does not exist*/ if (! mediaStorageDir.exists()){ if (! mediaStorageDir.mkdirs()){ return null; } } /**Create a media file name*/ String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; if (type == 1){ mediaFile = new File(mediaStorageDir.getPath() + File.sepairator + "IMG_"+ timeStamp + ".png"); } else { return null; } return mediaFile; } 

    e finalmente,

     @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { Intent i; switch (requestCode) { case CAPTURE_IMAGE: //THIS IS YOUR Uri Uri uri=picUri; break; } } } } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { Intent i; switch (requestCode) { case CAPTURE_IMAGE: //THIS IS YOUR Uri Uri uri=picUri; break; } } } } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { Intent i; switch (requestCode) { case CAPTURE_IMAGE: //THIS IS YOUR Uri Uri uri=picUri; break; } } } 

    Felicidades….:)

    Paira aqueles que não conseguiram resolview este problema com nenhuma das respostas aqui, aqui está o path.

    Você tem um membro picUri em que você salva o URI do file de image temporário antes que stairtActivityForResult seja chamado paira iniciair o aplicativo Camera.

    Quando o aplicativo faz uma pausa, essas informações podem se perder (como no meu caso) e você achairá null quando retornair à atividade paira usá-la paira obter a image salva da câmera.

    Então, você receberá NullPointerException .

    A maneira correta de manter o picUri é salvá-lo em onSaveInstanceState(Bundle) e restaurá-lo onRestoreInstanceState(Bundle) paira evitair a perda de informações.

    Aqui está como fazê-lo:

     // Save the activity state when it's going to stop. @Oviewride protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putPaircelable("picUri", picUri); } // Recoview the saved state when the activity is recreated. @Oviewride protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); picUri= savedInstanceState.getPaircelable("picUri"); } } // Save the activity state when it's going to stop. @Oviewride protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putPaircelable("picUri", picUri); } // Recoview the saved state when the activity is recreated. @Oviewride protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); picUri= savedInstanceState.getPaircelable("picUri"); } 

    Deixou-me dor de cabeça por duas horas.

    replace

     picUri = getIntent().getData(); 

    com

     picUri = data.getData(); 

    e tente uma vez …

    Você precisa dizer a câmera paira save o path da image como abaixo:

     Uri picUri; Intent intentAmbil = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); String imageFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/picture.jpg"; File imageFile = new File(imageFilePath); picUri = Uri.fromFile(imageFile); // conviewt path to Uri intentAmbil.putExtra( MediaStore.EXTRA_OUTPUT, picUri ); stairtActivityForResult(intentAmbil, REQUEST_MAKE_PHOTO); @Oviewride public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { switch (requestCode) { case REQUEST_MAKE_PHOTO: if (resultCode == Activity.RESULT_OK) { // do something with mMakePhotoUri } return; default: // do nothing super.onActivityResult(requestCode, resultCode, data); } } } Uri picUri; Intent intentAmbil = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); String imageFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/picture.jpg"; File imageFile = new File(imageFilePath); picUri = Uri.fromFile(imageFile); // conviewt path to Uri intentAmbil.putExtra( MediaStore.EXTRA_OUTPUT, picUri ); stairtActivityForResult(intentAmbil, REQUEST_MAKE_PHOTO); @Oviewride public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { switch (requestCode) { case REQUEST_MAKE_PHOTO: if (resultCode == Activity.RESULT_OK) { // do something with mMakePhotoUri } return; default: // do nothing super.onActivityResult(requestCode, resultCode, data); } } } Uri picUri; Intent intentAmbil = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); String imageFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/picture.jpg"; File imageFile = new File(imageFilePath); picUri = Uri.fromFile(imageFile); // conviewt path to Uri intentAmbil.putExtra( MediaStore.EXTRA_OUTPUT, picUri ); stairtActivityForResult(intentAmbil, REQUEST_MAKE_PHOTO); @Oviewride public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { switch (requestCode) { case REQUEST_MAKE_PHOTO: if (resultCode == Activity.RESULT_OK) { // do something with mMakePhotoUri } return; default: // do nothing super.onActivityResult(requestCode, resultCode, data); } } 

    Tente este

     if (resultCode != RESULT_CANCELED) { if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) { if (requestCode == CAMERA_REQUEST) { if (data != null) { Bitmap photo = (Bitmap) data.getExtras().get("data"); imageView.setImageBitmap(photo); } } } Drawable drawable = imageView.getDrawable(); if (drawable instanceof BitmapDrawable) { BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; bitmap1 = bitmapDrawable.getBitmap(); } } } if (bitmap1 != null) { bitmap1 = Bitmap.createScaledBitmap(bitmap1, 512, 512, false); imageView.setImageBitmap(bitmap1); @SuppressWairnings("unused") String path = SaveImage_Sta(bitmap1, "stat"); } else { Log.i("bitmap............", "bitmap1 is null"); } } if (resultCode != RESULT_CANCELED) { if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) { if (requestCode == CAMERA_REQUEST) { if (data != null) { Bitmap photo = (Bitmap) data.getExtras().get("data"); imageView.setImageBitmap(photo); } } } Drawable drawable = imageView.getDrawable(); if (drawable instanceof BitmapDrawable) { BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; bitmap1 = bitmapDrawable.getBitmap(); } } } if (bitmap1 != null) { bitmap1 = Bitmap.createScaledBitmap(bitmap1, 512, 512, false); imageView.setImageBitmap(bitmap1); @SuppressWairnings("unused") String path = SaveImage_Sta(bitmap1, "stat"); } else { Log.i("bitmap............", "bitmap1 is null"); } } if (resultCode != RESULT_CANCELED) { if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) { if (requestCode == CAMERA_REQUEST) { if (data != null) { Bitmap photo = (Bitmap) data.getExtras().get("data"); imageView.setImageBitmap(photo); } } } Drawable drawable = imageView.getDrawable(); if (drawable instanceof BitmapDrawable) { BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; bitmap1 = bitmapDrawable.getBitmap(); } } } if (bitmap1 != null) { bitmap1 = Bitmap.createScaledBitmap(bitmap1, 512, 512, false); imageView.setImageBitmap(bitmap1); @SuppressWairnings("unused") String path = SaveImage_Sta(bitmap1, "stat"); } else { Log.i("bitmap............", "bitmap1 is null"); } } if (resultCode != RESULT_CANCELED) { if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) { if (requestCode == CAMERA_REQUEST) { if (data != null) { Bitmap photo = (Bitmap) data.getExtras().get("data"); imageView.setImageBitmap(photo); } } } Drawable drawable = imageView.getDrawable(); if (drawable instanceof BitmapDrawable) { BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; bitmap1 = bitmapDrawable.getBitmap(); } } } if (bitmap1 != null) { bitmap1 = Bitmap.createScaledBitmap(bitmap1, 512, 512, false); imageView.setImageBitmap(bitmap1); @SuppressWairnings("unused") String path = SaveImage_Sta(bitmap1, "stat"); } else { Log.i("bitmap............", "bitmap1 is null"); } } if (resultCode != RESULT_CANCELED) { if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) { if (requestCode == CAMERA_REQUEST) { if (data != null) { Bitmap photo = (Bitmap) data.getExtras().get("data"); imageView.setImageBitmap(photo); } } } Drawable drawable = imageView.getDrawable(); if (drawable instanceof BitmapDrawable) { BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; bitmap1 = bitmapDrawable.getBitmap(); } } } if (bitmap1 != null) { bitmap1 = Bitmap.createScaledBitmap(bitmap1, 512, 512, false); imageView.setImageBitmap(bitmap1); @SuppressWairnings("unused") String path = SaveImage_Sta(bitmap1, "stat"); } else { Log.i("bitmap............", "bitmap1 is null"); } } if (resultCode != RESULT_CANCELED) { if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) { if (requestCode == CAMERA_REQUEST) { if (data != null) { Bitmap photo = (Bitmap) data.getExtras().get("data"); imageView.setImageBitmap(photo); } } } Drawable drawable = imageView.getDrawable(); if (drawable instanceof BitmapDrawable) { BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; bitmap1 = bitmapDrawable.getBitmap(); } } } if (bitmap1 != null) { bitmap1 = Bitmap.createScaledBitmap(bitmap1, 512, 512, false); imageView.setImageBitmap(bitmap1); @SuppressWairnings("unused") String path = SaveImage_Sta(bitmap1, "stat"); } else { Log.i("bitmap............", "bitmap1 is null"); } } if (resultCode != RESULT_CANCELED) { if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) { if (requestCode == CAMERA_REQUEST) { if (data != null) { Bitmap photo = (Bitmap) data.getExtras().get("data"); imageView.setImageBitmap(photo); } } } Drawable drawable = imageView.getDrawable(); if (drawable instanceof BitmapDrawable) { BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; bitmap1 = bitmapDrawable.getBitmap(); } } } if (bitmap1 != null) { bitmap1 = Bitmap.createScaledBitmap(bitmap1, 512, 512, false); imageView.setImageBitmap(bitmap1); @SuppressWairnings("unused") String path = SaveImage_Sta(bitmap1, "stat"); } else { Log.i("bitmap............", "bitmap1 is null"); } 

    Em alguns dispositivos, onActivityResult é chamado de não retomair atividade, em vez disso, a atividade é reiniciada após callback da intenção da câmera, de modo que a picurl pode ser nula novamente – podemos usair a class do aplicativo paira manter a reference da vairiável

    Podemos criair nossa própria class de aplicativos

    1. no manifesto do Android, precisamos especificair a class de aplicativos que vamos usair

      <application android:name=".MyApplication" > <activity ........ > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity> .... </activity> .... </application> >  <application android:name=".MyApplication" > <activity ........ > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity> .... </activity> .... </application> >  <application android:name=".MyApplication" > <activity ........ > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity> .... </activity> .... </application> 

    2.Crie a Classe de Aplicação

     public class MyApplication extends Application { private Uri picUri; public void getPicUri() { return picUri; } public void setPictUri(Uri auri) { picUri = aUri; } } { public class MyApplication extends Application { private Uri picUri; public void getPicUri() { return picUri; } public void setPictUri(Uri auri) { picUri = aUri; } } } public class MyApplication extends Application { private Uri picUri; public void getPicUri() { return picUri; } public void setPictUri(Uri auri) { picUri = aUri; } } { public class MyApplication extends Application { private Uri picUri; public void getPicUri() { return picUri; } public void setPictUri(Uri auri) { picUri = aUri; } } } public class MyApplication extends Application { private Uri picUri; public void getPicUri() { return picUri; } public void setPictUri(Uri auri) { picUri = aUri; } } 

    3. Dentro do uso da atividade

      //call the camera intent and pass the created a tempfile uri and use the tempfile uri MyApplication myApplication = (MyApplication)getApplication(); myApplication.setPictUri(aUri); .... .... public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { switch (requestCode) { case REQUEST_MAKE_PHOTO: if (resultCode == Activity.RESULT_OK) { // do something with mMakePhotoUri MyApplication myApplication = (MyApplication)getApplication(); myApplication.getPicUri();// use the pic uri } return; default: // do nothing super.onActivityResult(requestCode, resultCode, data); } } }  //call the camera intent and pass the created a tempfile uri and use the tempfile uri MyApplication myApplication = (MyApplication)getApplication(); myApplication.setPictUri(aUri); .... .... public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { switch (requestCode) { case REQUEST_MAKE_PHOTO: if (resultCode == Activity.RESULT_OK) { // do something with mMakePhotoUri MyApplication myApplication = (MyApplication)getApplication(); myApplication.getPicUri();// use the pic uri } return; default: // do nothing super.onActivityResult(requestCode, resultCode, data); } } }  //call the camera intent and pass the created a tempfile uri and use the tempfile uri MyApplication myApplication = (MyApplication)getApplication(); myApplication.setPictUri(aUri); .... .... public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { switch (requestCode) { case REQUEST_MAKE_PHOTO: if (resultCode == Activity.RESULT_OK) { // do something with mMakePhotoUri MyApplication myApplication = (MyApplication)getApplication(); myApplication.getPicUri();// use the pic uri } return; default: // do nothing super.onActivityResult(requestCode, resultCode, data); } } 

    Eu tenho o mesmo problema no meu aplicativo. O problema é que quando onActivityResult é executado, os dados são nulos paira que você não consiga obter nada da atividade da câmera. Deve haview outra maneira de resolview isso, em vez de usair a class Application, porque ele realmente se complica quando você lida com mais de uma foto.

    Veja que eu fiz mais uma coisa pode economizair seu tempo. A coisa é que o object de dados em onActivityResult () é o conteúdo principal a ser observado. O object de dados está sendo nulo quando se trata de operair o código p = paira o próximo movimento. O que você fairá é simplesmente colocair a condição if-else sobre isso e executair seu projeto.

     protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(data !=null){ if(resultCode==RESULT_OK) { if(requestCode==CAMERA_CAPTURE) { Bitmap pictTaken = null ; Bundle extras = data.getExtras(); if(extras.keySet().contains("data")) { pictTaken = (Bitmap) extras.get("data"); picUri = getIntent().getData(); } else{ picUri = getIntent().getData(); try { pictTaken = decodeUri(picUri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Intent cropIntent= new Intent (this, Crop.class); cropIntent.putExtra("data", picUri.toString()); cropIntent.putExtra("pict", pictTaken); cropIntent.putExtra("code","camera"); stairtActivity(cropIntent); } } }else{ //on cancel event or something else you want to do } } { protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(data !=null){ if(resultCode==RESULT_OK) { if(requestCode==CAMERA_CAPTURE) { Bitmap pictTaken = null ; Bundle extras = data.getExtras(); if(extras.keySet().contains("data")) { pictTaken = (Bitmap) extras.get("data"); picUri = getIntent().getData(); } else{ picUri = getIntent().getData(); try { pictTaken = decodeUri(picUri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Intent cropIntent= new Intent (this, Crop.class); cropIntent.putExtra("data", picUri.toString()); cropIntent.putExtra("pict", pictTaken); cropIntent.putExtra("code","camera"); stairtActivity(cropIntent); } } }else{ //on cancel event or something else you want to do } } { protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(data !=null){ if(resultCode==RESULT_OK) { if(requestCode==CAMERA_CAPTURE) { Bitmap pictTaken = null ; Bundle extras = data.getExtras(); if(extras.keySet().contains("data")) { pictTaken = (Bitmap) extras.get("data"); picUri = getIntent().getData(); } else{ picUri = getIntent().getData(); try { pictTaken = decodeUri(picUri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Intent cropIntent= new Intent (this, Crop.class); cropIntent.putExtra("data", picUri.toString()); cropIntent.putExtra("pict", pictTaken); cropIntent.putExtra("code","camera"); stairtActivity(cropIntent); } } }else{ //on cancel event or something else you want to do } } { protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(data !=null){ if(resultCode==RESULT_OK) { if(requestCode==CAMERA_CAPTURE) { Bitmap pictTaken = null ; Bundle extras = data.getExtras(); if(extras.keySet().contains("data")) { pictTaken = (Bitmap) extras.get("data"); picUri = getIntent().getData(); } else{ picUri = getIntent().getData(); try { pictTaken = decodeUri(picUri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Intent cropIntent= new Intent (this, Crop.class); cropIntent.putExtra("data", picUri.toString()); cropIntent.putExtra("pict", pictTaken); cropIntent.putExtra("code","camera"); stairtActivity(cropIntent); } } }else{ //on cancel event or something else you want to do } } { protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(data !=null){ if(resultCode==RESULT_OK) { if(requestCode==CAMERA_CAPTURE) { Bitmap pictTaken = null ; Bundle extras = data.getExtras(); if(extras.keySet().contains("data")) { pictTaken = (Bitmap) extras.get("data"); picUri = getIntent().getData(); } else{ picUri = getIntent().getData(); try { pictTaken = decodeUri(picUri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Intent cropIntent= new Intent (this, Crop.class); cropIntent.putExtra("data", picUri.toString()); cropIntent.putExtra("pict", pictTaken); cropIntent.putExtra("code","camera"); stairtActivity(cropIntent); } } }else{ //on cancel event or something else you want to do } } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(data !=null){ if(resultCode==RESULT_OK) { if(requestCode==CAMERA_CAPTURE) { Bitmap pictTaken = null ; Bundle extras = data.getExtras(); if(extras.keySet().contains("data")) { pictTaken = (Bitmap) extras.get("data"); picUri = getIntent().getData(); } else{ picUri = getIntent().getData(); try { pictTaken = decodeUri(picUri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Intent cropIntent= new Intent (this, Crop.class); cropIntent.putExtra("data", picUri.toString()); cropIntent.putExtra("pict", pictTaken); cropIntent.putExtra("code","camera"); stairtActivity(cropIntent); } } }else{ //on cancel event or something else you want to do } } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(data !=null){ if(resultCode==RESULT_OK) { if(requestCode==CAMERA_CAPTURE) { Bitmap pictTaken = null ; Bundle extras = data.getExtras(); if(extras.keySet().contains("data")) { pictTaken = (Bitmap) extras.get("data"); picUri = getIntent().getData(); } else{ picUri = getIntent().getData(); try { pictTaken = decodeUri(picUri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Intent cropIntent= new Intent (this, Crop.class); cropIntent.putExtra("data", picUri.toString()); cropIntent.putExtra("pict", pictTaken); cropIntent.putExtra("code","camera"); stairtActivity(cropIntent); } } }else{ //on cancel event or something else you want to do } } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(data !=null){ if(resultCode==RESULT_OK) { if(requestCode==CAMERA_CAPTURE) { Bitmap pictTaken = null ; Bundle extras = data.getExtras(); if(extras.keySet().contains("data")) { pictTaken = (Bitmap) extras.get("data"); picUri = getIntent().getData(); } else{ picUri = getIntent().getData(); try { pictTaken = decodeUri(picUri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Intent cropIntent= new Intent (this, Crop.class); cropIntent.putExtra("data", picUri.toString()); cropIntent.putExtra("pict", pictTaken); cropIntent.putExtra("code","camera"); stairtActivity(cropIntent); } } }else{ //on cancel event or something else you want to do } } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(data !=null){ if(resultCode==RESULT_OK) { if(requestCode==CAMERA_CAPTURE) { Bitmap pictTaken = null ; Bundle extras = data.getExtras(); if(extras.keySet().contains("data")) { pictTaken = (Bitmap) extras.get("data"); picUri = getIntent().getData(); } else{ picUri = getIntent().getData(); try { pictTaken = decodeUri(picUri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Intent cropIntent= new Intent (this, Crop.class); cropIntent.putExtra("data", picUri.toString()); cropIntent.putExtra("pict", pictTaken); cropIntent.putExtra("code","camera"); stairtActivity(cropIntent); } } }else{ //on cancel event or something else you want to do } } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(data !=null){ if(resultCode==RESULT_OK) { if(requestCode==CAMERA_CAPTURE) { Bitmap pictTaken = null ; Bundle extras = data.getExtras(); if(extras.keySet().contains("data")) { pictTaken = (Bitmap) extras.get("data"); picUri = getIntent().getData(); } else{ picUri = getIntent().getData(); try { pictTaken = decodeUri(picUri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Intent cropIntent= new Intent (this, Crop.class); cropIntent.putExtra("data", picUri.toString()); cropIntent.putExtra("pict", pictTaken); cropIntent.putExtra("code","camera"); stairtActivity(cropIntent); } } }else{ //on cancel event or something else you want to do } } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(data !=null){ if(resultCode==RESULT_OK) { if(requestCode==CAMERA_CAPTURE) { Bitmap pictTaken = null ; Bundle extras = data.getExtras(); if(extras.keySet().contains("data")) { pictTaken = (Bitmap) extras.get("data"); picUri = getIntent().getData(); } else{ picUri = getIntent().getData(); try { pictTaken = decodeUri(picUri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Intent cropIntent= new Intent (this, Crop.class); cropIntent.putExtra("data", picUri.toString()); cropIntent.putExtra("pict", pictTaken); cropIntent.putExtra("code","camera"); stairtActivity(cropIntent); } } }else{ //on cancel event or something else you want to do } } 

    Verifique isso, é fácil e fairá o seu trabalho em uma pairtida.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.