Saving files to external storage, custom directory. - Java for Android App Development

Hey all -
Have a question.
I want to call the Camera intent, but have the camera save to a custom file.
I've read this: https://developer.android.com/training/data-storage/files#WriteExternalStorage
And the only two options it gives is 'Save to a public directory" (like \Pictures, \Ringtones, etc), or "Save to a Provate Directory".
The latter sounds like it's what I want to do - but mentioned 'getExternalFilesDir()' function retrieves my application's custom data directory (which is (1)removed when the app is uninstalled, and (2)difficult to find when the phone is plugged into a computer - to copy the saved files from.)
What I'd REALLY wanna do is save my files to a root directory in the external storage. (Like, "/<sdcard mount path>/PicLogger/<file>").
Anyone know of a guide, or examples that show how to save images through the camera into a custom directory like this?
Thanks!
-Mike

You can save the file wherever you want, given that you have permission to write to SD card, by passing the file URI as MediaStore.EXTRA_OUTPUT in the MediaStore.ACTION_IMAGE_CAPTURE intent. See Save the full-size photo.
That being said, you should prefer something like "DCIM/YourAppName" or "Pictures/YourAppName", which apps like Google PhotoScan etc have been doing.
Code:
new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "YourAppName")
Apps should not create their own directories directly under the SD card root directory, and if they want to make something visible to user, it should be under one of the standard directories, preferrably under a subdirectory named after your app.
Or if you want to support scoped storage since Q, you can check out this SO answer.

Related

[Help] Apps

For applications.. where do i put it? and like applications like showing the batterybar etc... where do i put those? (just to put this in here i'm only 14... so.. don't use such big words..)
Generally you can put them anywhere. When you download an app, it is generally a .cab file, transfer this to you phone or storage card (not really important where, but I have a folder on my storage card called "cabs") and remember where you put it.
On the phone, use Flie Explorer to navigate to where you saved your cab file and tap on the cab... this will start the instal process. You will be given a choice of where you want to instal the app (phone or storage card), unless there are specific instructions to instal it to a certain area, the choice is yours. That's it, the app/program should be available in you programs list.

[Q]Intent to launch a file manager

I've been banging my head on this, but can't seem to get it to work.
I'm trying to launch a file manager from my app. Here's the code I'm using.. I think (thought) it was correct, but I'm missing something. I want it to pop up a list of available file managers to open to that path.
Code:
Url = "file:///sdcard/";
Intent fileMangerIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Url));
startActivity(fileMangerIntent);
Thanks.
Edit: I've tried just passing /sdcard as the path, and also with and without the trailing slash. I've tried with an http url and it works as intended.
try using ACTION_CHOOSER, it should display all the activities on the phone that can handle that type of URI. http://developer.android.com/reference/android/content/Intent.html#ACTION_CHOOSER
Thanks.. I'll try that..
Doesn't seem to do what I'm trying to get it to do. If I specify a file and a mimetype (ie. a jpeg), then it works to popup a list of apps to view the file.
And with AndExplorer, I can have it popup as a file chooser or directory chooser.
But what i'm trying to is just launch a file explorer at the given path. Don't need any information back.
What I'm working on is an app that lists all attached usb drives (on HC Tablets) and allows mounting/unmounting any/all devices of ext, fat, ntfs. And I want to be able to click the mount points in my app to switch to a file explorer to browse the files.
But it doesn't seem like any of the file managers handle that. I might have to build in a minimal file manager.
If the file browsers you are trying to incorporate into your app dont support an entry point that takes you straight to a directory then it'll be hard to make this work. I guess the best you can do is look at the published intents and see if there is a way to pass a directory.
From something awesome

[Q] Hide From Gallery

