Android Question Camera Intent triggers OK/Retry on phone, but returns an empty/0-byte image file on Android 14+ (TargetSDK 36)

actarus63

Member
Licensed User
Longtime User
Hi Erel and community,I am building a classic, standard Activity-based contact app (FullScreen = True, TargetSDK 36) on a real device running modern Android.The app generates dynamic contact panels inside a ScrollView. When clicking a custom "PHOTO" button, an asynchronous dialog asks the user to choose between the Gallery or the Camera. The Gallery works perfectly, but the Camera fails to return the image.The behavior:When choosing the Camera, the native camera app opens successfully. I can snap the photo, and the camera interface shows the standard "Retry / OK" confirmation checkmarks. However, when I press "OK", the camera closes, I return to my app, but the image file on disk is completely empty (0 bytes) and the ImageView remains gray/blank.I have already requested and granted Runtime Camera Permissions. My Manifest Editor contains the following standard setup for AndroidX:
Inside my code, I tried creating an empty file beforehand and passing its secure URI via iCamera.PutExtra("output", UriSicuro). I tried initializing this temp file both in rp.GetSafeDirDefaultExternal("") and File.DirInternal, launching the intent via startActivityForResult through a JavaObject context, and catching the response inside Sub Activity_Result.The camera launches without crashing, but the file size remains 0 when returning to the activity, so LoadBitmapSample cannot render anything.What is the official, correct way on TargetSDK 36 to force the external camera app to write the full-resolution image into our secure app directories without it being blocked by Android's strict background file-sharing policies? Should I strictly migrate to CameraClass v2 or B4XPages, or is there a specific way to handle the output URI for the camera intent in standard Activities?Thank you very much for your time and guidance!

Ciao Erel e community, sto sviluppando una classica app di contatti basata su Activity (FullScreen = True, TargetSDK 36) su un dispositivo reale con Android moderno. L'app genera pannelli di contatti dinamici all'interno di una ScrollView. Quando si fa clic su un pulsante "FOTO" personalizzato, una finestra di dialogo asincrona chiede all'utente di scegliere tra Galleria o Fotocamera. La Galleria funziona perfettamente, ma la Fotocamera non riesce a restituire l'immagine. Il comportamento è il seguente: quando scelgo la Fotocamera, l'app nativa si apre correttamente. Posso scattare la foto e l'interfaccia della fotocamera mostra i segni di spunta di conferma standard "Riprova / OK". Tuttavia, quando premo "OK", la fotocamera si chiude, torno alla mia app, ma il file immagine su disco è completamente vuoto (0 byte) e l'ImageView rimane grigia/vuota. Ho già richiesto e concesso le autorizzazioni per la fotocamera in fase di esecuzione. Il mio Manifest Editor contiene la seguente configurazione standard per AndroidX:
Nel mio codice, ho provato a creare un file vuoto in anticipo e a passare il suo URI sicuro tramite iCamera.PutExtra("output", UriSicuro). Ho provato a inizializzare questo file temporaneo sia in rp.GetSafeDirDefaultExternal("") che in File.DirInternal, avviando l'intent tramite startActivityForResult attraverso un contesto JavaObject e intercettando la risposta all'interno di Sub Activity_Result. La fotocamera si avvia senza crash, ma la dimensione del file rimane 0 quando si torna all'activity, quindi LoadBitmapSample non può renderizzare nulla. Qual è il modo ufficiale e corretto su TargetSDK 36 per forzare l'app della fotocamera esterna a scrivere l'immagine a piena risoluzione nelle nostre directory sicure dell'app senza che venga bloccata dalle rigide policy di condivisione file in background di Android? Dovrei migrare rigorosamente a CameraClass v2 o B4XPages, oppure esiste un modo specifico per gestire l'URI di output per l'intent della fotocamera nelle Activity standard? Grazie mille per il vostro tempo e la vostra guida!
 
Good morning, Teddy Bear, I tried your code, but nothing happens yet. The problem persists, which is that the camera opens; it takes a photo, but when I press OK to confirm the photo, it doesn't save. Any other ideas? I'll post the screenshots.
 

Attachments

  • 1787998373790.png
    1787998373790.png
    20.4 KB · Views: 124
  • 1787998459931.png
    1787998459931.png
    67.4 KB · Views: 122
  • 1787998498872.png
    1787998498872.png
    17.3 KB · Views: 124
Upvote 0
Good morning, Teddy Bear, I tried your code, but nothing happens yet. The problem persists, which is that the camera opens; it takes a photo, but when I press OK to confirm the photo, it doesn't save. Any other ideas? I'll post the screenshots.
Did you try this example?
 
Upvote 0
I mean this


Code: Copy
Try
        
        For Each Permission As String In Array(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION, _
            Starter.rp.PERMISSION_RECORD_AUDIO, _
            Starter.rp.PERMISSION_CAMERA)
            
            Starter.rp.CheckAndRequest(Permission)
            
            Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
            
            If Result = False Then
                ToastMessageShow("No permission! " & Permission, True)
                            
                Log("No permission! " & Permission)
                MsgboxAsync("Please allow " & Permission & CRLF &"Application will be closed","HCMS")
                Wait For msgbox_result(Res1 As Int)
                
                modFun.ExitApp
                Return
                
            End If
        Next
 
Upvote 0
I mean this


Code: Copy
Try
    
        For Each Permission As String In Array(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION, _
            Starter.rp.PERMISSION_RECORD_AUDIO, _
            Starter.rp.PERMISSION_CAMERA)
        
            Starter.rp.CheckAndRequest(Permission)
        
            Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        
            If Result = False Then
                ToastMessageShow("No permission! " & Permission, True)
                        
                Log("No permission! " & Permission)
                MsgboxAsync("Please allow " & Permission & CRLF &"Application will be closed","HCMS")
                Wait For msgbox_result(Res1 As Int)
            
                modFun.ExitApp
                Return
            
            End If
        Next
It is simple to use and doesn't require any permission (*), you don't need to do anythting in Starter module. See the tutorial by Erel
 
Upvote 0
Back
Top