androidnativescriptangular2-nativescript

How can I choose picture from android gallery using Nativescript?


I have been browsing Nativescript website and did not manage to find a way to get a picture locally from my phone. If anyone knows a way to do it on both android and ios I would be really glad.


Solution

  • In your case you could use file-system module and native code to access the external storage from your device. you can get the path to the file and open it with the NativeScript file-system api. I am attaching sample example how you could get the path os an image from the Camera Roll storage. You could also review the article here, where has been described, what you could access from android device storage.

    typescript

     import {path} from "file-system";
    
     var tempPicturePath = path.join(android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DCIM).getAbsolutePath(), "20160719_155053.jpg");
        console.log("extr storage "+tempPicturePath);
    

    javascript

    var file_system_1 = require("file-system");
    
    var tempPicturePath = file_system_1.path.join(android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DCIM).getAbsolutePath(), "20160719_155053.jpg");
            console.log("extr storage " + tempPicturePath);