Android implementation of Kontakt SDK


#1

Hi,

I am developing a plugin for the Kontakt IO SDK (Beacons)
The iOS part is done but I have issues with the Android part…

I got this error when I want to create the BeaconListener :

Uncaught (in promise): Error: Cannot convert JavaScript object with id 516837868 at index 0

const KontaktSDK = com.kontakt.sdk.android.common.KontaktSDK;
const ProximityManager = com.kontakt.sdk.android.ble.manager.ProximityManager;
const ScanPeriod = com.kontakt.sdk.android.ble.configuration.ScanPeriod;
const ScanMode = com.kontakt.sdk.android.ble.configuration.scan.ScanMode;
const SimpleIBeaconListener = com.kontakt.sdk.android.ble.manager.listeners.simple.SimpleIBeaconListener;

constructor() {
	KontaktSDK.initialize(apiKey);
	this.proximityManager = new ProximityManager(application.android.foregroundActivity);
    this.proximityManager.configuration()
        .scanPeriod(ScanPeriod.RANGING)
        .scanMode(ScanMode.BALANCED);
}

public startListening() {
    this.proximityManager.setIBeaconListener(new SimpleIBeaconListener({
        onIBeaconsUpdated: function(beacons, region) {
            console.log('BEACONS', beacons);
        }
    }));
}

SDK used : https://github.com/kontaktio/kontakt-android-sdk/tree/master/3.1.1

Someone can help me ? Thanks


#2

Hey Juneli,

It doesn’t become clear what class you are extending, nor what the typescript constructor belongs to.

The first thing that comes to my mind when I see that error is that you are extending a native Android class in TypeScript, naturally a typescript constructor will return a reference to the JavaScript object, and not to that of the underlying extended native object. The solution is simple, append the following at the end of your constructor:

return global.__native(this);

Please provide a complete code sample if what I wrote above doesn’t work for you.

Good luck!


#3

Hi Pete,

I was just trying to implement a Java Interface but it was a Class…
Sorry…