Android 调用相机拍照data 返回null。
ringa_lee
ringa_lee 2017-04-17 17:25:19
0
5
800

在Fragment中点击按钮启动相机拍照,在Fragment所依附的activity中重写onActivityResult方法,然后去接收,能进入到onActivityResult方法,但是返回的data是null。这个该如何解决?

已经指定了图片存放的路径,如果在onActivityResult中通过指定路径去取,改如何处理?

ringa_lee
ringa_lee

ringa_lee

reply all(5)
刘奇

First of all, what kind of mobile phone does the questioner use?
I have also encountered the first case of returning null.
1 Whether permissions are set
2 Whether the application takes up too much memory, which leads to an error when opening the camera

The second situation is easy to handle. Just get it
But it may happen that the path you set is null

The occurrence of null is basically caused by insufficient memory. It’s best to check if there is a memory leak

大家讲道理

Post the error on logcat

大家讲道理

Have you added permissions?

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

I have encountered this before. It seems that the requestcode returned by the fragment is negative. You can print it out and take a look.

刘奇

Take a look here:

https://segmentfault.com/q/1010000005951643

That’s where I answered.
There is one in the SCDN blog below.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template