search

Home  >  Q&A  >  body text

Android 调用相机拍照data 返回null。

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

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

ringa_leeringa_lee2771 days ago796

reply all(5)I'll reply

  • 怪我咯

    怪我咯2017-04-17 17:27:19

    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

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 17:27:19

    Post the error on logcat

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 17:27:19

    Have you added permissions?

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

    reply
    0
  • 黄舟

    黄舟2017-04-17 17:27:19

    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.

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 17:27:19

    Take a look here:

    https://segmentfault.com/q/1010000005951643

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

    reply
    0
  • Cancelreply