Hide pdf and .mp4 files in Android - android

I'm developing an app that downloads .pdf and .mp4 files from a server. I'm saving this files on my SD card.
I need to hide these files to only be visible from my app.
Can someone help me?
Thanks!
Best regards.

Create a folder with a folder name starting with '.' (dot) and save files in this folder,it usually works on all linux versions and android

Best practice is to use internal storage. files saved to the internal storage are private to your application and other applications cannot access them. When the user uninstalls your application, these files are removed.

Create folder like this
File rootPath = getBaseContext().getDir("Yourfoldername", Context.MODE_PRIVATE);
if (!rootPath.isFile()) {
rootPath.mkdir();
}
File file = new File(rootPath, "sample.pdf");

Create a folder and Inside folder save your file with '.' before File name and save files, it will work on all versions of android

Related

Hiding a folder in android not using "." extension

How can I hide a folder in android? I am downloading some data from the app which must be accessible only through my application. Currently, I am hiding folders by putting "." extension to the folder name and saving it in the app directory. But it will get visible when switching on "show hidden option" in file managers and enter the particular app data. Kindly suggest some methods by which we can hide data similar to what we see in amazon prime application and all.
Unless the user roots their device all internal files are accessible only to your app. Beyond that, there is no use case and no acceptable reason to hide files from the person who actually owns the device.
Hiding a folder in android not using “.” extension
you can use internal storage as an alternative to hide the folder, if the device is rooted don't allow the app to be installed, if the user roots the device after app install no matter what you do things will be accessible.
//Create internal dir;
File mydir = context.getDir("DIR_NAME", Context.MODE_PRIVATE);
Currently solved my issue by saving files to Internal Storage.
We can use either
File file = new File(context.getFilesDir(), filename);
or
File mydir = context.getDir("DIR_NAME", Context.MODE_PRIVATE);
for saving it in internal directory.
But if rooted device the issue will persist

How to attach SD card files with apk

My project have multiple files in SD card. But when I install apk file on phone it does not work.
Please tell me how to attach those files with apk.
Your sdcard files cannot become the part of APK file, if you want those files to attach to your apk, insert them into asset folder or raw folder.
EDIT:
If you put your file in raw directory then:
com.your.package:raw/yourFile
Like this:
int resourceId = context.getResources().getIdentifier("com.your.package:raw/somefile.txt");
File f = new File(context.getResources().openRawResource(resourceId));
And here's someone doing it with the assets folder:
Android Assets with sub folders
InputStream is = getAssets().open("subfolder/somefile.txt");
Create a sqlite database and store the path of whatever files you want to store on the sdcard. Also you can store them in assets folder depending upon the type of file but it is not a good practice as many say.
You could store the supporting files on a web server and have the application download the files to the sdcard on first run. This is what many games do. Google Play also offers free storage of files for applications.
Here is the Google blog post on large APK's
http://android-developers.blogspot.fr/2012/03/android-apps-break-50mb-barrier.html

How to set folder permission to read only in android [duplicate]

I want to create a folder in sdcard in an android device and I want to set a folder permission for the creating folder. The folder permission should be that from only from my application this folder should be assessable. No other application should be able to access this folder. Is there any method to create this. Please provide any valid link for this.
sadly it is not possible to create read-only permissions for the sdcard. This is a part of Android's system design and won't be changed soon.
I am making an application in android and I want to make a ready only folder in sdcard.
This is not possible, sorry.
FAT32, the standard SD card file system, does not support file permissions. This means that any file is world readable and world writeable.
String SaveFolder = "/Ready";
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File myFolder = new File(extStorageDirectory + Folder);
myFolder.mkdir();
This is a code to make a folder, and just like Tim said: it is not possible to create read-only permissions folder.
As others have said, you can't for the reasons specified.
I'm not exactly sure what you are trying to accomplish, but if you want to create a private file that can't be accessed by other apps, you can create in your app's "data" directory, by doing this,
OutputStream os = context.createFileOutput("myfile.ext", Context.MODE_PRIVATE);
Note that this is not the SD card, it's internal storage, so you aren't going to be able to create a very large file.

Create a read-only folder in sdcard in android

I want to create a folder in sdcard in an android device and I want to set a folder permission for the creating folder. The folder permission should be that from only from my application this folder should be assessable. No other application should be able to access this folder. Is there any method to create this. Please provide any valid link for this.
sadly it is not possible to create read-only permissions for the sdcard. This is a part of Android's system design and won't be changed soon.
I am making an application in android and I want to make a ready only folder in sdcard.
This is not possible, sorry.
FAT32, the standard SD card file system, does not support file permissions. This means that any file is world readable and world writeable.
String SaveFolder = "/Ready";
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File myFolder = new File(extStorageDirectory + Folder);
myFolder.mkdir();
This is a code to make a folder, and just like Tim said: it is not possible to create read-only permissions folder.
As others have said, you can't for the reasons specified.
I'm not exactly sure what you are trying to accomplish, but if you want to create a private file that can't be accessed by other apps, you can create in your app's "data" directory, by doing this,
OutputStream os = context.createFileOutput("myfile.ext", Context.MODE_PRIVATE);
Note that this is not the SD card, it's internal storage, so you aren't going to be able to create a very large file.

Adding file to .apk

My program needs large .txt file to be stored on SD-card (so, I want to redistribute it with .apk, without creation from the program). How I can attach the file (created on PC) to .apk?
You can save it in /res/raw folder
If you save your file as yourfile.txt
InputStream inputStream = this.getResources().openRawResource(R.raw.yourfile);
As far as I know you can open a .apk with zip and add files. Where is no magic :)
It might be slightly easier to use the AssetManager. Just save your files in the assets/ directory (as opposed to res/raw/). Then you can access them directly using their filename. http://developer.android.com/reference/android/content/res/AssetManager.html describes how to access the assets.

Categories

Resources