Image uri for Android camera returning Failure ResultInfo result

I made an application with two buttons

  • select image from gallery
  • one to take a new image using the camera

The gallery selection process works fine if I take a picture with the camera, it continues to receive the Failure delivering result ResultInfo . And it looks like the image is not being written to the folder.

Since both return the same, I have one handler to handle the result;

 protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 1) { if (resultCode == RESULT_OK && data.getData() != null){ try { Log.i("YADDA",data.getData().toString()); Uri targetUri = data.getData(); if (targetUri != null) { //Log.i("YADDA",targetUri.toString()); myImage nsi = new myImage(); nsi.ThumbNail = getThumbnail(targetUri); nsi.path = targetUri; nsi.FileName = FileNameBase + "_" + String.valueOf(1 + photos.size()); photos.add(nsi); } } catch (IOException e) { e.printStackTrace(); } DrawImageGallery(); } } 

Button handlers

  nsbu1.setOnClickListener(new Button.OnClickListener() { public void onClick(View v){ Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, 1); } }); nsbu2.setOnClickListener(new Button.OnClickListener() { public void onClick(View v){ Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); // Uri myuri=Uri.fromFile(new File(Environment.getExternalStorageDirectory().getAbsolutePath(), FileNameBase + ".jpg")); Uri myuri=Uri.fromFile(new File("/mnt/sdcard/tmp/" + FileNameBase + ".jpg")); Log.i("YADDA", myuri.toString()); intent.putExtra(MediaStore.EXTRA_OUTPUT, myuri ); startActivityForResult(cameraIntent, 1); } }); 

Things I tried:

  • I double-checked the manifest for write permissions on the SD card
  • wierd thing, the handler must be right, because the image from the gallery works great
  • Some versions of Android have a bug with this camera handler, but I check that my Nexus S is not one of them.
  • googled / debugged for watches and clocks

Logcat output;

  09-01 10:02:59.085: ERROR/AndroidRuntime(1898): FATAL EXCEPTION: main 09-01 10:02:59.085: ERROR/AndroidRuntime(1898): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.android.spot/com.android.spot.newsite}: java.lang.NullPointerException 09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at android.app.ActivityThread.deliverResults(ActivityThread.java:2532) 09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at android.app.ActivityThread.handleSendResult(ActivityThread.java:2574) 09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at android.app.ActivityThread.access$2000(ActivityThread.java:117) 09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:961) 09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at android.os.Handler.dispatchMessage(Handler.java:99) 09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at android.os.Looper.loop(Looper.java:130) 09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at android.app.ActivityThread.main(ActivityThread.java:3683) 09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at java.lang.reflect.Method.invokeNative(Native Method) 09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at java.lang.reflect.Method.invoke(Method.java:507) 09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at dalvik.system.NativeStart.main(Native Method) 09-01 10:02:59.085: ERROR/AndroidRuntime(1898): Caused by: java.lang.NullPointerException 09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at com.android.spot.newsite.onActivityResult(newsite.java:351) 09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at android.app.Activity.dispatchActivityResult(Activity.java:3908) 09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at android.app.ActivityThread.deliverResults(ActivityThread.java:2528) 09-01 10:02:59.085: ERROR/AndroidRuntime(1898): ... 11 more 
+6
source share
2 answers

I just helped a person with the same error on the PhoneGap release list. I believe you are missing permission:

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

from your AndroidManifest.xml file. We need to be able to write the captured image to a .jpg file.

+1
source

EDIT

Initially, I thought that cleaning my application on my phone and reinstalling it fixed the problem. It turns out that this is not so. I found out that there is a problem when the PhoneGap application is uninstalled using the Android Garbage Collection when trying to capture an image from the camera. After hours of searching, the solution I ended up using was using the foreground camera plugin . This plugin creates its own camera inside the application in such a way that you do not need to worry about garbage collection that collects it.

Unfortunately, it is not fully turned on, and most camera settings are not accessible to the user. It also only supports Cordova 2.4.0, which means that I had to abandon 2.7.0. This solution will work for my current application, hopefully next I will write that there will be a better solution. Hope this helps someone!

+1
source

Source: https://habr.com/ru/post/896311/


All Articles