Opening a file without knowing the name - android

In my application I am using a timestamp as my filename when I save it to a folder on my device.I know want to access one of these files from my application but I'm not sure how to open a file that you don't know the name of. They are all of the same file type so my question is how can this be done?

You probably want to save to a particular directory that only contains your timestamped files and nothing else. You can use the File.listFiles API to get an array of Files in your directory, you can then check each of the filenames to find the appropriate one (e.g. most recent timestamp).

You have to provide the name of file.Otherwise it would be like saying to JVM "do this?" without the idea of what to do?

Related

How to determine the WhatsApp file name format for pictures?

Premise: I am using WhatsApp on Android.
Why I am asking this
I am trying to create a script that, when configured with proper arguments, would restore accidentally deleted pictures in a WhatsApp chat, if you have a copy of those files somewhere else (with potentially different file names) and you pass them to the script.
What happens when you delete an image
Normally, if you accidentally delete the image files, WhatsApp still shows you a thumbnail, but if you click on it the following pop-up appears.
Therefore, I guess it looks for a filename in the storage and it tries to load that file.
I verified this
I tested this by manually replacing an image in the "WhatsApp Images" folder with another image, and the new image shows up in the corresponding chat as expected, so this is right.
But when I did that test, I knew the file name because I manually watched the file previews using a file manager and I identified the right file, so that was easy.
So the problem is
What about deleted files? how can I try to guess the corresponding file names in order to place the file copy back where it is supposed to be?
What I already know
First of all, I know the file names have this format:
IMG-yyyymmdd-WAxxxx.jpg
Where yyyymmmmdd is a date and xxxx is a sort of sequence number.
I also know that the mapping from thumbnails to actual files is stored in the msgstore.db database file, but it can only be accessed if you have root privileges. Do you think is there any other way to predict what the file name can be without accessing that DB?

In terms of usability, what is the best way to export a file?

I have an android app which allows the user to gather research data. I want to export the gathered data as an excel file. So the user can work with the data on a desktop computer.
The question is, what is the best way in terms of usability to offer file export to the user?
On idea was to start the email client with the excel file as attachment. But if you have to send this email to yourself just to get the files seem kind of a workaround.
The second idea is to store the file in the android file system. But is there a commen folder for something like that? Like the "Documents" folder in windows? I dont want the user to search too long for his file. And is this really best practice?
The common way, is using the shared intent system and allowing the user to pick which app "he" or "she" wants to use to share the file. You can also save it to the android file system just as easily. There is no common folder which everyone should use. But if you want ease of accessibility for the file, create a new sub-directory under the top-level directory on the device. Use this method to get a reference to the top-level, Environment.getExternalStorageDirectory(). You must have the android.permission.WRITE_EXTERNAL_STORAGE permission declared in your app Manifest. The sub-directory name should be something obvious to that user that the data inside belongs to your app. Furthermore, display a toast that indicates to the user where the file is stored to make it even easier for them.

Cordova/Phonegap - Where do I put a data file I want to read?

I've been driving myself crazy trying to find the answer to a seemingly easy question.
I am trying to create my first app using Cordova. I want to bundle a text file with my app that can be read when the app starts up.
Where do I put this file?
dataDirectory seems like a good place, but where is it? Documentation says /data/data/<app-id>/files but where are those data directories? Do I create them?
Update 1: Ok, I think I've figured out that dataDirectory should be pretty much just where the path says it should be, at the root of the file system. But the directory doesn't appear to be created automatically and I don't know how to package a file - a JSON file, for instance - and place it in that directory.
Essentially you do not need to create these directories. Those are created once your app is installed by the Android itself.
A typical way to get this done would be that you could first off add those files in your app's assets directory and then at runtime you can copy those file wherever you want.
There is a repository on Githup which provide a similar functionality.

Save App file to default folder

Well, I tried to search in google and SO, but didn't find much mainly because I am not sure what should be my search word. So, if anybody thinks this question is too generic and should be searched first, please help me providing some useful link.
What I want is, to have two buttons in my App which should download sample.csv and sample.php (I want to attach this file inside my App) file and save it to user directory, preferably in "download" folder or somewhere user can access easily.
I found this page by searching but here they demonstrates saving File on Internal Storage in App's folder only. Now I am confused whether this App's folder is accessible by browsing or not (I can't find my app's folder in my Samsung Note 2).
Another question pops up in my mind is, whether I have to read those sample files and create new file to save, or I can simply put a link and download the sample files I provided (more like HTML link)? Or may be I can just upload those sample files in my web server as zipped and give a link to dload?
Apology for my long email, but I am confused where to start.
Thanks,
You can not access your app's internal directory. However, what you can do is to use InputOutputStream to copy your file from the internal directory to your desired folder, and then delete the file from the app's directory. Try searching for copying files and you'll find multiple links.

what kind of file should i use in android to reference information that i stored?

I have created an android app that calculates the numerical values of word, and gives you a list of other words with the same numerical value. The way I have been doing it, is storring the words and value in a .properties file. Ie. A line from a .proprties file called "myWords" will have something like: 61=you, then I just use a get() method to call it,
ie. String myString = ResourseBundle.get("myWords").get("61"); would return the string "you". Is there a better way to do this? My guess is that this is not the proper use of a .properties file, and I was wondering if there was another way to do this correctly. I want to include the file in assets folder of the app, and from my limited understanding of sqlite, you can create a file within android, but you can't just include a file in the assets folder, and then read it. So that said, is there some other type of file that I should use, or was I wrong about sqlite, or is the .properties file being used correctly?
SQLite is your best bet and is the best way to handle your data on an Android phone, that is why Google bundled it on Android in the first place, to avoid people the pain of dealing with files.
If you follow this Tutorial they will show you how to create your database in your computer and then load it up on your "assets" folder and access it from your Android application.
Hope that helps!
You can use a csv file, read it from the assets folder each time the app starts or only once after installation and then store the values in a database.
Take a look at my answer here on how to read the files included in your app (you would use a csv file instead of a libray, but it's still reading files): Hosting an executable within Android application
Edit: here's another example to read from the assets folder: Image uploaded from the android app space seems corrupted
You can try out database option. Here is an interesting tutorial on how to pre-populate a database and then ship it out in the APK.

Categories

Resources