How to access Google Play Services in NativeScript

心已入冬 提交于 2019-12-03 08:43:28

In NativeScript when developing for Angular if a library/plugin is available in Jcenter/Maven Repository (Repositories for Android plugins, much like npmjs for all things JavaScript), or in your local Android SDK installation, then you can reference that dependency in your App_Resources/Android/app.gradle file.

Example:

dependencies {
    compile 'com.google.android.gms:play-services:9.0.0'
}

android {  
  defaultConfig {  
    generatedDensities = []
    applicationId = "org.nativescript.myApp"  
  }  
  aaptOptions {  
    additionalParameters "--no-version-vectors"  
  }  
} 

Build-time those dependencies will be downloaded and properly added to the project, so that you may consume them in your app.

As the next step you may want to read up on the usage of the library that you want to use. That will most likely be API Docs site, or Android/Java code samples. In NativeScript you are able to access Native API as you would if you were writing a native application. That means that "translating" the code you find in samples should be almost effortless. You can find sufficient information in the official docs site to get you started.

https://docs.nativescript.org/runtimes/android/marshalling/java-to-js https://docs.nativescript.org/runtimes/android/metadata/accessing-packages.html

Having said all that - back to your code sample - the class that you are attempting to instantiate is abstract, meaning you can only create instances of a non-abstract non-static descendant of that class (https://developers.google.com/android/reference/com/google/android/gms/common/api/GoogleApiClient).

If you were to write that in NativeScript however, for the sake of the example, let's assume we CAN create instances, we would write it like this -> var apiClient = new com.google.android.gms.common.api.GoogleApiClient();

Good luck!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!