igreenwood / SimpleCropView

A simple image cropping library for Android.
MIT License
2.48k stars 465 forks source link

Select image in Android 8.x does not work correctly #139

Open realsmartnose opened 6 years ago

realsmartnose commented 6 years ago

In Android 8+ google change the content provider (it is no Long anymore, it is a string with "raw:"-prefix), your library is throwing an NumberFormatException...

The selected Uri looks like this: content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2FCloudstationPrivate%2FTransfer%2Fimg.jpg

I fixed this by adding this to Util.getFileFromUri():

final String docId = DocumentsContract.getDocumentId(uri);
// Fix for OREO:
if (docId.startsWith("raw:")) {
  filePath = docId.replaceFirst("raw:", "");
} else if (isExternalStorageDocument(uri)) {...