I cannot get the files in Android's external sd card programmatically - android

When I try the code below:
File home = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
File [] f = home.listFiles();
I cannot get the files in the sd card, can anyone explain why?
and the path of the external directory is /storage/emulated/0/
Thank you

I think you are using emulator with API-24/25 ..
Unfortunately with both you have no access to storage. I have no idea id that was intended to be change or its just a bug
You can check if you have access to your storage by adb shell ls
You must use Emulator with API-23 or less to be able to access storage.

Related

When using emulators, how to interpret the output path when calling Context.getFilesDir()?

Inside onCreate() I have this line:
File aux = context.getFilesDir();
which outputs this:
/data/user/0/com.example.tirengarfio.myapplication/files
but.. where is this path exactly insde Linux filesystem? or is it taking as reference the Android Studio Project root directory? os should I create it somewhere?
EDIT:
As I said to #Simas, but by the moment Im not connecting any smartphone. Im just using emulators on Linux. My intention is just reading a file using
FileOutputStream fos = openFileInput(FILENAME, Context.MODE_PRIVATE);.
So, where should I place the file inside the Linux filesystem?
This is the path of your app's local data folder. It can either be in the memory card or the device storage.
There's no easy way to access it if your device is not rooted but here's a starter:How to access data/data folder in Android device?
Let us see what the doc says :
Returns the absolute path to the directory on the filesystem where files created with openFileOutput(String, int) are stored.
No permissions are required to read or write to the returned path, since this path is internal storage.
So actually the files you will find are those which were saved with the very same function openFileOutput(String,int) by your/other applications.
So basically if you want to test some functionality (which I suppose) write a unit test that uses this API openFileOutput(String,int) to store some mockup data and then get it again with Context.getFilesDir() and some code for file processing.

android obb file location in internal memory for 4.0 - 4.4

Help please solve my problem with obb files, I add downloader_library to my project, when application start he download for me obb file, this worked good.
If file stored in external sd card no problem,app work, but when I try on telephone without sd card my app is crash. I look to method which look if obb file exists and I see he always look on sd card, How I can find my obb file in internal memory ?
This method looks if obb file exists:
static public boolean doesFileExist(Context c, String fileName, long fileSize,
boolean deleteFileOnMismatch) {
// the file may have been delivered by Market --- let's make sure
// it's the size we expect
File fileForNewFile = new File(Helpers.generateSaveFileName(c, fileName));
if (fileForNewFile.exists()) {
if (fileForNewFile.length() == fileSize) {
return true;
}
if (deleteFileOnMismatch) {
// delete the file --- we won't be able to resume
// because we cannot confirm the integrity of the file
fileForNewFile.delete();
}
}
return false;
}
This method - Helpers.generateSaveFileName use Environment.getExternalStorageDirectory();
fileForNewFile for 4.0 -
/mnt/sdcard/Android/obb/com.example.app/main.1.com.example.app.obb
fileForNewFile for 4.4 -
/storage/sdcard/Android/obb/com.example.app/main.1.com.example.app.obb
How I understand and read in internal memory obb must be somewhere in /data/data/com.example.app but how receive this directory ? And what real path:
/data/data/com.example.app/obb/main.1.com.example.app.obb ?
/data/data/com.example.app/Android/obb/main.1.com.example.app.obb ?
On phone (4.4.2) without sd card file manager show me path after download - /Android/obb/com.example.app/main.1.com.example.app.obb but phone without root and i don't see upper directory where is this Android folder.
I completely confused please help.
The directory you are trying to read (the one with data/data) is the getFilesDir() result. Can you try here: /mnt/obb/packagename/ with the regular read storage permission? The obb folder should already exist (at least for emulators).. Other paths should already be constructed if you tried to access folders using the tutorial given on the Android developers website.
Also you don't need root to access the files through ADB, and you can push/pull them through ADB as well with basic commands

Create, store and access files in Android storage?

I am writing a file to Environment.getExternalStorageDirectory + File.separator + "myFile.txt" with the permission to write to the external storage. This seems to be successful (i.e.: no error messages in the logcat).
However, my issue is when I try to access the data folders or a folder which will contain the files I am making via adb shell or otherwise I am told permission denied. I realise this is because I am not root and the device is not rooted. However, is there a location on my Nexus 4 where I am able to freely create, store and access files easily without special permissions? If not is there a simple way to solve this issue?
Thank you for your help.
Environment.getExternalStorageDirectory() does not point to /data but to /mnt/sdcard or /sdcard. All in all you are looking in the wrong place

How to acces the data of root folder(/) of an android device?

I'm storing the DB file to the path /data/data/somefolder/ in my application. I want to get the file from this folder in my system or in my device so that I can view the content in it. I'm able to pull the file from emulator, but I'm not able to get the file from device. Is there any app which can do this?
PS: Programatically I'm able to access the file
You can see that Here to get the "/data/data/somefolder/" directory with getExternalStorageDirectory() method
While inserting and retrieving you path you have to store fullpath to get solve out your problem.
EDITED : AFAIK its not possible to access internal data but you can create your same folder in external directory for future Use and access it when you required.
If you want to Access it from device then you can also create Folder at path "sdcard/YOUR_APPLICATION/XYZ/" location with Full path location in database.
You can store file in internal storage so there is need to specify path from root. simply you can write/ create file like: File f= new File("myfile.txt");
and use it as you want. and it will not visible to other apps so its most secure.
If you still want to store on external storage like micro SDCard or phones built in storage then please try following:
File root = new File("/");
get all the folders from root
String[] folders = root.list();
and use one of them as you want.
or
Use above mentioned methods like getExternalStorageDirectory().......
It is easy, when the device is rooted. If not you can still get the file when your app is built in debug mode. Try on your development machine
adb shell
and then on the device
run-as your.package.name
cd databases
cat your.db.file > /sdcard/your.db.file
and then you can copy it from your sd card.

How to pick file from /data/data/ path from a device

I have created a file in the below path using my applcation.
/data/data/VisionEPODErrorLog/ErrorLog.txt
I am able to see the file using Eclipse DDMS->File Explore ->Data
But when I installed my applcation in the mob device I am not getting that path in the device.
I need to see the exact file in the device
Is there any third party applcation needed to access the path.If so whats that or is there any way else to get that file from the device.if anyone konws please let me konw
please use below method
BufferedInputStream in = new BufferedInputStream(Mtx.getContext().openFileInput("ErrorLog.txt"));
i used in my application to read file stored under /data/data/ directory
i think this will help
/data/data/VisionEPODErrorLog/ErrorLog.txt
That is an exceptionally bad idea. Please do not do that. Please use getFilesDir() to get the root of your internal storage for files.
But when I installed my applcation in the mob device I am not getting that path in the device.
You should not be able to write there on a production device. Please do not invent random paths. Please use getFilesDir() to get the root of your internal storage for files.
You certainly cannot view anything in /data/data on a production device via any tool, unless you root your phone.

Categories

Resources