I am developing an app in android where it download image files and use it as app resource. I want to save the file in a directory so that user can't see this as media files shown in gallery. I just need to know the specific directory where i can save the file and the user wouldn't able to see it.
Android would automatically scan all folders on external storage for media files. If you don't want your image files to show in the gallery, maybe you could add some extension like ".myapp", this way cheats the scanner.
Using the Internal Storage 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.
Just Simple apply your own logic.
when u read the file from internet is byte format.
and after right in to sdcard.
this time just change the some byte of read file.and store this byte in some place like a sharepreference,Static varibale anything.and when you read file and display else play then change the same byte agian and replace this byte with orignal.this call incrypt and decrept.
it`s work dear i do for image file.
Just add a file named .nomedia in the directory you want to exclude from MediaScanner.
Another alternative is to save your image in a Database as a BLOB.
With this you are 100% sure that only your application can access it.
Related
I have a list of images referenced from the res/drawable folder. I realized that these images can be viewed from the compiled apk file when the file is opened with a file compressor program such as winrar. Is there a way to hide my images so that they can't be so easily accessed by snooping users?
The best option I see here is not saving your images inside the app. Instead, save them on your app server and get each image only when it's needed.
If your app don't have a server, you can save the images obfuscated inside your app (for example: base64 encoded or encrypted with a hard coded key). It won't stop a hacker but it will defend you from the common user.
From your comments it sounds like you want to use Internal Storage.
From the above link:
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.
Just google or search stackoverflow on how to use Internal Storage if you need more help outside the Android docs.
So I have some files I want my Android App to access, read and write.
I want to store it internally. Where can I put these files in my Java Project so they are accessible or can this not be done?
There are three ways to achieve this, and according to your requirements select the approch
on SDCARD
This is the normal SDCARD/in-build SDCARD in newer smart phones. you need to create specific folder structure and put your files there, here you can do file read and write both
but this in insecure because accessible to all the application
on Internal Storage
This is given as Applicaiton specific storage where you can create the file and do the operation, this is most secure way to do it, but this is generated run time so you can not push the files directly, you can put your files in RAW or ASSETS and copy that here
RAW and ASSETS
This is in the code structure only and only read access is given to this folder, you can not change this file run time.
if you select any one of this approach then simple goggling will show you the sample code.
You can read or write files in the path of your internal storage as
data/data/package_name/files . I had already answered a similar question you can check it out.
In my application, I have created a bitmap and save it as a JPG image in the SD card. I don't want any other apps to use this image. Is this possible in android ? Any help will be greatly appreciated .
Unless you encrypt the file, there is nothing you can do to prevent access to files on the SD card.
(See the section on external storage here)
Files saved to the external storage are world-readable and can be
modified by the user when they enable USB mass storage to transfer
files on a computer.
Instead consider putting it in internal storage, then your application will be the only one that can access it.
Another option, if you only need to hide it from media scanners is to either give it a name that starts with a dot (.myfile.jpg) this will make it a hidden file. (if you have multiple files you want to hide this way, include an empty file with the name .nomedia (see Saving files that should be shared) so you don't have to rename them all)
When storing the image, change the extension of the file to something else, so other apps would not recognize it. But when you want to use it in your app, change the extension back to .bmp or .jpg!
Use an application specific database and save your images there instead saving it on the SD-Card. Then only your application has access. I'm doing this to encrypt the images in my application, just saving a BASE64 encoded image string doing crypto stuf on it and vice versa. This would also work if you save a Byte Array of the image file.
Method 1 – Creating A .nomedia File .
Using any file explorer/manager application (such as Astro File Manager or File Expert), navigate to the directory that you want hidden and create an empty file titled “.nomedia”.One way to do so is to:
Copy an existing text (.txt) or even an image (.jpg/.jpg) file to said directory,
Open it in a text editor (hold down on the file and select the appropriate option from the context menu that appears),
Delete its contents (hold down on the text, Select all and Delete), save changes and exit,
Rename it to “.nomedia” (hold down on the file again and select Rename from its context menu).
This method disables media scanning on the chosen directory, causing the Gallery to skip the directory altogether at launch.
I'm geting a file from server, and storing it on the phone. It's a PDF. Then I need to display . Assuming that I have a PDF viewer it will open the file.
The question is where should I store the PDF file so my pdf reader has access to it. I don't really want use external storage since not all phones has one. Is there a way to save public file on internal storage?
Or there is some way to pass the necessary information using ContentProvider. Unfortunately I would need some sample code of that.
All you put under internal directory can't be access by other applications. so getDir or getCacheDir have to be used only for your application.
If you need files to be open by other application you have to write files under SD card.
Can anyone help me ? Is it possible to create shared preference files in sdcard rather than on private path of an android application.
You cannot modify where shared preferences are stored.Its a private storage. if you want to use sd card use
Environment.getExternalStorageDirectory(). and get the path of directories stored in sdcard.
it is possible by reading&writing the xml file into the external storage ,but it's not the same as sharedPreferences. you will have to implement your own way , or use the android code of this class.
however , there are some disadvantage over using the internal storage:
anything you store on the sdcard is visible to every application and the end user can read it by just opening it.
only in the internal storage you get some sort of protection against reading the file , so that only rooted devices can read the files.
external storage can also be unmounted , so the data can sometimes be unreachable. you need to handle possible errors that can occur because of this.
uninstalling the app while the sd card is mounted means that the data will stay on the sdcard .