tronious commented on issue #665:
URL: 
https://github.com/apache/cordova-plugin-camera/issues/665#issuecomment-877297246


   For ME there is a bug in the camera plugin.  I fixed it for MY situation.  
This may or may not apply to yours.
   
   Scenario:
   
   1)  Using a tablet where the NATIVE CAMERA APP rotates to Landscape when it 
launches.
   2)  My app is running in portrait.  Because of this it needs to saveInstance 
var's and reload them.
   
   What I found and what I fixed:
   
   First look at ProcessResultFromCamera function -> these lines:
   ```
           String sourcePath = (this.allowEdit && this.croppedUri != null) ?
                   this.croppedFilePath :
                   this.imageFilePath;
   ```
   It's using imageUri but saving imageFilePath?  Maybe this is intended maybe 
not.  
   
   I added a quick debug helper class to push out Toasts.  I added Toasts all 
throughout CameraLauncher.java.  
   
   I looked at onSaveInstanceState and noticed a couple things:
   
   1) imageFilePath is not being stored anywhere in onSaveInstanceState so when 
the Activity recreates itself...the imageFilePath that was initially created is 
now null.  This imageFilePath is what's passed into ExifInterface.  If you note 
ABOVE...sourcePath is assigned to imageFilePath.
   
   This would explain why we get the "filename cannot be null" as that specific 
exception is thrown in ExifInterface.java I believe.
   
   ```
                   **_exif.createInFile(sourcePath);_**  <<---- sourcePath is 
null
                   exif.readExifData();
                   rotate = exif.getOrientation();
   
   ```
   
   ```
           if (this.**imageUri** != null) {
               state.putString(IMAGE_URI_KEY, this.**imageFilePath**);
           }
   
   ```
   The Fix??
   
   Update imageUri in onSaveInstanceState.  Add imageFileName to 
onSaveInstanceState.
   
   Add imageFileName to onRestore
   
   here's the actual code to update/add in onSaveInstanceState:
   
   ```
           if (this.imageUri != null) {
               state.putString(IMAGE_URI_KEY, String.valueOf(this.imageUri));
           }
   
           if (this.imageFilePath != null) {
               state.putString(IMAGE_FILE_PATH_KEY, this.imageFilePath);
           }
   
   ```
   
   here's the code to ADD in onRestoreStateForActivityResult:
   
   ```
           if (state.containsKey(IMAGE_FILE_PATH_KEY)) {
               this.imageFilePath = state.getString(IMAGE_FILE_PATH_KEY);
           }
   
   ``` 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to