如何使用 Kivy for Android 以 root 身份读取/写入文件?
我想在我的 Kivy 应用程序中写入 /etc/hosts,并且我肯定有一个需要测试的 root 设备。我尝试了多种方法,但总是让我的应用程序退出而没有任何警告或错误。
我试过:
subprocess.Popen("su -c touch /etc/hosts", shell = True)
subprocess.Popen("su -c bash -c touch /etc/hosts ", shell = True)
subprocess.Popen(["su", "-c", "bash -c touch /etc/hosts"])
以及它们的几种组合。每次我都能收到 su 应用程序消息框询问我的许可,然后我按“允许”,但我的应用程序在那之后退出。
编辑:logcat输出位于http://pastebin.com/YMT5Vxra
非常感谢,如果任何人都可以提出任何建议!
I would like to write to /etc/hosts in my Kivy app, and I've surely a rooted device to test. I tried several ways but always get my app exit without any warning or error.
I've tried:
subprocess.Popen("su -c touch /etc/hosts", shell = True)
subprocess.Popen("su -c bash -c touch /etc/hosts", shell = True)
subprocess.Popen(["su", "-c", "bash -c touch /etc/hosts"])
and several combinations of them. Every time I can get the su app message box asking me for permission and I pressed "Allow", but my app exits after that.
EDIT: logcat output is at http://pastebin.com/YMT5Vxra
Many thanks if anyone can give any suggestion!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的错误表明字符串转义不是已知的编码。 Kivy 正在随其库发布 Python 的精简版,而不是所有编码。您可以尝试的是:
然后那应该有效。
一旦 kivy 不传送你想要的文件,pgs4a-kivy 项目就不好。这就是我启动 python-for-android 项目的原因。您将在最终发行版中拥有您想要或不需要的权力。
Your error indicate that string-escape is not a known encoding. Kivy is shipping a lite version of Python with their libs, not all the encodings for example. What you can try is to:
Then that should work.
The pgs4a-kivy project is not good as soon as kivy is not shipping the files you want. This is why i've started python-for-android project. You'll have the power of what you want or not in your final distribution.