UWP C# removable drive added and ready

248 views Asked by At

I'm developing a UWP C# app witch used device detection (PortableStorageDevice). I'm using the code from official sample (scenario 2), creating a DeviceWatcher and subscribing events Added, Updated and Removed.

It works, but there is one problem I don't know how to solve, I need it works with devices like an ereader and smartphone. When I connect the ereader, the Added event is fired but in the device appears a dialog asking user to connect with computer to use storage.

When user accept the dialog, removable drive appears at My Computer (as connected in that moment), but no events get fired in my UWP app when that happens and I don't know if really the drive is connected or no. Because the user can accept this dialog maybe one hour later or reject it.

How could I get notified when the removable drive is really connected (to read files)?

I'm using this code:

DeviceWatcher deviceWatcher = DeviceInformation.CreateWatcher(DeviceClass.PortableStorageDevice);
deviceWatcher.Added += DeviceWatcher_Added;
deviceWatcher.Updated += DeviceWatcher_Updated;
deviceWatcher.Removed += DeviceWatcher_Removed;
deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted;
0

There are 0 answers