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.
Related
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.
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.
I have a file named flash_image in my apps asset folder.
I am wanting to copy this to my apps private data folder, and make it executable (my app will be running with root permissions, if this helps).
So, I want the file to be located at /data/data/com.liamwli.flash/flash_image and have that file executable.
I have tried many methods I found online, but I cannot get it to work.
How can I go about doing this?
If you want to save some data in /data folder, so you really want to save the data in devices internal memory. Check this out: Android Developers Storage Options Link. Also try changing mode to Context.MODE_WORLD_READABLE. I hope this will lead you in some way.
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.
How can I copy files to the file system (place) in android? How can I access it?
copy files from android to local
adb pull /data/data/com.example.sample ./sample/
copy file to android from local
adb push ./sample/ /sdcard/sample/
I'm not sure if this is what you're asking, but here's another interpretation of your question:
You can place files in the assets folder in the project on your development machine. They will be bundled into the apk file and then access them through the AssetManager class. Something like this from within a Service or Activity class:
AssetManager am = getAssets();
InputStream is = am.open("filename");
This will allow you to read the contents of those files. I don't believe you can write to them though. There are other options for if you need to read and write files in your application's storage sandbox. This is done by calling openFileOutput(). I should note though that the user can always access the files on the device through ddms but other applications won't be able to access files stored in your application's storage sandbox.
Edit Based on your comment, you probably want to use
OutputStream out = openFileOutput("outfile");
to write to a file from your code. This code must be called from within an Activity or Service (something that extends Context). This file will be stored on the phone's file system and not on the sdcard. These files will not be accessible to the average user. If users know how to enable usb debugging then they will be able to access them and there is really no way around this.
You can use:
Environment.getExternalStorageDirectory()
That will give you /sdcard if your device has an sdcard, or something different in other cases. For example the Archos.
I took some time to research about android's system files earlier, but almost always with android x86, i found out that the /system folder inside android is read-only,
it is an image with format is SFS format, this is read-only image format of linux so i don't think you can copy some thing inside this folder. I not sure about rooted android. Hope it will help you.
You can probably hide your file in the sdcard by prefixing it with a dot (ex: .myfile)