Android Question Exposing non-media files to a connected PC

ac9ts

Active Member
Licensed User
Longtime User
My app writes various log files (zipped and text). I can see them on the device using the device file manager. I would like to see them when I connect the device to the PC.

For a different app where I wanted to expose media, I used the following:
B4X:
' Force the scan of the passed file so it is visible to a USB connected PC.
Public Sub ExposeToPC(Directory As String, FileName As String) As Object
 
    Dim context As JavaObject
    context = context.InitializeStatic("anywheresoftware.b4a.BA").GetField("applicationContext")
    Dim paths() As String = Array As String(File.Combine(Directory, FileName))
    Dim mediaScanner As JavaObject
    mediaScanner.InitializeStatic("android.media.MediaScannerConnection")
    Return mediaScanner.RunMethod("scanFile", Array As Object(context, paths, Null, Null))
 
End Sub

When I run this code for the text/zip files, the files are visible from the PC but they show a 0 byte length. When I copy them to the PC, they are still 0 bytes. When lloking at them on the device using the the device file manager, they are the correct size.

Question: Is there a equivalent scan method to expose non-media files to a USB connected PC?

Edit: An added note is that I'm trying to expose the file that is located on the SDCard. I create the file on internal storage and then copy it to the SDCard using the Storage class. Running the above code on the internal file exposes it with the correct size, etc. The SDCard file is the one I can't see correctly.
 
Last edited:

ac9ts

Active Member
Licensed User
Longtime User
I set the device to MTP mode when I plug it in and, as mentioned, I can see the files on the PC but they are 0 length. If I take the files and compress them with the device's file manager app (ES File Explorer), the zip file shows up on the PC at the correct length which leads me to believe there is some way to do it.
 
Upvote 0
Top