Android ACTION_IMAGE_CAPTURE Intent

后端 未结 14 2012
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 02:04

We are trying to use the native camera app to let the user take a new picture. It works just fine if we leave out the EXTRA_OUTPUT extra and returns the small B

14条回答
  •  后悔当初
    2020-11-22 03:06

    I had the same issue and i fixed it with the following:

    The problem is that when you specify a file that only your app has access to (e.g. by calling getFileStreamPath("file");)

    That is why i just made sure that the given file really exists and that EVERYONE has write access to it.

    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    File outFile = getFileStreamPath(Config.IMAGE_FILENAME);
    outFile.createNewFile();
    outFile.setWritable(true, false);
    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,Uri.fromFile(outFile));
    startActivityForResult(intent, 2);
    

    This way, the camera app has write access to the given Uri and the OK button works fine :)

提交回复
热议问题