We have created aar file which is basically an native Android application for reading the card and will return card details in json format asynchronously. This is working fine and imported that aar file in nativescript project. How to invoke methods and callback from the imported aar file.
Asked
Active
Viewed 948 times
1
-
Can you provide any of the android/java code or some dummy example of it? If not, the best answer I can give you is that once the Android build runs and compiles the aar into the app you have access to its API. Similar to this: https://github.com/bradmartin/nativescript-twitterbang/blob/master/src/twitterbang.android.ts#L46 where I've loaded a library via gradle, once built, that native package is available to be executed. – Brad Martin Apr 24 '18 at 19:18
-
@BradMartinis there any documentation to follow? – ShaMoh Apr 25 '18 at 08:25
-
Depends on what approach you take. This is one doc if you make a 'plugin' out of it https://docs.nativescript.org/runtimes/android/plugins/plugins. If you just load the .aar privately for your app and don't want to hassle with the 'plugin' aspect then you would just add the .aar to your project, and then you have the library exposed inside your app when you run it. – Brad Martin Apr 25 '18 at 16:48
1 Answers
0
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

bhavin jalodara
- 1,470
- 9
- 12