我得到了圖像的媒體路徑nativescriptAndroid/NativeScript/JS。如何從android媒體路徑獲取包含文件名的絕對路徑?
我的代碼:
var logoPath = argIntent.getParcelableExtra(Intent_1.EXTRA_STREAM);
,但我得到這個路徑:
內容://媒體/外部/圖像/媒體/ 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;
}
我怎樣才能把它改寫!?
相關http://stackoverflow.com/questions/37768820/file-system-sd-card-support。您也可以在這裏查看示例應用程序 - https://github.com/tsonevn/ReadFilesFromDevice/blob/master/app/main-page.ts#L21 –