0

I use the Plyer library for filechooser to open the Android file chooser. I request runtime permissions and those seem to be granted when I print the check_permissions.

Filechooser Code:

  def file_pop(self):
    from android.permissions import request_permissions, Permission,check_permission
    request_permissions([Permission.WRITE_EXTERNAL_STORAGE])
    if check_permission(Permission.WRITE_EXTERNAL_STORAGE):
        print("Permissions granted")
    filechooser.open_file(on_selection=self.handle_selection)

On selecting a file I need to copy the file to my application directory to store the same. I do this using shutil library.

shutil.copy(selection[0], self.filename_pfix + "title." + extension)

On doing this while it is working fine in my PC. In my android phone it gives me the following error:

PermissionError: [Errno 13] Permission denied: '/storage/emulated/0/DCIM/Screenshots/20200420_003038.jpg'

I have given Storage permissions to the app. I have asked for runtime permissions as you can see in the code, and I see check_permissions true (again present in the above code).

Can you please help me resolving this issue? The logcat error log around the problem is pasted below:

'''

09-17 13:49:30.820 28441 28698 I python  : Android kivy bootstrap done. __name__ is __main__
09-17 13:49:30.820 28441 28698 I python  : AND: Ran string
09-17 13:49:30.820 28441 28698 I python  : Run user program, change dir and execute entrypoint
09-17 13:49:30.981 28441 28698 I python  : [WARNING] [Config      ] Older configuration version detected (0 instead of 21)
09-17 13:49:30.981 28441 28698 I python  : [WARNING] [Config      ] Upgrading configuration in progress.
09-17 13:49:30.987 28441 28698 I python  : [INFO   ] [Logger      ] Record log in /data/user/0/in.wondersky.lr/files/app/.kivy/logs/kivy_20-09-17_0.txt
09-17 13:49:30.987 28441 28698 I python  : [INFO   ] [Kivy        ] v1.11.1
09-17 13:49:30.987 28441 28698 I python  : [INFO   ] [Kivy        ] Installed at "/data/user/0/in.wondersky.lr/files/app/_python_bundle/site-packages/kivy/__init__.pyc"
09-17 13:49:30.987 28441 28698 I python  : [INFO   ] [Python      ] v3.7.5 (default, Sep 16 2020, 22:35:10) 
09-17 13:49:30.987 28441 28698 I python  : [Clang 8.0.2 (https://android.googlesource.com/toolchain/clang 40173bab62ec7462
09-17 13:49:30.988 28441 28698 I python  : [INFO   ] [Python      ] Interpreter at "android_python"
09-17 13:49:31.988 28441 28698 I python  : [INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
09-17 13:49:32.021 28441 28698 I python  : [INFO   ] [Factory     ] 184 symbols loaded
09-17 13:49:32.312 28441 28698 I python  : [INFO   ] [Text        ] Provider: sdl2
09-17 13:49:32.657 28441 28698 I python  : [INFO   ] [Window      ] Provider: sdl2
09-17 13:49:32.684 28441 28698 I python  : [INFO   ] [GL          ] Using the "OpenGL ES 2" graphics system
09-17 13:49:32.685 28441 28698 I python  : [INFO   ] [GL          ] Backend used <sdl2>
09-17 13:49:32.685 28441 28698 I python  : [INFO   ] [GL          ] OpenGL version <b'OpenGL ES 3.2 v1.r19p0-01rel0.###other-sha0123456789ABCDEF0###'>
09-17 13:49:32.685 28441 28698 I python  : [INFO   ] [GL          ] OpenGL vendor <b'ARM'>
09-17 13:49:32.686 28441 28698 I python  : [INFO   ] [GL          ] OpenGL renderer <b'Mali-G71'>
09-17 13:49:32.686 28441 28698 I python  : [INFO   ] [GL          ] OpenGL parsed version: 3, 2
09-17 13:49:32.686 28441 28698 I python  : [INFO   ] [GL          ] Texture max size <8192>
09-17 13:49:32.686 28441 28698 I python  : [INFO   ] [GL          ] Texture max units <16>
09-17 13:49:32.709 28441 28698 I python  : [INFO   ] [Window      ] auto add sdl2 input provider
09-17 13:49:32.710 28441 28698 I python  : [INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
09-17 13:49:33.042 28441 28698 I python  : Hello
09-17 13:49:33.210 28441 28698 I python  : [ERROR  ] [Image       ] Error reading file logo_bg_small.png
09-17 13:49:33.257 28441 28698 I python  : [ERROR  ] [Image       ] Error reading file logo_bg_small.png
09-17 13:49:33.304 28441 28698 I python  : [ERROR  ] [Image       ] Error reading file logo_bg_small.png
09-17 13:49:33.341 28441 28698 I python  : [ERROR  ] [Image       ] Error reading file logo_bg_small.png
09-17 13:49:33.426 28441 28698 I python  : [INFO   ] [GL          ] NPOT texture support is available
09-17 13:49:33.429 28441 28698 I python  : [ERROR  ] [Image       ] Error reading file logo_bg_small.png
09-17 13:49:33.516 28441 28698 I python  : [ERROR  ] [Image       ] Error reading file logo_bg_small.png
09-17 13:49:33.518 28441 28698 I python  : [WARNING] [Base        ] Unknown <android> provider
09-17 13:49:33.518 28441 28698 I python  : [INFO   ] [Base        ] Start application main loop
09-17 13:49:33.520 28441 28698 I python  : MagicRoom.db
09-17 13:49:57.147 28441 28698 I python  : Wondersky permissions granted
09-17 13:50:03.198 28441 28441 I python  : ['/storage/emulated/0/DCIM/Screenshots/20200420_003038.jpg']
09-17 13:50:03.215 28441 28441 I python  :  Traceback (most recent call last):
09-17 13:50:03.215 28441 28441 I python  :    File "jnius/jnius_proxy.pxi", line 50, in jnius.jnius.PythonJavaClass.invoke
09-17 13:50:03.216 28441 28441 I python  :    File "jnius/jnius_proxy.pxi", line 76, in jnius.jnius.PythonJavaClass._invoke
09-17 13:50:03.216 28441 28441 I python  :    File "/home/ram/.local/share/python-for-android/build/python-installs/unnamed_dist_1/android/activity.py", line 35, in onActivityResult
09-17 13:50:03.216 28441 28441 I python  :    File "/home/ram/.local/share/python-for-android/build/python-installs/unnamed_dist_1/plyer/platforms/android/filechooser.py", line 153, in _on_activity_result
09-17 13:50:03.217 28441 28441 I python  :    File "/home/ram/PycharmProjects/Magic_Teacher_App/sources/main.py", line 267, in handle_selection
09-17 13:50:03.217 28441 28441 I python  :  PermissionError: [Errno 13] Permission denied: '/storage/emulated/0/DCIM/Screenshots/20200420_003038.jpg'

'''

Ramprasad S
  • 41
  • 1
  • 4

0 Answers0