Writing files to an Android in C# - c#

I am writing a Windows Forms application in C#, and I want to copy files from a directory on my C:\ drive into the "Computer\SPH-D710\Phone\Music" directory on my Android phone. That music path I just copied and pasted from Windows Explorer to this post, but C# does not recognize it as a valid directory, probably because there is no "C:\" or the like.
What is a C# command that can write a file to an Android?

It appears your phone is connected as a MTP device (media transfer protocol). It is not as simple as a file system access (USB mass storage). Read these series of blogs on how to do it, its not a simple file copy.
https://learn.microsoft.com/en-us/archive/blogs/dimeby8/sending-mtp-commands-through-wpd-part-1-without-a-data-phase
https://learn.microsoft.com/en-us/archive/blogs/dimeby8/sending-mtp-commands-through-wpd-part-2-data-to-the-device
https://learn.microsoft.com/en-us/archive/blogs/dimeby8/sending-mtp-commands-through-wpd-part-3-data-from-device
Beware you will be diving into some unmanaged code for this.

The .NET libraries used to store files won't really care where they are saving the file. Your Android device is seen as a USB storage device (as long as USB storage is turned on from the phone's point of view!). I recommend that you put some of your C# code up so that we can potentially spot an error in the routine that you are running to actually save the file to the phone.
As a quick example - your C# code will likely want to look something like this:
string filePath = #"G:\Music\MySong.mp3";
System.IO.File.WriteAllBytes(filePath, mp3FileContent);

Related

Import external text file into Xamarin Forms application

I need to import a CSV file downloaded to a device into my Xamarin Forms application so that I can read the file contents, convert to Json and load into POCO objects and then send to SQLite database. My only question is how to select the file from the device file system for processing. I have looked at Gerald Versluis FilePicker Plugin for Xamarin and Windows. Is this my only choice for this process or is there something else available that I have not found?
Yes the the user needs to select the file from device storage, where ever that might be. The file picker plugin is what I decided to use as the plugin will let you select the file and read it into your app as a stream. Once you have the stream, you can pretty well do what ever you need.

Unity - Running Android app with 10000 small mp3 files

I am making a Unity dictionary app. It contains 10000 pronunciation mp3 files.
Every time the user selects one English word, it will automatically pronounce the words.
I can successfully install the apk file to my mobile phone. Unfortunately, it failed and stopped to run. It may be due to out of memory!
Total apk file size is around 65M, which is ok to me. What is the best way to handle 10000 mp3 files in my case?
Check out this article:
http://blog.theknightsofunity.com/wrong-import-settings-killing-unity-game-part-2/
Maybe setting Load Type to Streaming can help.
I believe keeping 10,000 media file in the app itself is not a good idea. As you said the APK size is 65MB it's very big for a simple app. I will recommend to keep those files in web and use URL in the app to download them at the beginning. after downloading save them to SD card or phone memory and access them from the storage location. It will not crash your app.

Simple SD card compatible database / NoSql solution for Windows Phone 8

Does anyone know of a good database or NoSql engine for Windows Phone 8 that can be used by my app?
I need to be able to open a read-only database file from the SD card. It needs to be able to cope with storing blobs (png images) as I want to use it to provide map tiles for offline use. 100,000's of image tiles will need to be stored in the database.
I've experimented with SQLite for Windows Phone via C# wrappers, but I don't seem to be able to get it to work with a database file located on the SD card.
There are limitations with Windows Phone apps accessing files located on an SD card, but it is possible:
http://msdn.microsoft.com/library/windowsphone/develop/jj720573%28v=vs.105%29.aspx
Feedback from a Microsoft employee regarding my difficulties with SQLite:
Windows Phone apps can read specific file types from the SD card using
the Microsoft.Phone.Storage APIs.
I expect that the SQLite implementation for the phone tries to open
the database using standard C file API rather than using the Storage
objects and so requires that the database be in the Xap or isolated
storage and cannot access a database on the SD card (this is
definitely the case for SQLite for Windows Store apps).
Feedback from SQLite SDK community:
Apparently it should be fairly straight forward to add support to the SQLite SDK for someone with some C++ skills (mine are a bit rusty!):
Replies:
http://www.mail-archive.com/sqlite-users#sqlite.org/msg81059.html
http://www.mail-archive.com/sqlite-users#sqlite.org/msg81060.html
To my original question:
http://www.mail-archive.com/sqlite-users#sqlite.org/msg81055.html
From your comments, it sounds like a very different approach would work better.
Your requirements seem to be that the end user is the one responsible for putting the data on the card using their desktop/laptop. Then plugging the card into the phone.
If that's the case then it seems the best solution would be to provide a regular desktop app that grabs the images in a zip file then performs an unzip operation onto the destination card. Essentially, the app takes care of the operation.
If you need any meta data about those images, then a json or xml file should be included.
This should be far simpler than dealing with a database on a read only SD card.
The solution that worked for me was to take OpenMCDF and adapt it to work on Windows Phone 8. I've made the adapted OpenMCDF-wp8 solution available on GitHub: https://github.com/gavinharriss/OpenMCDF-wp8
I've also made my workaround to the Windows Phone 8 bug that prevents Seek() from working correctly with the Stream returned from the ExternalStorageFile class: https://github.com/gavinharriss/ExternalStorageFileWrapper-wp8

Playing an MP4 in a zip file through a network location

I'm building a video system, and have came across a problem of accessing a video held in a remote location. Now predicament is that I don't want to mess around with the zip file by extracting the data, this would take too long from a user perspective and would rather be able to open video file directly from within side the zip. My question is, is this possible? The ability to open a file is not something I've found within the DotNetZip library.
The only solution I've found is pointing VideoLAN at the zip file and playing it from there. However, doing this programmatically is something I'm massively struggling with, through the VideoLan DotNet for WinForm & WPF C# plugin and it's lack of examples. Just wondering is there any alternative means?
Why dont you use the VLC ActiveX Directly ,just import the AxVlc.dll to you're project ,than you can select the VLC Plugin from Toolbox in VS (VLC Plugin v2 prefered).
Than you can do something vlc.playlist.add("FileName",Null,""); than use vlc.playlist.play(); version's under 0.9.9 works with Loop ,new version's you should build the Loop Function by you're self.
What's the reason of compressing video files? They are already compressed, and far better than zip can do.

WP7 -- finding isolatedStorage files on my computer

I am trying to use the C# class IsolatedStorageFile to write some data to a file in my app. This is using the simulator. I would like to look on my computer to see if it worked (i.e., look at the file in notepad). Where can I find that file?
The Isolated Storage is stored in the emulator, which is a virtual machine, and not directly on your harddrive. You'll have to code your own file viewer (e.g. from within your app, load the file from Isolated Storage and display the text using StreamReader).
I vaguely remember that the Mango toolkit (out in May) features an IsolatedStorage viewer built into the emulator, but I'm not sure what features it has.
You might be interested in this blog post. It explains how to export your file to your desktop.
You can download IsolatedStorageExplorer And use it to download file from IsolatedStorage to Computer.
Check out this Post and Answer given by Matt Lacey

Categories