Closed AlexPGA closed 8 years ago
Are you reinitializing the ImageChooserManager correctly on onActivityResult?
Take a look here. https://github.com/coomar2841/image-chooser-library/blob/dev/app/src/main/java/com/beanie/imagechooserapp/ImageChooserActivity.java#L154
yes. I reinitializing the imageChooserManager. When I get a photo, the screen shows the image and two button to accept o discard the photo. Here, if the screen is in portrait, the image is saved in the memory but the intent data no recibes nothing and crash the app. If I save in landscape dont happend this problem
Can you post your code in onActivityResult method?
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data);
if (resultCode == FragmentActivity.RESULT_OK) {
switch (requestCode) {
case ChooserType.REQUEST_PICK_PICTURE:
if (imageChooserManager == null) {
reinitializeImageChooser();
}
imageChooserManager.submit(requestCode, data);
break;
case ChooserType.REQUEST_CAPTURE_PICTURE:
if (imageChooserManager == null) {
reinitializeImageChooser();
}
imageChooserManager.submit(requestCode, data);
break;
}
}
}
In the re-initialize method, can you check if the path you are passing is null? It shouldn't be null.
It isnt null. My app is a fragment in an activity and inside the fragment I have a button to pick a photo from camera o from gallery. When selected camera, take photo and save, it crash or close activity parent. Can you send me and example using your library and activity with fragments? thanks for yours replys
thanks for your help. The problem was in the software of camera of my Samsung. Now, all functions correctly. Thanks
@AlexPGA What do you mean the "The problem was in the software of camera of my Samsung"?
I am having the same issue.
@coomar2841 by the way, i try with the sample app in google play, with a Samsung Galaxy S4. With the fragment example, your app crash. :S
Checking that.
Thanks and Regards,Kumar Bibek
http://techdroid.kbeanie.com http://techdroid.kbeanie.comhttp://www.kbeanie.com http://www.kbeanie.com
On Thu, Mar 3, 2016 at 4:54 PM, Javier Vieira notifications@github.com wrote:
@coomar2841 https://github.com/coomar2841 by the way, i try with the sample app in google play, with a Samsung Galaxy S4. With the fragment example, your app crash. :S
— Reply to this email directly or view it on GitHub https://github.com/coomar2841/image-chooser-library/issues/158#issuecomment-191715260 .
I installed a software for the camera from google play and it worked perfectly . My Samsung has installed one room and the camera software was the problem
@coomar2841
I think the camera from the S4 make rotate the fragment/activity, and when this happens the fragment is not really attach to an activity, and the problem comes when onImageChose wants to execute:
03-03 12:40:12.096 3543-7750/com.icodehigh.myapp E/ImageProcessorThread: Attempt to invoke virtual method 'void android.support.v4.app.FragmentActivity.runOnUiThread(java.lang.Runnable)' on a null object reference java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.app.FragmentActivity.runOnUiThread(java.lang.Runnable)' on a null object reference at com.icodehigh.myapp.ui.authorization.AuthorizationActivityFragment.onImageChosen(AuthorizationActivityFragment.java:326) at com.kbeanie.imagechooser.api.ImageChooserManager.onProcessedImage(ImageChooserManager.java:339) at com.kbeanie.imagechooser.threads.ImageProcessorThread.processingDone(ImageProcessorThread.java:187) at com.kbeanie.imagechooser.threads.ImageProcessorThread.process(ImageProcessorThread.java:163) at com.kbeanie.imagechooser.threads.ImageProcessorThread.processImage(ImageProcessorThread.java:154) at com.kbeanie.imagechooser.threads.ImageProcessorThread.run(ImageProcessorThread.java:62) 03-03 12:40:12.161 3543-3543/com.icodehigh.myapp D/Activity: performCreate Call secproduct feature valuefalse 03-03 12:40:12.161 3543-3543/com.icodehigh.myapp D/Activity: performCreate Call debug elastic valuetrue 03-03 12:40:12.281 3543-3553/com.icodehigh.myapp W/art: Suspending all threads took: 23.085ms 03-03 12:40:12.281 3543-3543/com.icodehigh.myapp E/ViewRootImpl: sendUserActionEvent() mView == null 03-03 12:40:12.351 3543-7750/com.icodehigh.myapp E/AndroidRuntime: FATAL EXCEPTION: Thread-2541 Process: com.icodehigh.myapp, PID: 3543 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.app.FragmentActivity.runOnUiThread(java.lang.Runnable)' on a null object reference at com.icodehigh.myapp.ui.authorization.AuthorizationActivityFragment.onError(AuthorizationActivityFragment.java:341) at com.kbeanie.imagechooser.api.ImageChooserManager.onError(ImageChooserManager.java:346) at com.kbeanie.imagechooser.threads.ImageProcessorThread.run(ImageProcessorThread.java:72) 03-03 12:40:12.506 3543-3543/com.icodehigh.myapp E/ViewRootImpl: sendUserActionEvent() mView == null
yes. When camera rotate image, fragment is destroy. My problem solves when use another app to camera
@coomar2841 Hi @AlexPGA is right, if you use the stock camera app from Samsung Galaxy 4, then the library breaks, because that APP makes the screen to rotate and recreate the fragment.
If you user another camera APP with the same phone, the library works
@coomar2841 do you have any idea or work around not to use another camera APP? because is hard to accept this as an answer if the users of the app is the general public :s
You can try delaying the execution till the activity and fragment is re-initialized properly.
@coomar2841 do you mind to provide a little example? I would really apreciate it :dancers: I dont get clear where to delay the execution and how :weary:
I am just doing it like your fragment example:
@Override
public void onImageChosen(final ChosenImage image) {
if (getActivity() == null) {
getView().postDelayed(new Runnable() {
@Override
public void run() {
onImageChosen(image);
}
}, 1000);
} else {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
pbar.setVisibility(View.GONE);
if (image != null) {
textViewFile.setText(image.getFilePathOriginal());
imageViewThumbnail.setImageURI(Uri.parse(new File(image
.getFileThumbnail()).toString()));
imageViewThumbSmall.setImageURI(Uri.parse(new File(image
.getFileThumbnailSmall()).toString()));
}
}
});
}
}
Try this snippet once. But, this is not a good solution. However, if you can confirm that this works, I can think of some workarounds.
No, it seem to break because "getView" returns null
03-03 14:02:23.531 5284-6972/com.icodehigh.myapp E/ImageProcessorThread: Attempt to invoke virtual method 'boolean android.view.View.postDelayed(java.lang.Runnable, long)' on a null object reference java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.view.View.postDelayed(java.lang.Runnable, long)' on a null object reference at com.icodehigh.myapp.ui.authorization.AuthorizationActivityFragment.onImageChosen(AuthorizationActivityFragment.java:326) at com.kbeanie.imagechooser.api.ImageChooserManager.onProcessedImage(ImageChooserManager.java:339) at com.kbeanie.imagechooser.threads.ImageProcessorThread.processingDone(ImageProcessorThread.java:187) at com.kbeanie.imagechooser.threads.ImageProcessorThread.process(ImageProcessorThread.java:163) at com.kbeanie.imagechooser.threads.ImageProcessorThread.processImage(ImageProcessorThread.java:154) at com.kbeanie.imagechooser.threads.ImageProcessorThread.run(ImageProcessorThread.java:62)
this line "AuthorizationActivityFragment.java:326" is "getView().postDelayed(new Runnable() {"
Thanks a lot for your time, I hope we can find a solution :D
Sorry. That was stupid of me. That wouldn't have worked. Give me a few hours. Will get back.
Sent from OnePlusOne. On 03-Mar-2016 6:34 pm, "Javier Vieira" notifications@github.com wrote:
No, it seem to break because "getView" returns null
03-03 14:02:23.531 5284-6972/com.icodehigh.myapp E/ImageProcessorThread: Attempt to invoke virtual method 'boolean android.view.View.postDelayed(java.lang.Runnable, long)' on a null object reference java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.view.View.postDelayed(java.lang.Runnable, long)' on a null object reference at com.icodehigh.myapp.ui.authorization.AuthorizationActivityFragment.onImageChosen(AuthorizationActivityFragment.java:326) at com.kbeanie.imagechooser.api.ImageChooserManager.onProcessedImage(ImageChooserManager.java:339) at com.kbeanie.imagechooser.threads.ImageProcessorThread.processingDone(ImageProcessorThread.java:187) at com.kbeanie.imagechooser.threads.ImageProcessorThread.process(ImageProcessorThread.java:163) at com.kbeanie.imagechooser.threads.ImageProcessorThread.processImage(ImageProcessorThread.java:154) at com.kbeanie.imagechooser.threads.ImageProcessorThread.run(ImageProcessorThread.java:62)
this line "AuthorizationActivityFragment.java:326" is "getView().postDelayed(new Runnable() {"
Thanks a lot for your time, I hope we can find a solution :D
— Reply to this email directly or view it on GitHub https://github.com/coomar2841/image-chooser-library/issues/158#issuecomment-191752808 .
Can you guys give this APK a try and let me know. If it doesn't work, please send me the logs.
https://www.dropbox.com/s/37j486wq4tivt8h/icl-samsung-s4-problem.apk?dl=1
@coomar2841
I have download and try several times, I really believe that the first 2 or 3 times i try all was fine. No crash and the picture taken by the camera was show. Then i close the app and open again and it fails. No crash but the image is not loaded. I reinstall the app and nothing, no crash but neither the image is show.
PD: I filtered the logs with "com.beanie.imagechooserapp"
Ok, At least the crash is not happening. From the logs, I see nothing suspicious. Could you try to determine the exact steps which can reproduce this problem every time. I am quite sure there's a specific scenario where it is failing.
in my code, the problem is that with the camera of samsung in the S4, the method "onImageChosen" "getActivity" is always null. And the fragment gets recreated twice... i think is because the camera app forces the screen rotation in the app. I will try to make a video for you with your app.
I have handled that as well. Check the latest code of ImageChooserFragment.
OK, I have made the video. I see in the video that you can not see very well the rotation that the camera makes, but if you see the notification bar, you can see how in some moments before returning to the app is in landscape. Also in the video you can see how with another camera software it actually works.
Hope this can help.
PD1: When in the video, the camera looks to be in landscape, in real life is in portrait mode. PD2: I had to make a ZIP because the comments does not support mp4
@coomar2841 besides the video I post, so far the only think i can see is that the fragment gets recreated twice and "onImageChosen" gets executed twice.
The line,
imageViewThumbnail.setImageURI(Uri.parse(new File(image.getFileThumbnail()).toString()));
Gets executed, but the image is never show in the thumbnail
Can you check if the file object has a thumbnail path? I just hate Samsung...
Hey mate!
I have found out new info.
The file object has the path, it does and it's fine. In fact if I use picasso to tell to load an image from the internet when the "run" is executed, it wont show the image with picasso. So the thing does not seem to do with the load file, neither the path.
I log out the call of the file object and this is the result:
D/AuthorizationFragment: run() file path: /storage/emulated/0/bichooser/1457354826742_fact_1.jpg
D/AuthorizationFragment: run(): file getAbsolutePath: /storage/emulated/0/bichooser/1457354826742_fact_1.jpg
D/AuthorizationFragment: run(): file getPath: /storage/emulated/0/bichooser/1457354826742_fact_1.jpg
D/AuthorizationFragment: run(): file getCanonicalPath: /storage/emulated/0/bichooser/1457354826742_fact_1.jpg
Now i find interesting that when I log the lifecycle after using the camera APP I think is a bit weird:
1) Open the app and the fragment where I am going to choose the picture. The fragment call the following methods (so far is normal):
AuthorizationFragment: onAttach()
AuthorizationFragment: onCreateView()
AuthorizationFragment: onActivityCreated()
2) I tell the app to take a picture. (so far is normal):
AuthorizationFragment: showImageChooser()
AuthorizationFragment: takePicture()
AuthorizationFragment: onSaveInstanceState()
3) I come back from the camera APP to the fragment, the lifecycle ocurrs twice, I dont see that very normal. Actually after called "onImageChosen" it calls again all the fragment creation lifecycle. how do you see this?
D/AuthorizationFragment: onAttach() called
D/AuthorizationFragment: onCreateView() called
D/AuthorizationFragment: onActivityCreated() called
D/AuthorizationFragment: onActivityResult() called
D/AuthorizationFragment: onSaveInstanceState() called
D/AuthorizationFragment: onImageChosen() called
D/AuthorizationFragment: onAttach() called
D/AuthorizationFragment: onCreateView() called
D/AuthorizationFragment: onActivityCreated() called
D/AuthorizationFragment: run() called
D/AuthorizationFragment: run() file path: /storage/emulated/0/bichooser/1457354826742_fact_1.jpg
D/AuthorizationFragment: run(): file getAbsolutePath: /storage/emulated/0/bichooser/1457354826742_fact_1.jpg
D/AuthorizationFragment: run(): file getPath: /storage/emulated/0/bichooser/1457354826742_fact_1.jpg
D/AuthorizationFragment: run(): file getCanonicalPath: /storage/emulated/0/bichooser/1457354826742_fact_1.jpg
finally I have found something out, if we make the fragment with the setRetainInstance(true)
, then it works, I guess it works because it nevers destroy the fragment
This shouldn't happen actually, and that's what is weird with the Camera App. setRetainInstance would work.. But it's not recommended.
@coomar2841 yes, I know setRetainInstance(true) is not recommended :-1: but so far is the only way i have found to make it work :S
Hi, I'm using the library in my personal application. When I have a problem use . The problem is to take the picture and send it to another activity. If photography is done in portrait, the other activity is not sent . However if it is done in landscape if it works perfectly . How I can do to fix this or force the application to perform in landscape photography ? I use Samsung S4 and its failed
Thanks for your reply