I have created a folder on my external sd card named Movies.
I use Moboplayer, and have pre-set it to only view that folder when opened. But, after viewing any of the files in the sd card folder, the folder and files are displayed in Gallery. How can I prevent that from happening?
Or, put another way, I want to store some video files on my external sd card
and want to be the only one who is able to view them?
create a file in that directory called .nomedia that will prevent it being scanned by Gallery
Thanks, I'll try that later today and report back.
gunnyman said:
create a file in that directory called .nomedia that will prevent it being scanned by Gallery
Click to expand...
Click to collapse
As a beginner with Android, I'm not sure I know how to do what you said to do.
Can you please tell me the easiest way to create that file? Thanks again.
Sure. Open an adb shell. Change to the directory you want the file in. Type "touch .nomedia "
Press enter
Sent from my Desire HD using XDA Premium App
As an Android beginner, I have no idea what or how to use and adb shell.
Does it require that the Tab be Rooted?
Can I use a file manager like Astro?
Can I open the folder on my win xp desktop and create the file om the sd card with windows explorer?
Sorry to be so dense here, but, I am trying to learn what to do.
jostarr said:
As an Android beginner, I have no idea what or how to use and adb shell.
Does it require that the Tab be Rooted?
Can I use a file manager like Astro?
Can I open the folder on my win xp desktop and create the file om the sd card with windows explorer?
Sorry to be so dense here, but, I am trying to learn what to do.
Click to expand...
Click to collapse
Get the free ES File Explorer from the store. You can do all the MS Windows-esque file management with that.
What is going to prevent someone else from launching Mobo and seeing the same files that you do?
I do have ES File Explorer installed, and didn't find a way to create a new file in that folder. Can you please suggest what to do when I get to the folder in question? Thanks.
As for your question about others using Mobo, is there a way to password protect a give app?
jostarr said:
I do have ES File Explorer installed, and didn't find a way to create a new file in that folder. Can you please suggest what to do when I get to the folder in question? Thanks.
As for your question about others using Mobo, is there a way to password protect a give app?
Click to expand...
Click to collapse
Ok, es 101: the key to finding everything is the menu button that spears on the dock in es. From there you can select new> folder.
android/linux 101: any file or folder named starting with a period is deemed "hidden". An example would be a folder called .media. Because the name behind with a period, it is now hidden. To show hidden file, go into es file explorer settings, and check "show hidden files"
...and if you don't want to play with renaming folders every time, try Hide It Pro from the market. You set a password that is required to open the app. It disguise itself as a fake audio manager. You just need to browse to the file you need to hide and select "share with audio manager". There's a really good guide inside the app when you install it but its rather simple Works great on Iconia.
https://market.android.com/details?id=com.smartanuj.hideitpro&feature=search_result
It also displays adds but its free and your hidden content is just a "click" away You can hide any file type compared to Photo Vault and Video Vault (they support only several file formats and they are paid apps)
Use a file manager such as astro, and change the format of the video to a format that doesn't exist by renaming it, for example: video.avi ----> video.uitpo, then the video won't be shown in gallery or anywhere else, and whenever you wanna view the video just change the format back to what it was.
gunnyman said:
create a file in that directory called .nomedia that will prevent it being scanned by Gallery
Click to expand...
Click to collapse
I have created a file in my directory named .nomedia
But, when the Acer is powered off and started up again, all the files in this directory show up in the Gallery again. That approach doesn't seem to work for me.

[Q] A storage question

This isn't necessarily a nexus question, but I thought you guys would probably know anyway.
If I look at the file structure over a USB cable from my PC, I see what I think is on the "SD card". I have a list of directories and I can see the files.
However, if I use ES File manager, I can go to /SDCARD0 and I see the same file list but an additional directory called "maps" (created by my mind map application).
if I use ES File manager and just look at where it starts off (the Home directory), I don't see that "maps" directory.
So, how can I get my PC to see that extra directory? Is it some sort of permissions or is it more complex than that?
regards
Alan

[Q] Big thumbdata3 file in internal storage

