Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I copy files to the file system of android?

How can I copy files to the file system (place) in android? How can I access it?

like image 826
Alex Kapustian Avatar asked Apr 19 '10 14:04

Alex Kapustian


People also ask

Does Android have a file system?

Device root storage – Every Android device has a special file system where all the root files are stored. This includes operating system files, sensitive application data, system apps, and more.

How do I copy a file to another file?

Copy and paste filesRight-click and pick Copy, or press Ctrl + C . Navigate to another folder, where you want to put the copy of the file. Click the menu button and pick Paste to finish copying the file, or press Ctrl + V . There will now be a copy of the file in the original folder and the other folder.


4 Answers

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/
like image 70
Raja Avatar answered Oct 20 '22 07:10

Raja


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.

like image 23
Chris Thompson Avatar answered Oct 20 '22 09:10

Chris Thompson


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.

like image 29
Macarse Avatar answered Oct 20 '22 09:10

Macarse


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.

like image 40
Danh Nguyen Avatar answered Oct 20 '22 09:10

Danh Nguyen