I am trying to use the MediaDevices library to download files from my phone. I am able to see the files on my phone, but MediaDevice.DownloadFile() throws a NotImplemented exception. I've got version 1.8.0 of the library. Here is my program:
using System;
using System.Diagnostics;
using System.IO;
using MediaDevices;
namespace ReadPhoneFile
{
class Program
{
static MediaDevice thePhone;
static void Main(string[] args)
{
var devices = MediaDevice.GetDevices();
foreach (MediaDevice device in devices)
{
try
{
thePhone = device;
device.Connect();
DownloadFiles(device, "e:/pictures/Rob's Test Phone/Lightroom");
device.Disconnect();
}
catch
{
// If it can't be read, don't worry.
}
}
Console.WriteLine("Press any key.");
Console.ReadKey();
}
static void DownloadFiles(MediaDevice device, string pcFolder)
{
var lightroomDir = device.GetDirectoryInfo(@"Phone\Android\data\com.adobe.lrmobile\files\carouselDocuments\a6f0275ee0b94c90b3c05f093250d4ef\Originals");
// ProcessLightroomFolder(photoDir, pcFolder, false);
foreach (MediaDirectoryInfo subFolder in lightroomDir.EnumerateDirectories())
{
ProcessLightroomFolder(subFolder, pcFolder, true);
}
}
static void ProcessLightroomFolder(MediaDirectoryInfo folder, string pcFolder, bool createFolder)
{
Console.WriteLine($"Processing folder {folder.Name} into folder {pcFolder}");
string pcSubFolder = $"{pcFolder}/{folder.Name}";
if (createFolder)
{
Directory.CreateDirectory(pcSubFolder);
}
foreach (MediaFileInfo file in folder.EnumerateFiles())
{
ProcessLightroomFile(file, pcSubFolder);
}
foreach (MediaDirectoryInfo subFolder in folder.EnumerateDirectories())
{
ProcessLightroomFolder(subFolder, pcSubFolder, true);
}
}
static void ProcessLightroomFile(MediaFileInfo file, string pcFolder)
{
Console.WriteLine($"Processing Lightroom file {file.Name} into folder {pcFolder}");
DownloadFile(file, pcFolder);
}
static void DownloadFile(MediaFileInfo phoneFile, string destinationFolder)
{
try
{
MemoryStream memoryStream = new System.IO.MemoryStream();
thePhone.DownloadFile(phoneFile.FullName, "c:/misc/downloadedFile.dng");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
there is an issue raised on github to solve this problem (https://github.com/Bassman2/MediaDevices/issues/32). The problem is that you are building your app on top of .NET Core 3.1, and this lib works well on .NET Framework 4.* as they warn when you build your project:
Package 'MediaDevices 1.8.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project