Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Files that I write to the sdcard do not show in Windows explorer, for Acer Iconiatab

Tags:

android

In my application, I create files and write them to the Sdcard. My created files show properly in DDMS, and in windows explorer when I mount my Samsung Galaxy as a USB device. But, they do not show in Windows explorer on my Acer Iconia Tab A500, when it is connected by USB. I assume this is due to some difference in 3.0? Do I need to create my files differently in 3.0 so that they show in Windows by usb?

like image 490
ab11 Avatar asked Jun 24 '11 13:06

ab11


People also ask

Why is my SD card not showing up in file explorer?

s know some of the common causes of SD card reader not showing up in File Explorer: Your SD card reader may be physically damaged. Laptop USB port or cable is not working. SD card reader is not properly connected to PC.

How do I view Android files on PC?

With a USB cable, connect your phone to your computer. On your phone, tap the "Charging this device via USB" notification. Under "Use USB for," select File Transfer. A file transfer window will open on your computer.

How do I access file manager on Android from PC?

To work with a device's file system, proceed as follows: Click View > Tool Windows > Device File Explorer or click the Device File Explorer button in the tool window bar to open the Device File Explorer. Select a device from the drop down list. Interact with the device content in the file explorer window.


3 Answers

Sending this intent after writing the file solved the issue. Credit goes to Commons Guy, he provided the answer on another forum.

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"
            + Environment.getExternalStorageDirectory()))); 

Edit: Commons Guy did comment that sending a fake intent (like above) is probably a bad idea, so I used this instead:

   //called after writing file, from my activity 
    new SingleMediaScanner(this, path); 

    private class SingleMediaScanner implements MediaScannerConnectionClient 
    { 
            private MediaScannerConnection mMs; 
            private String path; 
            SingleMediaScanner(Context context, String f) 
            { 
                mPath = f; 
                mMs = new MediaScannerConnection(context, this); 
                mMs.connect(); 
            } 
            @Override 
            public void onMediaScannerConnected() 
            { 
                mMs.scanFile(mFile, null); 
            } 
            @Override 
            public void onScanCompleted(String path, Uri uri) 
            { 
                mMs.disconnect(); 
            } 
        }
like image 66
ab11 Avatar answered Nov 15 '22 17:11

ab11


On my Acer Iconia Tab, getExternalStorageDirectory actually points to an internal storage (considered as "shared", as opposed to the "private" inner storage), and is mounted as /mnt/sdcard. There is an alternative (and "true") external storage that goes on the SDcard at /mnt/external_sd. I'm not sure if there currently is a perfect method to get that path, though. Do you know which partition is mounted when you connect your Iconia Tab by USB ?

like image 34
Gregory Avatar answered Nov 15 '22 17:11

Gregory


Also found this problem on a Nexus 7. If you device connects to your PC with MTP (the preferred USB connection protocol post honeycomb), when you create a file, the media scanner needs to be updated for it to be immediately visible in Windows Explorer.

Some devices update the media scanner automatically (Samsung S4), some do not (Nexus 7). After creating the new file on the SD card, to make sure the media scanner is updated make the following call.

File file= new File(FullPathAndFileNameToYourNewFile);
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(file));
sendBroadcast(intent);

Here is a really good post on the topic. Thanks go to the author for the explanation and code above. https://www.grokkingandroid.com/adding-files-to-androids-media-library-using-the-mediascanner/

like image 28
Marky0 Avatar answered Nov 15 '22 18:11

Marky0