Android Get Uri file path from Google Drive

I have this code for uploading a file to my application, and when the file is opened by the file manager or Dropbox or something else, the return path is correct and I can access it, I only have problems with Google Drive, it returns some path starting with β€œexposed” and I cannot β€œdecode” it in any way, I searched and did not find a way, who has any ideas?

if (resultCode == Activity.RESULT_OK) { if ((data != null) && (data.getData() != null)) { final Uri filePath; if (data.getDataString().startsWith("content")) { filePath = getRealPathFromURI(getApplicationContext(), data.getData()); } else { filePath = data.getData(); } // TODO bug with google drive if (filePath.getLastPathSegment() != null) { tvSelectedFile.setText("File selected: " + filePath.getLastPathSegment()); } else { tvSelectedFile.setText("File can not be accessed, please try another way"); } } } 
+7
android google-drive-sdk android-file
source share
1 answer

Use the attached code ... from the result of onActivity you will get uri content ... pass this uri to this method ...

 public static String getGDriveDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null; final String column = "_display_name"; final String[] projection = { column }; try { cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { final int column_index = cursor.getColumnIndexOrThrow(column); return cursor.getString(column_index); } } finally { if (cursor != null) cursor.close(); } return null; } 
-one
source share

All Articles