typescript - 使用 nativescript 调用 Android .arr 文件
问题描述
我们创建了一个 aar 文件,它基本上是一个用于读取卡片的原生 Android 应用程序,并将异步返回 json 格式的卡片详细信息。这工作正常,并在 nativescript 项目中导入了该 aar 文件。如何从导入的 aar 文件调用方法和回调。
解决方案
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
推荐阅读
- ios - ObjectBinding 和 EnvironmentObject 有什么区别?
- python - SQLAlchemy:在 Mixin [PostgreSQL] 中使用枚举
- rest - 如何使用数据库构建 RESTful 后端 API?
- javascript - 为什么我在运行 GET 请求 onChange 时只遇到 CORS 错误?
- elf - LD_BIND_NOW 对 ELF PIE 可执行文件不起作用
- c++ - 如何在 C++ 中对一列进行分组(计数)
- reactjs - 如果生产版本完全由静态文件组成,如何使用 Reac 制作动态网站?
- python-3.x - 在 python 中打印阿拉伯语内容的问题
- regex - 在python中按用户类型计算数据库命中
- android - 编译后的 APK 文件包含许多未知的 (A)XML 布局