Getting error to access external storage of Android


#1

Hi,

I am trying to access external storage of Android like this:

var path = fs.path.join(android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DCIM).getAbsolutePath(), "Camera");
console.log(path)

But I am getting this error:

JS: ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'os' of undefined
JS: TypeError: Cannot read property 'os' of undefined
JS:     at new MyCoursesComponent (file:///data/data/org.nativescript.NativeScript/files/app/components/mycourses/mycourses.js:85:40)
JS:     at createClass (file:///data/data/org.nativescript.NativeScript/files/app/tns_modules/@angular/core/bundles/core.umd.js:10912:26)
JS:     at createDirectiveInstance (file:///data/data/org.nativescript.NativeScript/files/app/tns_modules/@angular/core/bundles/core.umd.js:10730:37)
JS:     at createViewNodes (file:///data/data/org.nativescript.NativeScript/files/app/tns_modules/@angular/core/bundles/core.umd.js:12093:49)
JS:     at createRootView (file:///data/data/org.nativescript.NativeScript/files/app/tns_modules/@angular/core/bundles/core.umd.js:11998:5)
JS:     at Object.createProdRootView [as createRootView] (file:///data/data/org.nativescript.NativeScript/files/app/tns_modules/@angular/core/bundles/core.umd.js:12659:12)
JS:     at ComponentFactory_.create (file:///data/data/org.nativescript.NativeScript/files/app/tns_modules/@angular/core/bundles/core.umd.js:9919:46)
JS:     at ComponentFactoryBoundToModule.create (file:///data/data/org.nativescript.NativeScript/files/app/tns_modules/@angular/core/bundles/core.umd.js:3455:29)
JS:     at ViewContainerRef_.createComponent (file:///data/data/org.nativescript.NativeScript/files/app/tns_modules/@angular/core/bundles/core.umd.js:10121:62)
JS:     at DetachedLoader.loadWithFactory (file:///data/data/org.nativescript.NativeScript/files/app/tns_modules/nativescript-angular/common/detached-loader.js:38:34)
JS:     at PageRouterOutlet.activateOnGoForward (file:///data/data/org.nativescript.NativeScript/files/app/tns_modules/nativescript-angular/router/page-router-outlet.js:167:60)
JS:     at PageRouterOutlet.activateWith (file:///data/data/org.nativescript.NativeScript/files/app/tns_modules/nativescript-angular/router/page-router-outlet.js:139:18)
JS:     at ActivateRoutes.placeComponentIntoOutlet (file:///data/data/org.nativescript.NativeScript/files/app/tns_modules/@angular/router/bundles/router.umd.js:4526:16)
JS:     at ActivateRoutes.activateRoutes (file:///data/data/org.nativescript.NativeScript/files/app/tns_modules/@angular/router/bundles/router.umd.js:4507:26)
JS:     at file:///data/data/org.nativescript.NativeScript/files/app/tns_modules/@angular/router/bundles/router.umd.js:4443:58

In where I am doing wrong?


#2

Did you define android as ‘declare const android: any;’?