3
I’ve developed a small test app that checks both the battery status and whether the phone is being charged.
The app is running local from python main.py
, but when I install it in Android Studio Emulator, the software initializes and closes.
Updating
The package for Android is being generated with the buildozer
buildozer.spec (only settings)
[app]
title = My Test
package.name = mytest
package.domain = org.test
source.dir = .
source.include_exts = py,png,jpg,kv,atlas
source.exclude_exts = spec
version = 0.1
requirements = python3, kivy==2.0.0, kivymd==0.104.1, sdl2_ttf == 2.0.15
icon.filename = %(source.dir)s/data/icon.png
orientation = portrait
osx.python_version = 3
osx.kivy_version = 1.9.1
fullscreen = 0
android.permissions = BATTERY_STATS
android.arch = armeabi-v7a
[buildozer]
log_level = 2
warn_on_root = 1
End of update
I already understand that the problem is when I use the kivimd, with the kivy worked.
Follows the code
mytest.Kv
#:import MDLabel kivymd.uix.label
#:import MDBoxLayout kivymd.uix.boxlayout
#:import MDFloatLayout kivymd.uix.floatlayout
#:import MDTextButton kivymd.uix.button
<Page>:
lbl1: lbl1
lbl2: lbl2
MDFloatLayout:
MDTextButton:
center: root.center
size_hint_y: None
pos_hint: {'y': .5}
text: "Battery Status"
on_press: root.get_status()
MDBoxLayout:
size_hint_y: None
pos_hint: {'y': .1}
MDLabel:
text: "Is Charging?"
MDLabel:
id: lbl1
text:
MDLabel:
text: "Percentage"
MDLabel:
id: lbl2
text:
main py.
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from plyer import battery
class Page(MDBoxLayout):
def get_status(self, *args):
self.lbl1.text = str(battery.status['isCharging'])
self.lbl2.text = str(battery.status['percentage']) + "%"
class MyTest(MDApp):
def build(self):
return Page()
def on_pause(self):
return True
if __name__ == "__main__":
app = MyTest()
app.run()
Note: Replacing kivymd
for kivy
and replacing from MD to , works.
If you need more information, please comment on the post.
For those who voted against this question, could you tell me why I can improve it?
– Paulo Marques
I’m sorry, I don’t understand. Have you solved your problem? If so, answer your own question to stay in Q&A format instead of adding notes to the question. It’s hard to understand the way it is.
– Lucas
@Lucas. The problem NAY is solved. Are you familiar with the mobile development process using the Kivy framework? Kivymd is from the same group of Kivy developers. What I asked is using the Kivy framework is working, but with Kivymd it is not. Why Kivymd? Good question. It brings facilities to the layout.
– Paulo Marques