首页 > 解决方案 > 使用 nativescript 调用 Android .arr 文件

问题描述

我们创建了一个 aar 文件,它基本上是一个用于读取卡片的原生 Android 应用程序,并将异步返回 json 格式的卡片详细信息。这工作正常,并在 nativescript 项目中导入了该 aar 文件。如何从导入的 aar 文件调用方法和回调。

标签: typescriptteleriknativescriptnativescript-angularnativescript-plugin

解决方案


suppose in android you are importing method by import info.card.getCardsInfo and then calling it to get some data like Cards[] cards=getCardsInfo()

in above case after importing aar file in nativescript project. to get the card data you have to use below code.

declare var info:any

export class CardService{
    public getCard(){
        let cards=info.card.getCardsInfo;
        return cards;
    }
}

in nativescript to access any android native packages you can directly access them from any location inside your code like com.package.app.method. but to make sure TS compiler don't give you error. you have to declare the com variable to any like this declare var com:any or let com:any inside your TS file before accessing native apis.

more info on this can be found at https://docs.nativescript.org/angular/runtimes/android/metadata/accessing-packages


推荐阅读