Comments (16)
https://drive.google.com/file/d/1TO5VLXkkVM_bUwk9qBR9co2Zk4ml8V3O/view?usp=sharing
from imagepicker.
@ASKabanets You're right. The error is in logcat but, the app works and you could easily use the uri
and pass it to your Image Loader library.
I'll fix that false-positive exception. Thanks!
from imagepicker.
I've changed my GalleryProvider to include your permissions logic, but maintaining all my previous logic. It's working now 👍🏼
from imagepicker.
@ASKabanets What library version you use and which Android API you tests on?
I've used v2.1.8 on API 29 and API 30 and it works.
from imagepicker.
I've just downloaded this sample project, launched it on my OnePlus 5 (Android 10) and tried to get image from gallery or camera. It works great, but when crop is false I got FileNotFoundException.
Then I've created empty project (empty screen just with one button) and added ImagePicker as a dependency. Used the same piece of code as in the sample project - same: when crop is false it throws exception
from imagepicker.
Could you attach your sample project here?
from imagepicker.
It works (when crop is false) if you use uri
to set an image. If you use file path it doesn't work ( ImagePicker.getFilePath(activityResult.data)
when crop is false)
from imagepicker.
@ASKabanets Please use Uri. I'm gonna update the sample app and the Readme.
from imagepicker.
I'm having the same problem with this setup:
ImagePicker
.with(activity)
.maxResultSize(maxWidth, maxHeight, true)
.createIntentFromDialog { intentLauncher.invoke(it) }
I can have a path:
private val imageLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (it.resultCode == Activity.RESULT_OK) {
uploadImage(ImagePicker.getFilePath(it.data)!!)
} else {...}
}
But:
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: java.io.FileNotFoundException: /external_files/Android/data/com.myapp/files/DCIM/Camera/IMG_20210917_143936745.jpg: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:575)
at java.io.FileInputStream.(FileInputStream.java:160)
at okio.Okio__JvmOkioKt.source(JvmOkio.kt:181)
at okio.Okio.source(Unknown Source:1)
at okhttp3.RequestBody$Companion$asRequestBody$1.writeTo(RequestBody.kt:167)
at okhttp3.MultipartBody.writeOrCountBytes(MultipartBody.kt:157)
at okhttp3.MultipartBody.writeTo(MultipartBody.kt:93)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.kt:202)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:920)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:567)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:273)
at libcore.io.ForwardingOs.open(ForwardingOs.java:567)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7728)
at libcore.io.IoBridge.open(IoBridge.java:561)
at java.io.FileInputStream.(FileInputStream.java:160)
at okio.Okio__JvmOkioKt.source(JvmOkio.kt:181)
at okio.Okio.source(Unknown Source:1)
at okhttp3.RequestBody$Companion$asRequestBody$1.writeTo(RequestBody.kt:167)
at okhttp3.MultipartBody.writeOrCountBytes(MultipartBody.kt:157)
at okhttp3.MultipartBody.writeTo(MultipartBody.kt:93)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.kt:202)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:920)
ps: if I switch to my implementation I don't have this problem (but then I have with API versions that you fixed)
Any hint @Drjacky ?
from imagepicker.
This is the path I get using my version: /data/user/0/com.myapp/files/temp.JPEG
🤔
from imagepicker.
@GuilhE Using file path (ImagePicker.getFilePath(activityResult.data)
) when the crop is false doesn't work (I'll fix it later) but, using uri
works perfectly even if the crop is off:
private val launcher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (it.resultCode == Activity.RESULT_OK) {
val uri = it.data?.data!!
// Use the uri to load the image
}
}
from imagepicker.
I've tried that, but I get exactly the same path uppon uri.path
🤔
from imagepicker.
@GuilhE No, not .path
.
This:
private val galleryLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (it.resultCode == Activity.RESULT_OK) {
val uri = it.data?.data!!
mGalleryUri = uri
imgGallery.setLocalImage(uri)
} else parseError(it)
}
from imagepicker.
What's the imgGallery.setLocalImage(uri)
? Ideally I've taken a photo or picked a image from the gallery, save it as a temp file under the app access scope and then retrieve the path (/data/user/0/.../files/temp.JPEG) to upload it as MultipartFormData
. In the end I'll be using a File
, something like this:
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
val image = ImagePicker.getFile(it.data)
if (image?.exists() == true) {
api.uploadPhoto(MultipartBody.Part.createFormData("image", file.name, file.asRequestBody("image/*".toMediaTypeOrNull())))
}
}
Our implementations differ, my version:
GalleryProvider
private fun handleResult(data: Intent?) {
val uri = data?.data
if (uri != null) {
val filePath: String? = FileUriUtils.getRealPath(activity, uri)
if (!filePath.isNullOrEmpty()) {
activity.setImage(File(filePath))
} else {
setError(R.string.error_failed_pick_gallery_image)
}
} else {
setError(R.string.error_failed_pick_gallery_image)
}
}
I believe the differences in FileUriUtils could also be related 🤔 .
from imagepicker.
I'm getting same issue when try to open camera without crop() option.
Can be recreated removing crop option in pickCameraImage() function.
Unable to decode stream: java.io.FileNotFoundException: /external_files/Android/data/com.github.drjacky.imagepicker.sample/files/DCIM/Camera/IMG_20230109_103418027.jpg: open failed: ENOENT (No such file or directory)
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference at com.github.drjacky.imagepicker.provider.CompressionProvider.compressTask(CompressionProvider.kt:72) at com.github.drjacky.imagepicker.provider.CompressionProvider.access$compressTask(CompressionProvider.kt:24) at com.github.drjacky.imagepicker.provider.CompressionProvider$compress$1.invokeSuspend(CompressionProvider.kt:58) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:367) at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30) at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:25) at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:110) at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126) at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56) at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1) at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47) at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1) at com.github.drjacky.imagepicker.provider.CompressionProvider.compress(CompressionProvider.kt:57) at com.github.drjacky.imagepicker.ImagePickerActivity.setImage(ImagePickerActivity.kt:172) at com.github.drjacky.imagepicker.provider.CameraProvider.handleResult(CameraProvider.kt:142) at com.github.drjacky.imagepicker.ImagePickerActivity.cameraLauncher$lambda$1(ImagePickerActivity.kt:59) at com.github.drjacky.imagepicker.ImagePickerActivity.$r8$lambda$TbnVizF4DKsKWrDO5-zrgXMal9g(Unknown Source:0) at com.github.drjacky.imagepicker.ImagePickerActivity$$ExternalSyntheticLambda1.onActivityResult(Unknown Source:4) at androidx.activity.result.ActivityResultRegistry$1.onStateChanged(ActivityResultRegistry.java:149) at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:360) at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:271) at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:313) at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:151) at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:134) at androidx.lifecycle.ReportFragment.dispatch(ReportFragment.java:68) at androidx.lifecycle.ReportFragment$LifecycleCallbacks.onActivityPostStarted(ReportFragment.java:187) at android.app.Activity.dispatchActivityPostStarted(Activity.java:1428) at android.app.Activity.performStart(Activity.java:8254) at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3789) at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221) at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2284) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:210) at android.os.Looper.loop(Looper.java:299) at android.app.ActivityThread.main(ActivityThread.java:8337) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1037)
from imagepicker.
@ClarkXP Please create a new issue with the all necessary information
from imagepicker.
Related Issues (20)
- Black Image returned when cropping large images with higher resolution especially raw camera photos, tried it with a (3456 * 4608) . It doesn't crash though. HOT 6
- Setting up different languages HOT 1
- Android 13 not workinf HOT 4
- WRITE_EXTERNAL_STORAGE is denied between Sdk 29 and 33. HOT 2
- Getting ANR in some devices when picking from Gallery.
- [Crash] CropProvider.convertBitmapToFile - java.io.IOException - No such file or directory HOT 2
- Image provider can not be null
- In AndroidManifast file, Kindly updated the <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />, like android:maxSdkVersion="33" this permission not working in android 10, 11, 12 devices
- Delete image when succesfull
- Screen Orientation Issue: Image Picker HOT 4
- Java Sample HOT 1
- API 29 crop image preview not showing black screen only available after crop HOT 1
- set limit on multiple images
- app crash when launch HOT 1
- Cropped Aspect Ratio! HOT 1
- Manifest merger failed : Attribute activity#com.yalantis.ucrop.UCropActivity@theme value=(@style/CameraTheme) from [paysprint_onboarding_live_1_0_9.aar] AndroidManifest.xml:56:13-47
- Could not scale to target size HOT 1
- Open front camera at first.
- [Crash] When picking a camera image without setting crop() HOT 1
- return error "Image provider can not be null"? Any idea...
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imagepicker.