title: Null when trying to parse Uri from String path
body: <p>I'm using this <code>FileUtils</code> class to handle the <code>Uri</code>:</p>
  <pre><code>public class FileUtils {
  private FileUtils() {
  }
  
  private static final String TAG = &quot;FileUtils&quot;;
  private static final boolean DEBUG = false;
  
  private static boolean isExternalStorageDocument(Uri uri) {
      return &quot;com.android.externalstorage.documents&quot;.equals(uri.getAuthority());
  }
  
  private static boolean isDownloadsDocument(Uri uri) {
      return &quot;com.android.providers.downloads.documents&quot;.equals(uri.getAuthority());
  }
  
  private static boolean isMediaDocument(Uri uri) {
      return &quot;com.android.providers.media.documents&quot;.equals(uri.getAuthority());
  }
  
  
  private static boolean isGooglePhotosUri(Uri uri) {
      return &quot;com.google.android.apps.photos.content&quot;.equals(uri.getAuthority());
  }
  
  private static String getDataColumn(Context context, Uri uri, String selection,
                                      String[] selectionArgs) {
  
      Cursor cursor = null;
      final String column = &quot;_data&quot;;
      final String[] projection = {
              column
      };
  
      try {
          cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                  null);
          if (cursor != null &amp;&amp; cursor.moveToFirst()) {
              if (DEBUG)
                  DatabaseUtils.dumpCursor(cursor);
  
              final int column_index = cursor.getColumnIndexOrThrow(column);
              return cursor.getString(column_index);
          }
      } finally {
          if (cursor != null)
              cursor.close();
      }
      return null;
  }
  
  @RequiresApi(api = Build.VERSION_CODES.KITKAT)
  public static String getPath(final Context context, final Uri uri) {
  
      if (DEBUG)
          Log.d(TAG + &quot; File -&quot;,
                  &quot;Authority: &quot; + uri.getAuthority() +
                          &quot;, Fragment: &quot; + uri.getFragment() +
                          &quot;, Port: &quot; + uri.getPort() +
                          &quot;, Query: &quot; + uri.getQuery() +
                          &quot;, Scheme: &quot; + uri.getScheme() +
                          &quot;, Host: &quot; + uri.getHost() +
                          &quot;, Segments: &quot; + uri.getPathSegments().toString()
          );
  
      final boolean isKitKat = Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.KITKAT;
  
      // DocumentProvider
      if (isKitKat &amp;&amp; DocumentsContract.isDocumentUri(context, uri)) {
          if (isExternalStorageDocument(uri)) {
              final String docId = DocumentsContract.getDocumentId(uri);
              final String[] split = docId.split(&quot;:&quot;);
              final String type = split[0];
  
              if (&quot;primary&quot;.equalsIgnoreCase(type)) {
                  return Environment.getExternalStorageDirectory() + &quot;/&quot; + split[1];
              }
  
          }
          // DownloadsProvider
          else if (isDownloadsDocument(uri)) {
  
              final String id = DocumentsContract.getDocumentId(uri);
              final Uri contentUri = ContentUris.withAppendedId(
                      Uri.parse(&quot;content://downloads/public_downloads&quot;), Long.valueOf(id));
  
              return getDataColumn(context, contentUri, null, null);
          }
          // MediaProvider
          else if (isMediaDocument(uri)) {
              final String docId = DocumentsContract.getDocumentId(uri);
              final String[] split = docId.split(&quot;:&quot;);
              final String type = split[0];
  
              Uri contentUri = null;
              if (&quot;image&quot;.equals(type)) {
                  contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
              } else if (&quot;video&quot;.equals(type)) {
                  contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
              } else if (&quot;audio&quot;.equals(type)) {
                  contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
              }
  
              final String selection = &quot;_id=?&quot;;
              final String[] selectionArgs = new String[]{
                      split[1]
              };
  
              return getDataColumn(context, contentUri, selection, selectionArgs);
          }
      }
      // MediaStore (and general)
      else if (&quot;content&quot;.equalsIgnoreCase(uri.getScheme())) {
  
          // Return the remote address
          if (isGooglePhotosUri(uri))
              return uri.getLastPathSegment();
  
          return getDataColumn(context, uri, null, null);
      }
      // File
      else if (&quot;file&quot;.equalsIgnoreCase(uri.getScheme())) {
          return uri.getPath();
      }
  
      return null;
  }
  </code></pre>
  <p>I call it in my <code>MainActivity</code>, inside <code>onActivityResult</code>, after selecting a video from the device:</p>
  <pre><code>@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (requestCode == SELECT_VIDEO_REQUEST &amp;&amp; resultCode == RESULT_OK) {
  
          if (Build.VERSION.SDK_INT &gt;= 19) {
              
              //Calling FileUtils class
              String sourcePath = FileUtils.getPath(getApplicationContext(), data.getData());
            
              Intent intent = new Intent();
              intent.setClass(MainActivity.this, PlayerActivity.class);
              intent.putExtra(&quot;videoUri&quot;, sourcePath);
              startActivity(intent);
  
          } else {
              //Not relevant to the question
              .......
  
          }
      }
      if (requestCode == SELECT_VIDEO_REQUEST &amp;&amp; resultCode != RESULT_OK) {
          Toast.makeText(getApplicationContext(), &quot;Failed to select video&quot;, Toast.LENGTH_LONG).show();
      } else {
          super.onActivityResult(requestCode, resultCode, data);
      }
  
  
  }
  </code></pre>
  <p>In my <code>PlayerActivity</code> I get the <code>String</code> and try to parse the <code>Uri</code>, like this:</p>
  <pre><code>//Getting String from Intent
  mStringFilePath = getIntent().getStringExtra(&quot;videoUri&quot;);
  //Parse Uri from String
  mVideoUri = Uri.parse(mStringFilePath);
  </code></pre>
  <p>When testing on my device, I have no issues. I get the correct path and the <code>Uri.parse</code> works fine. But I see a lot of crashes on my Crashlytics saying - <code>nullpointerexception at line 59</code>, referring to <code>mVideoUri = Uri.parse(mStringFilePath);</code></p>
  <p>What am I doing wrong? Why is it working on my device and returning null on some other devices?</p>
  <h2>Edit 1</h2>
  <p>I forgot to add <code>&lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot; /&gt;</code> in my Manifest. I'm at a point where I atleast don't get a <code>nullpointerexception</code>, but I get the following -</p>
  <p><code>java.io.FileNotFoundException: Not found (No such file or directory)</code></p>
  <p>Somehow the <code>Uri</code> is incorrect when I select a file from my SD Card, any reason why?</p>