Search code examples
c#androidmobileconnectionmtp

Recognize internal storage of portable device through MTP in C#


I'm trying to develop winform(C#) application to search file from connected portable device(mobile device) using MTP.

I can get connected or disconnected status from wndproc method using WM_DEVICECHANGE. But what I really want to develop is to cause an event when internal storage is created (it is able to read on window) after the deivce is connected from MTP.

So I was trying to create wndProc and input the code below in this code "if (m.Msg == UsbAlert.WM_DEVICECHANGE){ ... }"

         if (devType == UsbAlert.DBT_DEVTUP_VOLUME)
            {
                Console.WriteLine("DBT DEVTUP VOLUME");
                DEV_BROADCAST_VOLUME vol;
                vol = (DEV_BROADCAST_VOLUME)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_VOLUME));
                Console.WriteLine(vol.dbcv_unitmask);
            }

But it is only can operate portable device such as USB not a mobile phone (android, ios) There are so many codes for connecting device to windows but not for mobile phone. Please let me know how can set an event when internal storage is ready to scan on windows. Can I use WndProc function to develop this or not.

Thank you.


Solution

  • I just solved by myself not using the WM_DEVTUP_VOLUME using wnd_proc fuctions.

    This article make me solved the problem below. How to get MTP device Available Storage & Storage Capacity using C#?

    You can get storage voulme using WPD lib from windows.