Kivy - 在任何安卓设备上获取 DCIM 文件夹的路径 [英] Kivy - get the path to DCIM folder on any android device

查看:195
本文介绍了Kivy - 在任何安卓设备上获取 DCIM 文件夹的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想确切地知道如何使用 Kivy 在 android 上获取 DCIM 文件夹的路径.

I would like to know exactly how to get the path to the DCIM folder on android using just Kivy.

PyJinus 不是一个选项,因为它目前不适用于 Python 3.5

PyJinus is not an option as it currently doesn't work with Python 3.5

到目前为止我尝试的是:

What i tried so far is:

DATA_FOLDER = os.getenv('EXTERNAL_STORAGE') if platform is 'android' else os.path.expanduser("~")

但这只会让我获得用户区.有什么想法吗?

But this will only get me the user area. Any ideas?

推荐答案

使用 user_data_dir 如果您打算将 sdcard 用作应用程序的存储,请向上走(使用 user_data_dir 变量会创建一个文件夹):

Use user_data_dir and go up if you intend to use the sdcard as a storage for your app (the usage of user_data_dir variable creates a folder):

from kivy.app import user_data_dir
from os.path import dirname, join
join(dirname(user_data_dir), 'DCIM')

或者直接使用它的代码:

DCIM = join('/sdcard', 'DCIM')

我认为 /sdcard 只是指向真实文件夹(无论它在哪里)的符号链接,因此使用此路径只会在访问时获取值,例如到 /storage/sdcard0(符号链接)或者直接到真实路径.

I think /sdcard is only a symlink to the real folder (wherever it is), so a usage of this path just gets the value when accessed e.g. to /storage/sdcard0 (symlink) or rather directly to the real path.

除了这些解决方案,android 在环境中具有您已经注意到的路径:

Except those solutions, android has the path in the environment as you've noticed in:

  • EXTERNAL_STORAGE (/storage/emulated/legacy) 再次符号链接到 SD 卡
  • SECONDARY_STORAGE (/storage/extSdCard) 即用于外部卡,如果您在那里存储照片
  • EMULATED_STORAGE_TARGET (/storage/emulated) 基本上是您 sdcard 的父文件夹,其中真正的 sdcard(对我而言)在 /storage/extSdCard/emulated/0
  • EXTERNAL_STORAGE (/storage/emulated/legacy) again symlink to sdcard
  • SECONDARY_STORAGE (/storage/extSdCard) i.e. for the external card if you store photos there
  • EMULATED_STORAGE_TARGET (/storage/emulated) basically a parent folder for your sdcard, where the real sdcard (for me) is in /storage/extSdCard/emulated/0

这篇关于Kivy - 在任何安卓设备上获取 DCIM 文件夹的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