【发布时间】:2015-07-13 18:20:17
【问题描述】:
我的目标是使用 python 模块 Plyer(版本 1.2.4 了解我的 Nexus 5(Andrid 5.1.1)的地理坐标em>)。
所以我在我的智能手机上安装了解释器 QPython2.7(版本 1.0.6),并受 Plyer 文档 https://plyer.readthedocs.org/en/latest/#plyer.facades.GPS 上的示例启发编写了以下代码. Qpyton2.7 安装包括我在代码中使用的 Kivy 模块(版本 1.8.0)。
我期望程序做什么:
当我按下按钮时,程序将启动位置更新,当我再次按下它时,程序将停止更新。 当程序更新位置时,它会调用 loc() 方法将按钮文本值更新为当前位置。
程序的真正作用:
它在 gps.start() 调用时崩溃。
注意事项:
程序不会在 gps.configure() 之前的调用中崩溃。 Plyer 模块的方法 vibrator.vibrate() 工作正常!
报告错误:
...
文件“jnius_export_class.pxi”,第 562 行,在 jnius.jnius.JavaMethod.call (jnius/jnius.c:17724) 文件“jnius_export_class.pxi”,第 656 行,在 jnius.jnius.JavaMethod.call_method (jnius/jnius.c:18722) 文件“jnius_utils.pxi”,第 43 行,在 jnius.jnius.check_exception (jnius/jnius.c:3175) jnius.jnius.JavaException: 发生 JVM 异常
代码:
#qpy:kivy
from plyer import vibrator
from plyer import gps
from kivy.app import App
from kivy.uix.button import Button
class TestApp(App):
def build(self):
self.locbutton = Button(text='START', on_press=self.start_stop)
return self.locbutton
def on_start(self):
gps.configure(on_location=self.loc)
def loc(self, **kwargs):
self.locbutton.text = 'lat:{lat},lon:{lon}'.format(**kwargs)
def start_stop(self, instance):
if self.locbutton.text == 'START':
#self.locbutton.text = 'STOP'
gps.start()
else:
gps.stop()
self.locbutton.text = 'START'
vibrator.vibrate(0.01)
TestApp().run()
【问题讨论】:
-
这和权限有关吗?
-
可能是,在网上搜索我发现权限可能会影响 Plyer 操作,但我不知道如何解决。
-
我现在检查了Info App中的QPython授权,它似乎可以访问本地化系统!
-
我用 Kivy Launcher 运行程序,一切正常!我不知道为什么 QPython 执行失败。
标签: android python gps kivy qpython