1

I have a program which when ran, will copy all images from the connected iPhone to a folder in my documents. The problem I have is I want to make it compatible for android phones. I don't personally have one but I tried with my android tablet and it didn't work so I assume android phones wont work. Another thing to note is I got this from another post I made so I'm not 100% what every bit of code does. I thought changing the Manufacturer and Description to what it was on my tablet but that didn't work, would anyone be able to help? even try on their android phone themselves? I'm also aware it will only copy images that start with IMG which is what I want, even on android.

public partial class Frm_Main : Form
{
    public Frm_Main()
    {
        InitializeComponent();
    }

    public static class WiaCopy
    {
        public static IEnumerable<IDeviceInfo> GetAppleDevices()
        {
            return new DeviceManager().DeviceInfos.Cast<IDeviceInfo>().Where(di =>
                di.Type == WiaDeviceType.CameraDeviceType
                && di.Properties["Manufacturer"].get_Value().ToString() == "Apple Inc."
                && di.Properties["Description"].get_Value().ToString() == "Apple iPhone");
        }

        public static IEnumerable<Item> GetImgItems(IDeviceInfo deviceInfo)
        {
            var device = deviceInfo.Connect();
            return device.Items.Cast<Item>().Where(i => i.Properties["Item Name"].get_Value().ToString().StartsWith("IMG"));
        }

        public static void TransferJpgItem(Item item, string path)
        {
            var itemName = item.Properties["Item Name"].get_Value();
            if (!item.Formats.Cast<string>().Contains(FormatID.wiaFormatJPEG))
            {
                Console.WriteLine("Unexpected formats for item {0}, skipping.", itemName);
                return;
            }

            var targetName = itemName + ".jpg";
            Directory.CreateDirectory(path);
            ImageFile file = (ImageFile)item.Transfer(FormatID.wiaFormatJPEG);
            Console.WriteLine("Copying {0}", targetName);
            file.SaveFile(Path.Combine(path, targetName));
        }
    }

    private void Copy()
    {
        {
            try
            {
                var savePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "Documents");

                foreach (var iPhone in WiaCopy.GetAppleDevices())
                {
                    foreach (var imgItem in WiaCopy.GetImgItems(iPhone))
                    {
                        WiaCopy.TransferJpgItem(imgItem, Path.Combine(savePath, iPhone.Properties["Name"].get_Value().ToString()));
                    }
                }
            }
            catch { }
        }
    }
Yandy_Viera
  • 4,320
  • 4
  • 21
  • 42
Will
  • 23
  • 5
  • WIA = Windows Image Acquisition, the whole paradigm is wrong here and isn't a simple port. – Ron Beyer Aug 15 '15 at 02:02
  • i have got "using WIA;" at the top and i added the WIA library refrence. It does work though, just not with android – Will Aug 15 '15 at 02:06
  • Which *bit* isn't working? Can you get the Android devices with just return new DeviceManager().DeviceInfos.Cast().Where(di => di.Type == WiaDeviceType.CameraDeviceType) – Jim W Aug 15 '15 at 03:17
  • Also, "catch { }" is terrible! If there's an exception you won't know what it is, only that "it doesn't work". Exceptions are your friend, remove that empty catch and see if that's the problem. – Jim W Aug 15 '15 at 03:21
  • Im now sure how to test it, I'm not that experienced with programming but I know saving the images works fine as it does it for iPhone. I'll try removing the catch tomorrow because I'm in bed atm and see what happens there – Will Aug 15 '15 at 03:45
  • after some testing, foreach (var iPhone in WiaCopy.GetAppleDevices()) is the bit thats not working, its not even going into the forloop which means that i think the Getappledevices bit is wrong – Will Aug 15 '15 at 13:48
  • Have you tried it without the Manufacturer and Description conditions in the Where clause? – Jim W Aug 16 '15 at 03:24
  • i just tried leaving manufacturer and desc blank, taking both of them out completley and changing the camera device type to video, scanner and unspecified and nothing is working. Its difficult because im testing it on a tablet when i really need an acutal android phone but im not sure if it will make a difference – Will Aug 16 '15 at 13:30

1 Answers1

0

I can see nothing on the web indicating that WIA supports Android phones (nor iPhone for that matter).

I think you need an alternative approach, along the lines of

Read/write to a Samsung android phone/tablet from a C# windows app

Community
  • 1
  • 1
Jim W
  • 4,866
  • 1
  • 27
  • 43