Arti
Arti

Reputation: 3071

Folder and files added in android not visible via USB

I have seen many posts with similar issue as mine, but could not find solution for it. Hence I am posting the question specific my configurations.

I am developing a Xamarin android application which is supposed to create folder structure and files as show below:

Folder structure

The Test Folder would have mp3 files.

mp3 files

I want the user to be able to view all the files located under AppnName folder ie. abc.xml files and all the mp3 files inside test Folder

Here is my code:

var dir = new Java.IO.File(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/AppName/TestFolder");
if (!dir.Exists())
    dir.Mkdirs();

The above code works, it creates the folder structure, I could view all files from ES File Expolrer on my android device but once I connect the device to windows PC I can not view any of the files and folder.

I did some r&d and tries some of the solutions, but that did't help. I tried using media scan to scan the files as per the solution given here :https://stackoverflow.com/a/19934089/1650891. But it is not working for me.

Any help would be appreciated. Thanks in advance.

Upvotes: 1

Views: 1845

Answers (1)

Arti
Arti

Reputation: 3071

I have managed to get it working. The trick here is to scan every new file created in the that directory. Every time I create a new file I follow it with below line of code.

MediaScannerConnection.ScanFile(Android.App.Application.Context, new String[] { path }, null, null);

Upvotes: 2

Related Questions