When selecting media from external storage (SD Card) on a device running SDK 19+ I was receiving a null reference. It appears the ("primary".equalsIgnoreCase(type)) was never met and would just return "". I added an else case to handle this with the getExternalMediaDirs() call.
Fix for SDK 26+
When selecting media from internal storage Long.valueOf(id) would crash NumberFormatException since the id is a URI. This was changed on Android 26+. I added a check for "raw" and return the URI directly in that case.
Fix for SDK 19+
Fix for SDK 26+