-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't write ti SD-card on Android 6.0.1 #1024
Comments
I believe the permission is the same - |
I'm currently writing to /sdcard on Android 6.0.1 without any special effort. (that's where the kivy writes its ini files, for instance). Can you show the actual code and error messages? |
Hey, was this fixed? Is there a way at all to write to sdcard using kivy and modern android? |
I think it can be done using jnius. Here it says you need to open the Uri treeUri = resultData.getData();
DocumentFile pickedDir = DocumentFile.fromTreeUri(this, treeUri);
grantUriPermission(getPackageName(), treeUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
getContentResolver().takePersistableUriPermission(treeUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
copyFile(sdCard.toString(), "/File.txt", path + "/new", pickedDir); I managed to open the tree file and get the uri, but I can't find how to call Here is what I have: import kivy
from kivy.app import App
from kivy.uix.button import Button
from jnius import cast
from jnius import autoclass
import os
from android import activity
# Forum discussion: https://groups.google.com/forum/#!msg/kivy-users/bjsG2j9bptI/-Oe_aGo0newJ
def on_activity_result(request_code, result_code, intent):
PythonActivity = autoclass('org.kivy.android.PythonActivity')
currentActivity = cast('android.app.Activity', PythonActivity.mActivity)
uri = str(selectedImage.toString())
print(uri)
return
class MyApp(App):
def callback(self, data):
print("Started folder picker")
# import the needed Java class
PythonActivity = autoclass('org.kivy.android.PythonActivity')
Intent = autoclass('android.content.Intent')
Uri = autoclass('android.net.Uri')
# create the intent
intent = Intent()
intent.setAction(Intent.ACTION_OPEN_DOCUMENT_TREE)
currentActivity = cast('android.app.Activity', PythonActivity.mActivity)
activity.bind(on_activity_result=on_activity_result)
currentActivity.startActivityForResult(intent, 1)
def build(self):
return Button(text='Hello world', on_press=self.callback)
if __name__ == '__main__':
MyApp().run() |
@gdyuldin if you use #1528 's branch and use the permission api, you can do it like this (although you'll need to check if the permission was granted with a timer, there is no callback support yet):
After you gained permission, you can just use regular |
@Jonast |
@guysoft sorry I really don't know, I don't use buildozer myself (I use p4a directly) |
@Jonast You could just modify the URL in the kivy recipe to point to your repo/branch. I have a WIP where I also pass
|
@hackalog wouldn't it make more sense to just add |
Yes, the You can change the url-string to anything you want. if you know the owner, repo name (or |
Are the repo + owner names used anywhere else? If not it seems a bit redundant to have them separately. But apart from that, this sounds like a very useful addition worth a buildozer pull request |
Ok, got it building from that fork which I merged with master. Its done by pointing in Using #1528 fails for me because of outdated
|
@Jonast ok after merging and using #1528 , it still does not work. I made a small repo with simple reproduction steps so you can try it out and we can look at the same code, have a feeling you might spot the error if you take a look, instructions in a comment in the PR, It also uses your docker images that are now hosted on github 🙂 : |
The permission API is now implemented with on master with #1528 merged, even though the callback mechanism probably would still be worth adding at some point. The functionality is documented here: The latest kivy development version should also per default save the config to a writable location now (without any more general sd card permissions necessary) |
Hello everyone! So, I'm trying to create an empty file on SD-card. I've two phones, first with Android 4.4 and second with Android 6.0.1. My application works very well on the first phone, but not on the second. I heard, that there is a new permission for writing on SD-card on Android 6.0.1: WRITE_MEDIA_STORAGE. But with this permission I have the following error:
"android.permission" contain an unknown permission WRITE_MEDIA_STORAGE
So, the question is: how to write on SD-card on Android 6.0.1?
The text was updated successfully, but these errors were encountered: