Skip to content

Instantly share code, notes, and snippets.

@PGMacDesign
Last active September 16, 2016 17:07
Show Gist options
  • Save PGMacDesign/92cb449b8b4a6ac10a7661f9ff26d9bd to your computer and use it in GitHub Desktop.
Save PGMacDesign/92cb449b8b4a6ac10a7661f9ff26d9bd to your computer and use it in GitHub Desktop.
For fixing the permissions bug
//Get the photo Uri (Java Uri). Make your adjustments to get the actual path (not shown here)
Uri uri = data.getData();
try {
//Make a File
File fromFile = new File(uri.toString());
//Make a Temp File
File tempFile = File.createTempFile("temp_photo", ".jpg", context.getCacheDir());
//One of my Utilities (inspired by Yalantis no less!) Here if you need it:
//https://github.com/PGMacDesign/PGMacUtilities/blob/master/app/src/main/java/com/pgmacdesign/pgmacutilities/utilities/FileUtilities.java
FileUtilities.copyFile(fromFile, tempFile);
//One of my Conversion Utilities. Here if you need it:
//https://github.com/PGMacDesign/PGMacUtilities/blob/master/app/src/main/java/com/pgmacdesign/pgmacutilities/utilities/StringUtilities.java
uri = StringUtilities.convertJavaURIToAndroidUri(tempFile.toURI());
//Call this so that it will delete when the section / app exists
tempFile.deleteOnExit();
} catch (NullPointerException e1){
//Original Uri was null
} catch (IOException e){
//File Creation issue
}
//Then run your cropping on the New Uri here
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment