As the documentation suggests:
The Android packages are available in the JavaScript/TypeScript global context and are the entry point for accessing Android APIs. Think of them as of TypeScript/C# namespaces, or the way to access sets of classes. For example, the
android.view
package grants access to classes likeandroid.view.View
- the base of all view elements in Android.
But when I try to access any package it gives me following error:
Error: Cannot find name 'android'
I don't know what is wrong here maybe the documentation is outdated or I am missing something. If you know that please let me know please let me know I can solve this problem.
When working with TypeScript (and even with plain JavaScript if you want intelliSense for the native APIs) you need to have explicit declarations (usually coming from typings files with *.d.ts extension). From the same documentation article, you have referred
Note: To have access and Intellisense for the native APIs with NativeScript + TypeScript or NativeScript + Angular projects, you have to add a dev dependency to
tns-platform-declarations
. More details about accessing native APIs with TypeScript can be found here.
Detailed instructions for how to use tns-platform-declarations
can also be found here or in the plugin's instructions