我正在尝试包装在这里找到的 android API https://github.com/noke-inc/noke-mobile-library-android/blob/c95e45aeba686ec4c5cca932c9b47240d0ebc9cd/README.md
我想我已经弄清楚了接受这条线
public void onServiceConnected(ComponentName className, IBinder rawBinder) {
//Store reference to service
mNokeService = ((NokeDeviceManagerService.LocalBinder) rawBinder).getService();
public class LocalBinder extends Binder{
public NokeDeviceManagerService getService(){
return NokeDeviceManagerService.this;
}
}
我目前正在尝试用 pyjnius 做的是这个
NokeDeviceManagerService = autoclass('com.noke.nokemobilelibrary.NokeDeviceManagerService')
NokeDevice = autoclass('com.noke.nokemobilelibrary.NokeDevice')
NokeMobileError = autoclass('com.noke.nokemobilelibrary.NokeMobileError')
NokeServiceListener =autoclass('com.noke.nokemobilelibrary.NokeServiceListener')
class ServiceConnection(PythonJavaClass):
__javainterfaces__ = ('android.content.ServiceConnection')
__javacontext__ = 'app'
@java_method('(Landroid/content/ComponentName;Landroid/os/IBinder;)V')
def onServiceConnected(className, rawBinder):
nokeDeviceManagerService = NokeDeviceManagerService()
nokeService = cast(nokeDeviceManagerService.LocalBinder,rawBinder)
mNokeService = nokeService.getService()
#mNokeService = ((NokeDeviceManagerService.LocalBinder)rawBinder).getService()
mNokeServiceListener = NokeServiceListener()
mNokeService.registerNokeListener(mNokeServiceListener)
mNokeService.startScanningForNokeDevices()
我有点迷失在这一步该怎么做。将服务绑定在一起的例子并不多。
在 NokeDeviceManagerService 类里面有这个
public class NokeDeviceManagerService extends Service {
.
.
.
/**
* Class for binding service to activity
*/
public class LocalBinder extends Binder{
public NokeDeviceManagerService getService(){
return NokeDeviceManagerService.this;
}
}
我收到一个错误 AttributeError: 'com.noke.nokemobilelibrary.NokeDeviceManagerServic' 对象没有属性 'LocalBinder'