Hi all;
Can i know why the thumbdata3 file folder in /mnt/sdcard/DCIM is so big in size (nearly 1gb) in my internal storage? Actually, all my photos or videos are in my ext-SD.
I have tried to delete the thumbnail folder but it come back again in same location. As shown in the picture, the device memory bar is almost full,but the available space still show 7.24gb. Please advice. Thanks.............
Anyone can help..? Thanks.........
Big thumbdata3 file in internal storage
erictanyh said:
Anyone can help..? Thanks.........
Click to expand...
Click to collapse
Using a disk space analyzer, I was surprised to see that my Android tablet had 1.03GB of photos. This was odd to me, because I knew there were only a couple of photos on the device.
I pinpointed the problem to thumbnails. These are tiny copies of photos used by some apps to more quickly display pictures. Specifically, the 1GB was being taken up by a thumbnail index file, and I didn't need to lose that 1GB to a function I don't use on the tablet. I erased the file as follows:
1. Open a file manager on Android. I use File Manager from Rhythm Software.
2. Ensure that it can display system or hidden files. This is an option somewhere under Settings. In File Manager, tap Menu > Settings > Show Hidden Files.
3. Navigate to \mnt\sdcard\DCIM\ .thumbnails. By the way, DCIM is the standard name for the folder that holds photographs, and is the standard for pretty much any device, whether smartphone or camera; it is short for "digital camera IMages." Another BTW: when a folder name is prefixed with a period, then it is a hidden folder in Android (such as .thumbnails).
4. Select and erase the file that's about 1GB and contains the word 'thumbdata." The exact file name will vary.
After I did this, image viewing apps like Gallery operated just fine, with no apparent slowdown from the loss of this file.
In this way I freed up 1GB on my Android v4 tablet, 1GB on my Android v4 phone, and 750MB on an older Android v2 phone.
Keeping the 1GB Free
Because .thumbdata is a system file, Android recreates it. Indeed, you may find more than one copy in the .thumbnails folder, if you have reinstalled Android or similarly redid the system in some way.
To keep Android from creating the 1GB file anew, we need to create a dummy file that fools Android. In short, we create a text file with a text editor, and then move it to the thumbnails folder. Here are the steps to doing this:
1. Use File Manager to determine the exact name of the thumbnail index file. On one of my Android devices, the name is .thumbdata3--1967290299. Write it down.
2. Start a text editor or word processor on the Android, and then create a new text file.
3. Use the Save As command to save the file in the DCIM folder. (We move it to the .thumbnails folder in a later step.) Save it with the same name at that index file, such as ".thumbdata3--1967290299". Now, depending on the text editor's capabilities, it might not allow the "." prefix or a blank extension. Thus, you might end up with thumbdata3--1967290299.txt as the file name. We fix this in a later step.
4. Exit the text editor, and then switch to File Manager. Now, it is important you use a file manager like Rhythm Software's File Manager app, because it does what some others cannot: it can (a) rename file extensions and (b) access hidden folders.
5. In File Manager, navigate to the \DCIM\ .thumbnails folder. If the thumbdata3 file is there again, erase it again.
6. Move up a level to the \DCIM folder, and then right-click the thumbdata3--1967290299.txt file name. ("Right click" means hold your finger down on the name until a menu appears.)
7. From the menu, choose Rename, and then rename thumbdata3--1967290299.txt to .thumbdata3--1967290299 -- (a) add the dot (.) to the start of the file name, and (b) erase the ".txt" from the end of the file name.
8. Click OK (or Rename) to finish renaming.
9. Right click the file name, and then choose Move (or Cut).
10. Navigate down to the .thumbnails folder, and then tap Paste.
The dummy file will now prevent Android from creating the huge index file.
Thumbdata files allow most devices to access the file it is in i.e if u give another device permission to access your device it will create a thumbdata file so it can browse your personal files so should be treated with caution as app developers would be able to illegally access your sensitive personal images or information on your phone or smart device without consent from the owner therefore maybe should be treated as spyware permissions for thumbdata should be an optional decision from the user in Android systems and currently is not

Categories

Resources