from kivy import platform
from kivy.factory import Factory
from kivy.app import App
import os
class TestApp(App):
def on_start(self):
if platform == "android":
from android.permissions import Permission, check_permission, request_permissions
perms = [Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE]
if not all([check_permission(perm) for perm in perms]):
Factory.MyPermReqPopup().open()
def popup_close(self):
from android.permissions import Permission, request_permissions
request_permissions([Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE])
exit()
def create_folder_click(self):
if platform == "android":
from android.storage import primary_external_storage_path
os.makedirs(str(primary_external_storage_path()) + "/Android/data/org.app.test/folder", exist_ok=True)
TestApp().run()
1条答案
按热度按时间yebdmbv41#
你的应用需要请求存储权限才能访问它的私有文件夹之外的文件。下面是工作示例。我将
os.mkdir
更改为os.makedirs
,以便能够创建你的路径的父目录。main.py
test.kv