- Home /
How to access persistent data path in Android phone?
I am working on porting my Unity windows application to Android and have been trying to figure out how to re-implement the external config-file reading process on a Samsung Galaxy Tab.
I have read that Unity has the Application.persistentDataPath function that returns a safe path for the Android application to perform file IO. On the Galaxy Tab, it returns "data/data/com.MyDemo/files". I have been trying to copy a simple text config file from windows to that persistent data path on the Android device directly via USB but no matter what I do, I simply could not find the directory anywhere, either in both windows explorer or on the device file manager itself.
This is really baffling to me. How on earth can I "install" basic config files if I cannot even access the data folder manually? Is there anyway to do this?
Does anyone even visit this website? It seems to pale in comparison with StackOverflow...
It does. It's a combination of two things: A: StackOverflow is more general, so it attracts a far larger audience, and B: Unity takes almost no technical knowledge to get started with, but pretty much a full-fledged university-level programmer to master. So, as a result, the Q&A website gets a really tilted ratio of beginners to experts. Sorry I can't be of actual assistance with your question, I guess I just... needed to vent that. >_<
Find a good software to open/show the Android folders in your Windows. I'm trying some software for this, and find the Android Commander as a good option. Link: http://android-commander.en.uptodown.com/
Answer by colchambers · Oct 30, 2012 at 08:43 PM
You need to change the build settings for android. change configuration > write access to external (sd card).
Answer by Calvin2274 · Sep 11, 2014 at 08:12 AM
Application.persistentDataPath have two paths base on your Write Access setting, you can find it at Build Setting > Player Setting > Other Settings, by default, it is internal Only. means that the path should be point to /data/data/com.your.appid/files which is for development only, user cannot find this files without root android device.
if you set the Write Access as External(SD Card) or add WRITE_ EXTERNAL_STORAGE permission into AndroidManifest.xml, Application.persistentDataPath will point to Android/file/com.your.appid/files of your sd card.
This answer also is correct but goes into a little more detail than the selected answer. Thanks Calvin.
@Calvin2274 And if the phone don't have an SD Card slot or we don't have any SD Card?
I changed the the Write Access to External(SD Card) but still can't see the file.
Edit: If you don't have an SD Card, the file doen't appear in Android/file/com.your.appid/files because it's the Internal Memory of the phone. If you print the Application.persistentDataPath while you don't have an SD Card, it still prints the path Android/file/com.your.appid/files. As far as I tested, you can create a file in the persistent data path, but you can't access it via the File Explorer. Also you can read this invisible file and write on it, but you need to do it via script. I made an app for my self to read and show the information of my JSON database. Also to make changes.
Answer by shishirams222 · Apr 05, 2019 at 01:33 PM
Is there any option to make the files accessible within internal storage rather than external sd card?? @Calvin2274
Your answer
Follow this Question
Related Questions
Add a pdf file 0 Answers
Android File-io? 1 Answer
Check if folder exists - Unity's way 2 Answers
Loading from multiple files? 2 Answers
Reading files on Android, 1 Answer