'Android - data is zero on physical device but not in emulator SKD 31

On my emulator, result.getData() is NOT null. On my real device, result.getData() is NULL and doesn't jump into the iff branch. Why can that be? My Emulatro runs with SDK 31. My physical device has Android 12 with also SKD 31.

      File file;

       if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.Q)
                {
          file = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES),UUID.randomUUID()+".jpg");
                }
       else{
          file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+UUID.randomUUID()+".jpg");

                }
                
       outputFileUri = FileProvider.getUriForFile(getApplicationContext(),BuildConfig.APPLICATION_ID + ".fileprovider",file);
       Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
       intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);

       startActivityIntent.launch(intent);




   ActivityResultLauncher<Intent> startActivityIntent = registerForActivityResult(
        new ActivityResultContracts.StartActivityForResult(),
        new ActivityResultCallback<ActivityResult>() {
            @Override
            public void onActivityResult(ActivityResult result) {
                int resultCode = result.getResultCode();
                if(result.getResultCode() == Activity.RESULT_OK)
                {
                    if(result.getData() != null)

                    {
                        Log.e("FILE : ", outputFileUri.toString());

                        Intent intent = new Intent(MainActivity.this,AddNewPlace.class);
                        intent.putExtra("File",outputFileUri.toString());

                        startActivity(intent);
                    }
                }

            }
        });


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source