Access the internal memory of android through in independent java code - java

I have created an xml file here: /data/data/com.appName/emergency.xml
Now I want to access this file from my desktop.
I am able to access the SD card through my java code. In this case, I think, the file is created in the internal memory of the device. So is it possible to access the file emergency.xml?

if you have a non-rooted device then you can't get that file from your desktop since it is readable only for the "com.appName" app. You can try to do "adb pull /data/data/com.appName/emergency.xml", but that should not work on a normal device.
But if "com.appName" is your app then you can let the app copy the file to a place where you can access it from your desktop (e.g. /sdcard).
Example Code for file copy: http://www.roseindia.net/java/beginners/CopyFile.shtml

Now I know that this works on rooted devices (which you really should probably have if you want to do serious dev work), and I THINK it will work for nonroot devices. Basically you enter the adb shell and then do something like "dd if=/data/data/com.appName/emergency.xml of=/sdcard/emergency.xml". Then you should be able to pull the file with adb pull off the sdcard.

Related

Android 11 Storage Access and Java File Library

I have an android application already available on playstore. It is a file transfer app between PC to Android using localhost. I'm using following java function within it:
To create directory/file/show list of files and many other file functions(append, byte read/write etc):
file.mkdir
directory.listFiles();
file.createNewFile()
I had also put
requestLegacyExternalStorage="true"
And it is working fine on android 10 after giving sufficient read/write external storage permission.
But the problem is that these will not work on android 11 as requestLegacyExternalStorage will not work. I have used MANAGE_EXTERNAL_STORAGE and the app works perfect but the problem is that playstore is not allowing it. (Don't know why they rejected the update)
I have also used getExternalFilesDir and it works perfect but don't like data to be in android folder and remove if app is deleted.
I have also tried to use download location and it works but the problem is getExternalStorageDirectory is deprecated:
File file = new File(Environment.getExternalStorageDirectory()+"/"+Environment.DIRECTORY_DOWNLOADS,"FileChat");
So what I wanted to ask how can I manage/use file library for android 11 to read/write/create/delete files and directory. It should not be in android folder as this will be deleted after app is deleted. Can I used public directory like downloads? If I can, what is the alternative to getExternalStorageDirectory()?
I don't need to read user data. Just want to have a directory in which app can store files. The read function is working as file is picked by user using intent.
Thanks in advance.
Top-level directory write access of shared storage is not available in Android 11, however you can use the existing File APIs to access the media and download collection folders like /Pictures, /Downloads, /DICM etc. It won't be possible to create your app's own folder as top level directory but it is possible to create a dedicated sub-directory in the default collection folders.
To keep your app running as expected on Android 10, requestLegacyExternalStorage flag will also be required since access to shared storage on Android 10 was restricted via MediaStore APIs only.
If transfer is only for your apps own files then put them in
File file = new File(Environment.getExternalStoragePublicDirectory(DIRECTORY_DOCUMENTS),"FileChat");
Or use Storage Access Framework to let the user choose and or create a directory on external storage inclusive removable micro sd card.

Android: Retrieving shared preferences of other application (rooted device)

I am running a vulnerable android application on a rooted device using the Genymotion and i am trying to read shared preferences and a file in files directory inside different android application like:
/data/data/xxxx/config.xml and
/data/data/xxx/files/xxxx.xml
i am trying to read this data programmatically using a sample java application to show the data in logcat, but when i try to read the files, i get permission issue on the logcat.
The funny thing is the application is running on a rooted device, so i suppose to have access to other applications sharedpreferences.I need something like this, but show this in the logcat:
https://lightsec.wordpress.com/2014/04/28/android-sharedpreferences-insecure-storage/.
I have also tries this answer, but it does not work:
Android: Retrieving shared preferences of other application
How can i retrieve all the available keys from sharedpreferences and show in logcat?
Both of those links describe using the WORLD_XX constants as in the app you're trying to read from.
Literally no one in the world would use those constants, as they don't want their shared preferences to be read by others. Everyone uses the MODE_PRIVATE constant, so they can't be read by others.
To achieve this, you'll need to do the following:
1) Request Root Access in your app (Having a rooted phone is NOT enough). (A library like RootTools can help you do this)
2) After you get root access, then you have to read the raw .xml file from the file system, and parse it accordingly. Then you can read all the data, and even write to it if you wanted.
Sounds a bit like you're confusing having a rooted phone and your app having root access, those are different things.

Android access file system nexus 7

Background
I am developing an android application that will only be used on Nexus 7 tablets (my team is also providing and has access to the hardware).
Problem
The app needs to be flexible to allow content to be added (by non-tech savvy users) to the app and accessed without an internet connection.
Our Idea
Android devices have a file system. We want to design a file system layout such that the people adding content to the application can drag and drop into the correct folder.
e.g.
AppName
Images
Videos
If the user adds a video to the videos folder of the device under our app, it will show up in the app.
We understand that this could easily go wrong (accidentally delete a folder, etc.) but this is out best attempt to solve this without having to update the app ourselves whenever new content comes up (and remember, no internet connection!).
The Question
Is it possible to access the android file system contents and insert them into an app as described in the "Our Idea" section? If so, how?
Yes. This is possible if you don't bother about content security. You can copy the content to any of the file system path in sdcard and your app can look for the folder and read the files .
Example , you can create a folder in sdcard as
sdcard/appname/media/
and create a layout to access the files in the device, and when user selects the files provide option to copy it to your sdcard/appname path.
Check this link
http://developer.android.com/training/basics/data-storage/files.html
Note : the sdcard path can be accessed if you connect to any external system ( PC).

Custom password encrypted file system for storing files in Android

is it possible to create a custom file system or use an existing file system like EncFs to read data inside Android environment.
My idea is to make a virtual filesystem for storing some media files and developing an app which can directly access those files from the filesystem volume.
I hope im clear with my question.!!
Yes, but you need a rooted devices to use it. Or, you need to build your own firmware. Here's one, it's open source: http://nemesis2.qx.net/pages/LUKSManager

Trouble having when pushing files to DDMS?

I'm trying to push one mp3 file to (Emulator) the location /system/media/audio/ui using command adb push But, i'm having
E:\Android\android-sdk\platform-tools>adb push song.mp3 /system/media/audio/ui
failed to copy 'song.mp3' to '/system/media/audio/ui/song.mp3': Read-only file system
this error. How can i change the Permission or how to push the files to this location. Any idea?
Unless you have a really good reason not to, you should stay in the /sdcard/ folder. Except for /sdcard/, most of the file system is read-only for a normal user.
It is possible, but not recommended, to "root" the phone. After which you would have full access to the whole system. Attempting this on a real phone, could break the phone, or invalidate your warranty.
If you wish to get root-privileges on the emulator, you can look at the accepted answer to this question: how to root/getroot access on android emulator?
That means your emulator does not support the sdcard. So create the emulator with sdcard option. see the bello image...

Categories