Android Qpython Plyer GPS-调用GPS.start()方法时崩溃
我的目标是使用python模块Plyer(版本1.2.4)了解Nexus5(andrid5.1.1)的地理坐标 因此,我在智能手机上安装了解释器QPython2.7(1.0.6版),并根据Plyer文档中的示例编写了以下代码。 Qpyton2.7安装包括我在代码中使用的Kivy模块(1.8.0版) 我期望该计划做什么:Android Qpython Plyer GPS-调用GPS.start()方法时崩溃,android,python,gps,kivy,qpython,Android,Python,Gps,Kivy,Qpython,我的目标是使用python模块Plyer(版本1.2.4)了解Nexus5(andrid5.1.1)的地理坐标 因此,我在智能手机上安装了解释器QPython2.7(1.0.6版),并根据Plyer文档中的示例编写了以下代码。 Qpyton2.7安装包括我在代码中使用的Kivy模块(1.8.0版) 我期望该计划做什么: #qpy:kivy from plyer import vibrator from plyer import gps from kivy.app import App from
#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()
当我按下按钮时,程序将启动位置更新。当我再次按下按钮时,程序将停止更新。
当程序更新位置时,它将调用loc()方法用当前位置更新按钮文本值
该程序的真正功能:
#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()
它在gps.start()调用时崩溃
注意事项:
#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()
程序不会在gps上崩溃。configure()上一次调用。
Plyer模块的可控震源.vibrate()方法工作正常
报告的错误:
#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()
文件“jnius_export_class.pxi”,第562行,在jnius.jnius.JavaMethod.call中(jnius/jnius.c:17724)
文件“jnius_export_class.pxi”,第656行,在jnius.jnius.JavaMethod.call_方法(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()
由于方法调用bes gps plyer作为参数在_location=其函数示例上传递,因此代码未运行:
from plyer import gps
from kivy.app import App
from import kivy.uix.button Button
class mi_app(App):
def buscar_coord (self, **kwargs):
info = Kwargs.items()
## Decodificas the json
print str(info)
def gps_activar(self, ins):
self.buscar_coord()
def build(self):
gps.configure (on_location = self.buscar_coord)
## we call start method
gps.start ()
return Button(text = "TEST_GPS" on_release = self.gps_activar)
mi_app().run()
这可能与权限有关吗?可能是,在互联网上搜索我发现权限可能会影响Plyer的操作,但我不知道如何解决。我现在检查了信息应用程序中的QPython授权,它似乎可以访问本地化系统!我用Kivy Launcher运行程序,一切正常!我不知道QPython执行失败的原因。jeyfrin,谢谢您的回答,但请确保始终使用代码格式化块,以使您的代码对其他用户可读。