【问题标题】:Qpython Plyer GPS - Crash on call of gps.start() methodQpython Plyer GPS - 调用 gps.start() 方法时崩溃
【发布时间】: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


【解决方案1】:

代码没有运行,因为方法调用 bes gps plyer 作为参数传递 on_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()

【讨论】:

  • jeyfrin,感谢您的回答,但请务必始终使用代码格式化块使您的代码对其他用户可读。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-28
  • 1970-01-01
  • 1970-01-01
  • 2016-11-04
  • 2015-01-26
  • 1970-01-01
相关资源
最近更新 更多