Directory for saving/accessing files in Android - android

I'm currently developing an app in Android Studio for Android TV on a mac. Ultimately I want to load local image files as card images in a VerticalGridFragment where a card id and an image filename have matching numbers. For the sake of prototyping, right now I'm just trying to set up best practices (as a complete novice) with a single 1.jpg file that will appear on every card.
I'm using the included Android TV emulator and assume I shouldn't attempt to use access or make use of any OSX file system. So my two questions are:
While I'm prototyping and trying to get 1.jpg to be the image for
each card, where should I place this file in a manner that I can
access using a file path string for internal storage, such as /root/1.jpg
which I can later change to /root/$.jpg where $ is a dynamic id
associated with each card. This needs to satisfy both the emulator
being able to access the file, a device being able to access the file when the app is finished, and me being able to place files there
from my host os while prototyping.
A follow-on question. When the app is finished I obviously won't be
relying on manually placing image files. Will the solution to the
above also provide a straightforward means of saving images to this
directory on a device?
Thanks.

Ok, I think I've got my head around this now:
Inside Android Studio, there's a Monitor utility in which there's a File Explorer. Using this, you can browse, and save to the directory structure that the emulator's using.
Most importantly, there is a standard assigned directory for apps to save and open from on internal storage. It can be found in the file browser at /data/data/com.applicationname/files/
From any app, it can be referenced for saving to or opening from using getFilesDir(), which answers question 2.

Related

How to create file on android using xamarin?

I've tried several folders but looks like no file is created.
External read & write permission have been enabled.
The code run without any sign of error. (as given below)
Here is the screenshot of the code inside mainactivity.cs (this is for testing purposes).
I also assume that since this is platform specific, the code must be in android project.
string filename = Path.Combine(Xamarin.Essentials.FileSystem.AppDataDirectory, "count1.txt") ;
StreamWriter sw = File.CreateText(filename);
sw.WriteLine("asad ini test");
sw.Close();enter code here
1b. I 'm using Android 6.0 phone, but I can't find such folder /data/user...
(I'm not sure if such folder is targeted special version of Android)
I search both internal /Android/myproject/files/ and found nothing
I search external SDcard /Android/myproject/files/ and still found nothing
(please look at the my android phone folders, i can't even find /data folder
Once, this is accomplished the next step would be how to call this function from the generalproject (non android, non IOS, non UWP project).
Example to write file given in xamarin document.
Where should this code reside? in general project folder ? or, android project folder?
The term "external" used in android is very misleading. It doesn't mean the external removable SD card rather some folders that don't require "root" permission. Therefore, initially I can't find the folder which I save a file into.
Another reason is each phone manufacture uses different name, hence it is very difficult to get an absolute address of an external removable SD Card.
More details is explained in blog_external_removable_SD_Card
You can't write to the removable SD Card
an old post here

Android Storage access framework

I am writing a file encryption app.
I set up the file(s) browse code using the default storage directory.
This works great, I wrote the code to be able to encrypt multiple files as well as directories.
Directories simply get copied, and the files within are encrypted into a new directory.
The problem is now after some research I have found that I need to utilize the storage access framework to be able to select files from external sd cards, and any other storage system the user may have.
My question is, is there a way to select multiple files and folders simultaneously through activities in the saf? Is there a workaround for this? I found an activity that is able to select multiple files, and I found one that allowed me to select a single directory.

Save files locally, but prevent them from showing up in the users file manager

Using PhoneGap 3.2 and the File API, I'm downloading a set of images to display in the app. I create a folder named "Appname" and put all the files there. On Android this folder is accessible through the file manager, and on some models the images show up in the users image gallery.
Is it possible to save files locally, but prevent them from showing up to the user outside of the app?
Technically, no. Especially if the client has root access.
You may try the followings to mitigate the problem:
a) Name your files to start with a DOT (.) so that it is recognized as hidden file. (Still, a file manager configured to show hidden files can show it).
b) Store the file instead on some databases in the /data/data/your.app.packages path, which is by default only accessible to your app. (Still a root user can see it).
c) A linux trick. Create a file, open it, hold the file descriptor but remove the file. In this way the file is removed from the directory structure so that it doesn't show up in the FS layer (and thus inaccessible). To make it permanent, use the file descriptor you hold to create a link (or dig into the /proc directory tree to make links with files under fd.
Since this trick works on linux, I guess it should work on Android. But it's probably overkill.
d) Other stopgaps include encryption, obfuscation, etc. But they don't exactly fall into the kind you are looking for.

how to access files in phone or SD card memory

hello guys i need small help in understanding file system of android
Now in windows for example we create files using paths like "c:/mytextfile.txt" or "c:/folder/mytextfile.txt".Now how can i access files and folders in android i mean whats the path like.
Does the phone support file browser instead of relying on third party apps??
Android does not have a native file browser, but there are numerous third-party ones (Astro comes to mind). The filesystem of Android is that of Linux; the path separator is / and the FS grows from a single root called /. So, you have your app packages under /data/apps, and so forth. Unless the phone is jailbroken ("rooted"), you won't get to see the whole filesystem - permissions get in the way. This applies to all Android applications, they are sandboxed - that is, they don't get access the whole filesystem. There are API calls to get the path to the current application's sandbox directory.

Best way to do a separate data install on Android

I want to decouple data from code on my Android application, and I am not sure of the best way to do that.
For instance - with the Linux Mahjongg game you can add new tiles to the game by dropping a specially formatted file into a specific directory. The Mahjongg game checks that directory when it starts up.
I want to do the same thing with my Android app - I want to be able to install the app, and then have separate installs for different data files. It's the data file installs that have me hung up. I do not want to have to set up my own server and write my own download code.
You can ship the data with the installer app, then use Input/Output Streams to copy the data from the assets or raw dirs.
Check this out:
Ship an application with a database
The answer has an implementation of in/outputstream. You don't need to use a db, just copy the file to ext storage.
One important detail: if you put the file in assets, it will be shipped compressed, and the phone/tab will try to uncompress the file in its entirety in memory. One (hocky) way to avoid that is to name the file .mp3. Assets in .mp3 format are not compressed. (Hey! I said it was hocky!)
The installer app can either uninstall itself by using ACTION_DELETE in an intent (see http://android.amberfog.com/?p=98 for details) or just show a msg to the user that it's safe to delete the data app.
HTH,
llappall
by dropping a specially formatted file into a specific directory
You can do that on external storage. Create a directory, and check it when your app starts up for new files. Tell the user they have to stick the magic files in the magic directory for it to work.

Categories

Resources