1

I am trying to implement android.bluetooth.le.ScanCallback which is an abstract class using pyjnius. The moment I instantiate the given below python class there is a JVM error. The error states that android.bluetooth.le.ScanCallback is not an interface class. I believe an interface is an abstract class. What am I missing?

class ScanCallback(PythonJavaClass):
    
    __javainterfaces__ = ['android/bluetooth/le/ScanCallback'] 

    def __init__(self, scanCallback, batchCallback=None, errorCallback=None):
        super(ScanCallback, self).__init__()
        self.batchCallbk = batchCallback
        self.scanCallbk = scanCallback
        self.errorCallbk = errorCallback
        pass

    @java_method ('(L/java/utils/List<ScanResult>/)V')
    def onBatchScanResults(self,results): 
        print dir(results)

    @java_method ('(I)V')   
    def onScanFailed(self, errorCode):
        print "failed to scan" + str(errorCode)
        raise ValueError(str(errorCode))
    
    @java_method ('(IL/android/bluetooth/le/ScanResult)V')
    def onScanResult(self, callbackType, result):
        print dir(result)
Nux ツ
  • 146
  • 1
  • 7

1 Answers1

0

I found out that with PyJNius it is only possible to implement interface class (pure abstract class) not an abstract class. "android/bluetooth/le/ScanCallback" is an abstract class not an interface class which was the case with earlier bluetooth API (< 21).

  • This is a problem shared by java interfaces on android. It would be good if Google would offer user classes as interfaces so that third party apis could provide them. Android uses a different bytecode system preventing the normal approach. – fuzzyTew Dec 19 '20 at 12:09