I've been trying to create an Android app to check if the phone's wifi is turned on or off. What I'm trying to do is, if the WiFi is on, then is shows a BoxLayout which is white in color and if it isn't on, then it shows a Popup. I'm new to Android Development and I got hooked to Kivy because of its simplicity and my love for Python. I tried following Pyjnius docs, but I couldn't get the app to run. So I'll post the code here:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.popup import Popup
from kivy.uix.button import Button
from kivy.lang import Builder
from jnius import autoclass
Builder.load_string('''
<WiFiENABLED>
canvas.before:
Color:
rgb: 1, 1, 1
Rectangle:
pos: self.pos
size: self.size
<WiFiDISABLED>
BoxLayout:
orientation: 'vertical'
Label:
text:"Wifi is turned off"
Button:
text:"OK"
<Box>
Label:
text: "WiFi Tester"
''')
class WiFiENABLED(BoxLayout):
def wfenabled(self):
pass
class WiFiDISABLED(Popup):
def wfdisabled(self):
pass
class WiFiStatus():
def WiFi(self):
WiFi_Status = autoclass('android.net.wifi.WiFiManager')
WiFi = WiFi_Status.getSystemService(Context.WIFI_SERVICE)
if WiFi.getWifiState() == WiFi.WIFI_STATE_ENABLED:
return WiFiENABLED()
elif WiFi.getWifiState() == WiFi.WIFI_STATE_DISABLED:
return WiFiDISABLED()
class Box(BoxLayout):
def b(self):
return WiFiStatus()
class WF(App):
def build(self):
return Box()
if __name__ == "__main__":
WF().run()
And should I make any changes to permissions in builder.spec file? As of now, it is just INTERNET.