code: private static String getFileName(Context context, Uri uri){
          Cursor c = context.getContentResolver().query(uri, null, null, null, null);
          int nameIndex = c.getColumnIndex(OpenableColumns.DISPLAY_NAME);
          c.moveToFirst();
          String fileName = c.getString(nameIndex);
          c.close();
          return fileName;
      }
docs: Get the filename of an {@link Uri} that was returned from the storage access framework
  
  @param context       the application context to get the content resolver
  @param uri           the uri to get the name of
  @return              the name, or null