How to save acceleration data in a file on my android device using python kivy? -
i used jsonstorage , pickle did not work. maybe doing wrong way? activity appears , disappears. log says handler error. in update()
function value storing txt
variable. want store txt
in external file on mobile phone.
my code:
__version__ = '1.0' # declare app version. used buildozer kivy.app import app # main app kivy.uix.floatlayout import floatlayout # ui layout kivy.uix.label import label # label show information plyer import accelerometer # object read accelerometer kivy.clock import clock # clock schedule method class ui(floatlayout): # app ui def __init__(self, **kwargs): super(ui, self).__init__(**kwargs) self.lblacce = label(text="accelerometer: ") # create label @ center self.add_widget(self.lblacce) # add label @ screen try: accelerometer.enable() # enable accelerometer # if want disable it, run: accelerometer.disable() clock.schedule_interval(self.update, 2.0/1) # 24 calls per second except: self.lblacce.text = "failed start accelerometer" # error def update(self, dt): txt = "" try: txt = "accelerometer:\nx = %.2f\ny = %.2f\nz = %2.f " %( accelerometer.acceleration[0], # read x value accelerometer.acceleration[1], # y accelerometer.acceleration[2]) # z except: txt = "cannot read accelerometer!" # error self.lblacce.text = txt # add correct text class accelerometer(app): # our app def build(self): ui = ui() # create ui return ui # show if __name__ == '__main__': accelerometer().run() # start our app
just use json store.it surely work. here code : add import jsonstore jsonstore=(/storage/emulated/0/hello.json); json.put(txt)
Comments
Post a Comment