【问题标题】:Unable to request pictures to samsung device无法向三星设备请求图片
【发布时间】:2017-06-01 10:41:52
【问题描述】:

所以我有这个代码从相机应用程序请求图像。

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
        );
    }

它在摩托罗拉设备上运行良好。但是当我尝试在三星设备中使用相同的应用程序时,相机应用程序总是会中断......我在stackoverflow中尝试了一些解决方案,但仍然没有看。

编辑:

这是我的堆栈跟踪:

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)

感谢任何帮助!

【问题讨论】:

  • 你能发布任何堆栈跟踪吗?
  • 我无法访问堆栈跟踪,因为基本上我的应用程序从不崩溃,但三星设备的相机应用程序是崩溃的。所以我看不出到底出了什么问题。
  • 通常在 logcat 中,您应该能够更改过滤器以显示所有应用程序,这可能有助于获取堆栈跟踪,如果没有堆栈跟踪,很难帮助您了解问题所在。
  • 看看这个问题,看看有没有帮助:stackoverflow.com/questions/33650632/…
  • 您忘记在您的ACTION_IMAGE_CAPTURE Intent 上调用addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION),或者对旧版Android 执行相同操作。就目前而言,没有相机应用程序可以工作,因为它没有对Uri 标识的内容的写入权限。请参阅this blog post 了解更多信息。

标签: java android samsung-mobile android-camera-intent


【解决方案1】:

我认为您的问题是您正在尝试将相机图像保存到内部存储,我认为这是不可能的。您可以尝试保存到 SDCard 上的某个位置吗?

【讨论】:

猜你喜欢
  • 2018-04-25
  • 1970-01-01
  • 2017-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多