2016-04-01 4 views
0

ich die „Photofile“ bin immer null in onActivityResult()android: Bildaufnahme von Kamera ein Null es bekommen

auf Aufnahmetaste klicken ich eine Methode dispatchTakePictureIntent() aufrufen Aber wenn ich es null bekommen wieder zurück .

Dieses Problem ist dann auftreten, wenn die Bildauflösung/Größe wie 4012 * 4012 usw. Sehr groß ist und speziell geschehen auf Android-Version 6.0 +

Hier ist mein Code

private void dispatchTakePictureIntent() { 
    Intent takePictureIntent = new Intent(
      android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
    // Ensure that there's a camera activity to handle the intent 
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) { 
     // Create the File where the photo should go 
     File photoFile = null; 
     try { 
      photoFile = Util.createImageFile(); 
      mCurrentPhotoPath = photoFile.getAbsolutePath(); 

      System.out.println("photoFile:" + photoFile.getAbsolutePath()); 
     } catch (IOException ex) { 
      ex.printStackTrace(); 
     } 
     // Continue only if the File was successfully created 
     if (photoFile != null) { 

      System.out.println("@@@@ photoFile: " + photoFile.getAbsolutePath()); 

      /*takePictureIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT,1024); 
      takePictureIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, 
        mCurrentPhotoPath);*/ 

      takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, 
        Uri.fromFile(photoFile)); 

      startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); 

     } 
    } 
} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 

    if (resultCode != RESULT_CANCELED) { 
     if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) { 
      try { 
       //Bundle extras = data.getExtras(); 
       // Log.i(TAG, "extras: " + extras.get("data")); 

       Bitmap mphoto = (Bitmap) data.getExtras().get("data"); 


       System.out.println("***photoFile: " + data.getExtras().get("data")); 

      } catch (Exception e) { 
       // Log.i(TAG, "Exception:" + e.getMessage()); 
      } 

      ShowPopupDialog(mCurrentPhotoPath); 
     } 

    } 
} 

Bitte mir helfen. Danke im Voraus.

+0

posten Sie Ihre Fehler msg –

+0

Fehler ist: Kann Stream dekodieren: java.lang.NullPointerException: Der Versuch, virtuelle Methode aufzurufen ‚char [] java.lang.String. toCharArray() 'für einen Null-Objektverweis – SAndroidD

Antwort

0

Ändern Sie Ihre OnActivityResult Code:

@Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 

     if (resultCode != RESULT_CANCELED) { 
      if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) { 
       try {  

         File fil = new File(Environment.getExternalStorageDirectory().toString()); 
          for (File temp : fil.listFiles()) { 
           if (temp.getName().equals("temp.jpg")) { 
            fil = temp; 
            break; 
           } 
          } 
          Bitmap bitmap = null; 

          BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); 
          Bitmap bmp = BitmapFactory.decodeFile(fil.getAbsolutePath(),bitmapOptions); 
    // 
          Log.e("edit", "new image path is " + fil.getAbsolutePath()); 
       } catch (Exception e) { 
        // Log.i(TAG, "Exception:" + e.getMessage()); 
       } 

       ShowPopupDialog(mCurrentPhotoPath); 
      } 

     } 
Verwandte Themen