【问题标题】:Android/NativeScript/JS. How to get absolute path including the file name from android media path?Android/NativeScript/JS。如何从android媒体路径获取包含文件名的绝对路径?
【发布时间】:2017-02-28 07:36:21
【问题描述】:

我在 nativescript 中获取图像的媒体路径

我的代码:

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

但我得到了这条路:

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

如何从该路径获取包含文件名的绝对路径??

请在 Nativescript/Javascript 实现中!如果有某种代码..

--

我需要这样的东西,但在 javascript 代码中:

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;
}

我怎样才能重写它!?

【问题讨论】:

标签: javascript android android-intent nativescript android-contentresolver


【解决方案1】:

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

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

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

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

也可以参考这个link

【讨论】:

  • 不,我需要这样的东西,但是在 javascript 代码中:请参阅我在 up 中添加的代码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-01
  • 2021-10-18
  • 1970-01-01
  • 2013-01-09
相关资源
最近更新 更多