Android: OpenCV: imwrite always returns false and fails to write

后端 未结 4 906
误落风尘
误落风尘 2020-12-09 18:06

This code used to work but on Android 4.2 and OpenCV 2.4.4 it fails, but I don\'t know why. Can anyone shed any light on it for me?

Thanks for any help.

Baz<

4条回答
  •  盖世英雄少女心
    2020-12-09 18:36

    From Android 6+

    Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app...

    And you need to add something like:

      if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) 
      {
            ActivityCompat.requestPermissions(
                    this,
                    new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                    PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
      }
    

    https://developer.android.com/training/permissions/requesting.html

提交回复
热议问题