Reputation: 581
Today I started learning nativescript. I am trying to build simple ng2 app which would use 3rd party java library. I am trying to achieve something like in here
http://developer.telerik.com/featured/using-native-libraries-in-nativescript/
but I keep getting undefined errors.
I have no problem of accessing java within my ts code:
import app = require("application");
import platform = require("platform");
declare var java;
.......
public get message(): string {
var str = new java.lang.String('Hello world!');
var result = str.endsWith('world!');
console.log(result); // true
But I can't access 3rd party java library
import {Component} from "@angular/core";
import app = require("application");
declare var KontaktSDK;
@Component({
selector: "my-app",
templateUrl: "app.component.html",
})
export class AppComponent {
public counter: number = 16;
public onTap(args) {
KontaktSDK.initialize("API_KEY");
this.counter--;
}
}
It throws reference error "KontaktSDK is not defined"
Thank you for your help!
Upvotes: 1
Views: 1147
Reputation: 831
When accessing android native methods in nativescript you need to use the full package name and class e.g com.kontakt.sdk.android.common.KontaktSDK.initialize("API_KEY")
also a little trick i picked up while developing nativescript plugins is you can use console.dump(com.kontakt.sdk.android.common.KontaktSDK)
on a class and it would display all methods contained in that class . When in doubt log it out
Upvotes: 4