Accessing 'data/internal_memory' on Android phone - c#

Hi I bought a cheap Android phone to do app debugging on, and I would like to know how to access the internal memory folder, which is rejecting my advances.
When I first got the phone I downloaded some pictures from the internet using the browser. I also took a photo with the camera. They were stored in internal memory because I had not installed a SD card.
Then I installed an SD card, and downloaded some more images with the browser, which were stored on the SD card. Now when I look in the gallery there are different folders for the images on the SD card and the ones in internal memory.
I am writing a C# application using Xamarin to browse the pictures, but when I try to reach /data/internal_memory, I receive a permissions error. I can however access the folder using a file manager app (Easy Files Finder). I assume that this is because Easy Files Finder made me accept various permission exceptions before installation.
What do I have to do in my application to give me read access to the internal storage? Thanks for any advice!

As Google says:
"You can save files directly on the device's internal storage. By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user). When the user uninstalls your application, these files are removed."
But you can try this:
Call openFileInput() and pass it the name of the file to read. This returns a FileInputStream.
Read bytes from the file with read().
Then close the stream with close().
See this

Accessing internal memory may be restricted. I'd try searching here:
string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
To access files on the SD card use Android.OS.Environment.ExternalStorageDirectory.AbsolutePath.

Related

Path and file do not exist in C# mobile

I'm currently making a mobile app in Visual Studio C# Xamarin Forms and decided to use JSON for my data.
Workout workout = JsonConvert.DeserializeObject<Workout(File.ReadAllText("C:/Users/Agata/Desktop/data.json"));
And it couldn't find path to the JSON file and the file itself. I have checked my account status and it says that my account is administrator (well, it's only one account on PC). I have checked if my antivirus blocks the code, but it's still the same error:
System.IO.DirectoryNotFoundException: 'Could not find a part of the path "/C:/Users/Agata/Desktop/data.json".'
What should I try to check and what to do to not have such error in the future?
P.S - I have tried to change slashes like this
Workout workout = JsonConvert.DeserializeObject<Workout(File.ReadAllText("C:\\Users\\Agata\\Desktop\\data.json"));
and like this
Workout workout = JsonConvert.DeserializeObject<Workout(File.ReadAllText(#"C:/Users/Agata/Desktop/data.json"));
The file path in mobile is different to PC.
Android groups the filesystem into two different types of storage:
Internal Storage – this is a portion of the file system that can be
accessed only by the application or the operating system.
External Storage – this is a partition for the storage of files that
is accessible by all apps, the user, and possibly other devices. On
some devices, external storage may be removable (such as an SD card).
You can read this document for more information about android file system.
In iOS, there are also different Application directories.
You can also handling files in Xamarin.Forms and here is document and examples.

Can I create public/permanent files from Xamarin App?

I'm making an App where I need to create CSV files with data I need to load in a software in a Windows machine. I want to connect an Android Device via USB to a computer and get the file from there. Is there any way I can create a file that's visible for a computer?
From what I've found you can only create cache files and files only visible to the app (neither my PC or the File Manager on the phone can see them).
I thought about creating a service in the network and send the data to that and create the file in the server but that would add more failing points and of course is more work, besides sometimes the app could be running in parts where the Wifi doesn't get to it and would mean I would have to do a temporal file and somehow upload it when it connects back, so not practical at all.
Of course you can create files and folders on external storage of the android device, which is publicly accessible. Refer to this guide.
Note: You need to get permission WRITE_EXTERNAL_STORAGE to write and READ_EXTERNAL_STORAGE to read from device's external storage.

locations to save files which can be accessed on app

I want to supply a bunch of files with my Windows Phone 8.1 app which are necessary for running the application. I searched on the net and found that this page. But I don't know which place in particular is the ApplicationData.Current folder. What I want is the following:-
Can I create a folder called Resources or use the existing Assets folder in my Project tree and save the files in there.
If yes, then how can I access that folder from within my App i.e. how can I open and close files in that Directory(relative or absolute addressing format to be used)? If you can provide a one or two line code for this, it would be great.
Do I have to use the ReadTextAsync method to read the entire text of the file into a string or are there any other methods.(The System.IO.File.ReadAllText() method is not accessible when creating Windows 8.1 Phone app).
Thanks in advance.
Your App is installed on SD or Phone, depending on user Settings on the Phone. You can't normally access those files eg. by browsing files while Phone is connected to computer - the apps are Isolated.
Depending on your App:
if it's 8.1 Silverlight then you will find all the information here at MSDN.
if it's 8.1 RunTime then take a look here.
Although you can't access files inside your App from outside the App, from WP8.1 you have access (read/write) to SD Card and other KnownFolders.
EDIT - you can also access your files by using Uri schemes.

Fileupload into WP7 application

I just have a "short" Question. I did a lot of research the last few hours and found out, that a Wp7 application has access to his own directory and the IsolatedStorage. So if I want to work with a file in my application I either have to load it into the project using the Solutionexplorer in VS, or create a file manually by code, load it into the Isolated Storage and then read out of it.
So i come to the result that it isnt possible to load a specific file, which is in an unknown directory or folder and has an unknown name from my mobile Phone (or WP7 emulator) into the App directly, right? Because there is no browsing feature or something like e.g. in the ASP.NET Webform,the FileUploadControl.
Is my understanding correct or do I miss something?
you cannot access anything that is on the phone (except music and photo lib etc) other than whats included with the app and its isolated storage area.
you can't browse the local device like you can on windows. however you can download files from the net.

How to Play Video File On D Drive In WinRT?

Using XAML C# in Windows "Metro" Apps how do I go about playing a certain video file. Examples:
D:\video1.wmv
\\MEDIAPC\video2.wmv
The only way I managed to get this working so far is by using FilePicker, but I don't want to use this as I already have a list of files to play.
I have tried to use GetFileFromPathAsync but I keep getting permission / access issues
await StorageFile.GetFileFromPathAsync(#"D:\video1.wmv");
Apologies if this has been answered I just couldn't find an answer that fits my problem.
If your D:\ drive is a non-network resource try adding the Removable storage application capability. This can be accomplished by double-clicking on the Package.appxmanifest and navigating to the Capabilities tab. By default your application (assuming it is a Windows Store app) only has access to local files packaged with your app or files stored in local/roaming/temp folders (usually reserved for Application state).
If your data is stored on a Network resource that requires authentication you will want to enable the Enterprise Authentication capability.
You may also want to fiddle with the Home and Work Networks for the \MEDIAPC\ files if you aren't accessing resources that require network authentication.
Further Reads:
Accessing data and files
How to load data from files
App Capabilities Overview

Categories

Resources