+ this.fileUri = fileUri;
+
+ // Query the exact file name if the API >= 26.
+ if (Build.VERSION.SDK_INT >= 26) {
+ // Get a cursor from the content resolver.
+ Cursor contentResolverCursor = activity.getContentResolver().query(fileUri, null, null, null);
+
+ // Move to the first row.
+ contentResolverCursor.moveToFirst();
+
+ // Get the file name from the cursor.
+ fileNameString = contentResolverCursor.getString(contentResolverCursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME));
+
+ // Close the cursor.
+ contentResolverCursor.close();
+ } else {
+ // Use the file URI last path segment as the file name string.
+ fileNameString = fileUri.getLastPathSegment();
+ }