1

I get media path of image in nativescript

my code:

var logoPath = argIntent.getParcelableExtra(Intent_1.EXTRA_STREAM);

but I get this path:

content://media/external/images/media/152

How to get absolute path including the file name from this path??

In Nativescript/Javascript implementation please! if there is some kind of code ..

--

I need something like this, but in javascript code:

public static String getRealPathFromURI_API19(Context context, Uri uri){
    String filePath = "";
    String wholeID = DocumentsContract.getDocumentId(uri);

     // Split at colon, use second item in the array
     String id = wholeID.split(":")[1];

     String[] column = { MediaStore.Images.Media.DATA };     

     // where id is equal to             
     String sel = MediaStore.Images.Media._ID + "=?";

     Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 
                               column, sel, new String[]{ id }, null);

     int columnIndex = cursor.getColumnIndex(column[0]);

     if (cursor.moveToFirst()) {
         filePath = cursor.getString(columnIndex);
     }   
     cursor.close();
     return filePath;
}

How I can rewrite it!?

LS2010
  • 121
  • 5
  • related to http://stackoverflow.com/questions/37768820/file-system-sd-card-support . You could also review the sample app here - https://github.com/tsonevn/ReadFilesFromDevice/blob/master/app/main-page.ts#L21 – Nikolay Tsonev Feb 28 '17 at 09:28

1 Answers1

0
String path = yourAndroidURI.uri.getPath() // "file:///mnt/sdcard/FileName.mp3"

File file = new File(new URI(path));

or

String path = yourAndroidURI.uri.toString() // "/mnt/sdcard/FileName.mp3"

File file = new File(new URI(path));

also refer this link

Pranav Singh
  • 17,079
  • 30
  • 77
  • 104
vijay chhalotre
  • 396
  • 2
  • 11