0

So I have this code request images from the camera app.

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {

            try {
                mUltimaFotoFile = createImageFile();

                Uri photoURI = FileProvider.getUriForFile(this,
                        "br.com.nortemobile.sgaconsultor",
                        mUltimaFotoFile);
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                startActivityForResult(takePictureIntent, SHOOT_PIC);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }

    private File createImageFile() throws IOException {
        // Create an image file name
        String imageFileName = "registroFoto";

        File directory = new File(getFilesDir(), "app_imageDir");
        directory.mkdir();

        return File.createTempFile(
                imageFileName,  /* prefix */
                ".jpg",         /* suffix */
                directory
        );
    }

It's working just fine in a Motorola device. But when I try to use the same app in an Samsung device, the camera app always break... I tried some solutions in stackoverflow, but still no look.

Edit:

Here is my stacktrace:

java.lang.SecurityException: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{43965918 20244:com.sec.android.app.camera/u0a10082} (pid=20244, uid=10082) that is not exported from uid 10149
                                                       at android.os.Parcel.readException(Parcel.java:1431)
                                                       at android.os.Parcel.readException(Parcel.java:1385)
                                                       at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:2906)
                                                       at android.app.ActivityThread.acquireProvider(ActivityThread.java:4829)
                                                       at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2560)
                                                       at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1152)
                                                       at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:667)
                                                       at android.content.ContentResolver.openOutputStream(ContentResolver.java:540)
                                                       at android.content.ContentResolver.openOutputStream(ContentResolver.java:516)
                                                       at com.sec.android.app.camera.Camera$LastContentUriCallback.onCompleted(Camera.java:5991)
                                                       at com.sec.android.app.camera.Camera.onLaunchGallery(Camera.java:5873)
                                                       at com.sec.android.app.camera.Camera.onImageStoringCompleted(Camera.java:5217)
                                                       at com.sec.android.app.camera.CameraEngine.imageStoringCompleted(CameraEngine.java:2331)
                                                       at com.sec.android.app.camera.CeStateInitialized.handleMessage(CeStateInitialized.java:47)
                                                       at com.sec.android.app.camera.CameraEngine$StateMessageHandler.handleMessage(CameraEngine.java:256)
                                                       at android.os.Handler.dispatchMessage(Handler.java:99)
                                                       at android.os.Looper.loop(Looper.java:176)
                                                       at android.app.ActivityThread.main(ActivityThread.java:5493)
                                                       at java.lang.reflect.Method.invokeNative(Native Method)
                                                       at java.lang.reflect.Method.invoke(Method.java:525)
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1225)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1041)
                                                       at dalvik.system.NativeStart.main(Native Method)

Any help is appreciated!

Leandro Borges Ferreira
  • 12,422
  • 10
  • 53
  • 73
  • Can you post any stacktrace? – FrankR Jan 17 '17 at 11:49
  • I don't have access to the stacktrace because basically my app never crashes, but the camera app from samsung devices is the one that crashes. So I can't see exactly that went wrong. – Leandro Borges Ferreira Jan 17 '17 at 12:01
  • Normally in logcat you should be able to to change the filter to show all apps, this might help in getting a stacktrace, without one it's really hard to help see what the issue is. – FrankR Jan 17 '17 at 12:06
  • You're right. I found the stacktrace – Leandro Borges Ferreira Jan 17 '17 at 12:21
  • 2
    take a look at this question and see if it's any help: http://stackoverflow.com/questions/33650632/fileprovider-not-working-with-camera – FrankR Jan 17 '17 at 12:34
  • 1
    You forgot to call `addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)` on your `ACTION_IMAGE_CAPTURE` `Intent`, or do the equivalent for older Android versions. As it stands, no camera app will work, as it does not have write access to the content identified by the `Uri`. See [this blog post](https://commonsware.com/blog/2016/08/31/granting-permissions-uri-intent-extra.html) for more. – CommonsWare Jan 17 '17 at 12:35
  • @user7410521 I followed the answer in the question that you posted and it totally worked. CommonsWare I need the solution for older devices, but it works now. Thanks everyone, this was killing me! – Leandro Borges Ferreira Jan 17 '17 at 12:51

1 Answers1

0

I think your issue is that you are trying to save the camera image to internal storage, I don't think this is possible.Can you try saving to a location on the SDCard instead?

FrankR
  • 196
  • 10
  • It is possible to save in the internal storage... I just didn't have the permission. I used the answer in this question: http://stackoverflow.com/questions/33650632/fileprovider-not-working-with-camera and it works now. – Leandro Borges Ferreira Jan 17 '17 at 12:53