Reputation: 29
from kivymd.app import MDApp
from kivy.base import Builder
from kivymd.toast import toast
from android.permissions import request_permissions, Permission
import ssl
import requests
# Import necessary Android modules
from jnius import autoclass
from android import mActivity
# Request storage permission
request_permissions([Permission.WRITE_EXTERNAL_STORAGE,Permission.READ_EXTERNAL_STORAGE])
# Get the storage path
context = 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.text
response = 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
I need file access permission to create file
Upvotes: 0
Views: 12695
Reputation: 1
Although I am new here , I had the same problem and I had to make alot of research. What I could come up with is the Permission.MANAGE_EXTERNAL_STORAGE. I added it to my buildozer.spec file. It prompted me to view and write only media files . I had to go to settings to allow File access permission which is the uttermost permission. Just add Permission.READ..., Permission.WRITE... and Permission.MANAGE_EXTERNAL_STORAGE TO YOUR app source file and to your buildozer.spec file. Note use try and except because android 10 an less requires only Read and write permission. Only android 11 and above allows read, write and manage permission
Upvotes: 0
Reputation: 9292
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.
Upvotes: 1