android-crop icon indicating copy to clipboard operation
android-crop copied to clipboard

CropImageActivity may crash with NetworkOnMainThreadException

Open aballano opened this issue 9 years ago • 2 comments

Hi there!

Seems that if the user is somehow trying to crop a not-really-local image (let's say from an app that provides the photo with "content://" schema, maybe Google Drive?) then when calling ContentResolver.openInputStream an exception will be thrown at some point because we're trying to access the network from the main thread.

I digged a bit and found this thread in which basically suggest using some kind of threading mechanism: http://stackoverflow.com/a/27586116/616119

Here's the stacktrace

Caused by: android.os.NetworkOnMainThreadException
    at android.os.Parcel.readException(Parcel.java:1568)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
    at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:148)
    at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:691)
    at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1108)
    at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:948)
    at android.content.ContentResolver.openInputStream(ContentResolver.java:673)
    at com.soundcloud.android.crop.CropImageActivity.calculateBitmapSampleSize(CropImageActivity.java:159)
    at com.soundcloud.android.crop.CropImageActivity.loadInput(CropImageActivity.java:137)
    at com.soundcloud.android.crop.CropImageActivity.onCreate(CropImageActivity.java:76)

aballano avatar Feb 26 '16 13:02 aballano

I have the same issue. I hope this bug can be handled inside the library.

danieltigse avatar Jun 06 '16 15:06 danieltigse

Yes, Even i'm Facing the same Issue.

RAJMONY avatar Jan 09 '18 07:01 RAJMONY