@@ -37,6 +37,9 @@ public static String getRealPath(Context context, Uri fileUri) {
3737
3838 public static String getRealPathFromURI_API19 (final Context context , final Uri uri ) {
3939 // DocumentProvider
40+ if (isDriveFile (uri )) {
41+ return null ;
42+ }
4043 if (DocumentsContract .isDocumentUri (context , uri )) {
4144 // ExternalStorageProvider
4245 if (isExternalStorageDocument (uri )) {
@@ -47,6 +50,9 @@ public static String getRealPathFromURI_API19(final Context context, final Uri u
4750 if ("primary" .equalsIgnoreCase (type )) {
4851 return Environment .getExternalStorageDirectory () + "/" + split [1 ];
4952 }
53+ if ("home" .equalsIgnoreCase (type )) {
54+ return Environment .getExternalStorageDirectory () + "/" + split [1 ];
55+ }
5056
5157 } else if (isDownloadsDocument (uri )) {
5258
@@ -67,6 +73,10 @@ public static String getRealPathFromURI_API19(final Context context, final Uri u
6773 }
6874 }
6975 }
76+ } else {
77+ StringBuilder path = StringUtils .trimExternal (uri .getPath ().substring (1 ));
78+ path .insert (0 , Environment .getExternalStorageDirectory () + "/" );
79+ return path .toString ();
7080 }
7181 return null ;
7282 }
@@ -113,6 +123,20 @@ public static boolean isExternalStorageDocument(Uri uri) {
113123 return "com.android.externalstorage.documents" .equals (uri .getAuthority ());
114124 }
115125
126+ /**
127+ * This function is used to check for a drive file URI.
128+ *
129+ * @param uri
130+ * @return
131+ */
132+ public static boolean isDriveFile (Uri uri ) {
133+ if ("com.google.android.apps.docs.storage" .equals (uri .getAuthority ()))
134+ return true ;
135+ if ("com.google.android.apps.docs.storage.legacy" .equals (uri .getAuthority ()))
136+ return true ;
137+ return false ;
138+ }
139+
116140 /**
117141 * @param uri The Uri to check.
118142 * @return Whether the Uri authority is DownloadsProvider.
0 commit comments