from kivymd.app import MDAppfrom kivy.base import Builderfrom kivymd.toast import toastfrom android.permissions import request_permissions, Permissionimport sslimport requests# Import necessary Android modulesfrom jnius import autoclassfrom android import mActivity# Request storage permissionrequest_permissions([Permission.WRITE_EXTERNAL_STORAGE,Permission.READ_EXTERNAL_STORAGE])# Get the storage pathcontext = mActivity.getApplicationContext()storage_path = os.path.join(os.environ['EXTERNAL_STORAGE'], 'Download')KV='''#my design'''class MainApp(MDApp):def __init__(self, **kwargs):super().__init__(**kwargs)def build(self):return Builder.load_string(KV) def download_site(self):try:url = self.root.ids.site_link.textresponse = requests.get(url,verify=False)if response.status_code == 200:filename = os.path.join(storage_path, 'site.html')with open(filename, 'w', encoding='utf-8') as file:file.write(response.text)toast("Webpage source saved")else:toast("Failed to save webpage source.")except Exception as e:toast('Please check your Internet Connection')print(str(e))MainApp().run()
This is my main.py
. I've mentioned everything about permission. During run time my app asks for media and photo
access permission but don't asks for file access permission.That's why my app can't save the file site.html
.I've mentioned every possible permission in buildozer.spec
file but still not working.But other apps like PicsArt
ask for photo,media and file
access permission. But my app don't. Please help me.My Android version is 11
This is how my app look likes during run time
And this how other apps look likes during run time.I want my app to ask the same permissions like this app
I need file access permission to create file
Best Answer
In an Android 11 device your app cannot write files in root of external storage.
Instead use one of the public directories in external storage like DCIM, Pictures, Documents, Download and so on.