Closed zwyuan closed 7 years ago
The bug is cause by using PythonActivity
to cast an Android class. In fact, the plugins are run as PythonService
in MobileInsight, therefore the type of pyActivity will be <type 'NoneType'> and cause error. Users should use PythonService
to cast classes, see below an example:
#!/usr/bin/python
import os
import sys
from jnius import autoclass, cast
'''
Don't use the following block in a plugin:
PythonActivity = autoclass('org.kivy.android.PythonActivity')
pyActivity = PythonActivity.mActivity
The plugins are run as PythonService in MobileInsight, therefore
the type of pyActivity will be <type 'NoneType'> and cause error
'''
PythonService = autoclass('org.kivy.android.PythonService')
pyService = PythonService.mService
Context = autoclass('android.content.Context')
mWifiManager = pyService.getSystemService(Context.WIFI_SERVICE)
mWifiInfo = mWifiManager.getConnectionInfo()
print mWifiInfo.getBSSID()
print mWifiInfo.getFrequency()
I will commit an example plugin for this.
See commit 222861d
The below demo code will lead to crash if saved as a plugin (
main.mi2app
):The crash log is attached here: