Q: Attaching files and uploading to server - Android Nougat I am trying to upload files to server from my application. The user is allowed to attach the file from his internal storage. But some how the path I get from a Nougat phone is different from the standard /storage/emulated/0/... . in few phones I get external_files/... and in others I get root_files/storage/999/.... . In this case I am not getting the right path of the file. How do we handle this scenario? 
My code :
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        Uri selectedImageUri = data.getData();
        String filePath = data.getData().getPath();
        File sourceFile = new File(fileFields.get(i).getFileName());
        FileInputStream fileInputStream = new FileInputStream(sourceFile);
    }
} 


A: A Uri is not a file. getPath() is meaningless unless the scheme of the Uri happens to be file. That will not be very common on newer Android devices. Instead, the scheme will be content, and getPath() will be useless to you.
Instead, for both file and content Uri values, use a ContentResolver and openInputStream() to get an InputStream on the content identified by the Uri. This approach works all the way back to Android 1.0.
