Search Unity

Resolved How can I find persistentDataPath on android?

Discussion in 'Scripting' started by raarc, Nov 20, 2020.

  1. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    I have downloaded some files into persistent data path on android, however it seems some are not loading and I would like to navigate my phone to make sure the files are there. However I cant seem to find the folder on my phone, documentation says I should search for "/storage/emulated/0/Android/data/<packagename>/files" however i cant find that path on my phone. Using windows search doesnt work on the phone either so I cant do that either.

    I know at least SOME of the files are there because some are loading so the folder exists somewhere, i just dont know where.

    Here is what I see when I open my phone contents in windows:

    Untitled.png
    Btw everything works well when i build for windows, I am only having trouble on the android build.

    EDIT: nevermind I found it
     
    Last edited: Nov 20, 2020
  2. Havyx

    Havyx

    Joined:
    Oct 20, 2020
    Posts:
    140
    https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html

    "Contains the path to a persistent data directory (Read Only).

    This value is a directory path where you can store data that you want to be kept between runs. When you publish on iOS and Android, persistentDataPath points to a public directory on the device. Files in this location are not erased by app updates. The files can still be erased by users directly."

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Info : MonoBehaviour
    4. {
    5.     void Start()
    6.     {
    7.         Debug.Log(Application.persistentDataPath);
    8.     }
    9. }
     
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    As far as finding where the path is on your phone, the first thing I'd try is just adding this line anywhere and checking the log output when run on your phone.

    Code (csharp):
    1. Debug.Log(Application.persistentDataPath);
     
  4. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    how do i check debug logs when running on phone?

    while using unity remote 5 the game essentialy is running on windows and is just cast to the phone, so the directories all point to desktop

    only when I build does it truly run on the phone, and when the build starts running on the phone the connection to unity is severed so the console doesnt display anything
     
    Last edited: Nov 21, 2020
  5. Havyx

    Havyx

    Joined:
    Oct 20, 2020
    Posts:
    140
    If possible you might want to look into using the device simulator (might be easier than the remote app)

    https://docs.unity3d.com/Manual/com.unity.device-simulator.html
    https://docs.unity3d.com/Packages/com.unity.device-simulator@2.2/manual/index.html

    In regards to your issue I think you want ADB logcat

    https://docs.unity3d.com/Packages/com.unity.mobile.android-logcat@0.1/manual/index.html

    "Android Logcat Package is a utility for displaying log messages coming from Android device in Unity Editor"
     
    Joe-Censored and raarc like this.
  6. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    Using the logcat package in the package manager, or using the standalone logcat viewer that comes with the android apk.

    Edit: @Havyx already mentioned the package sorry to say the same thing :(.
     
    Joe-Censored, raarc and Havyx like this.
  7. MateenAlam

    MateenAlam

    Joined:
    Sep 29, 2021
    Posts:
    6
    How do we move file from data folder into other folder and run that file.
     
  8. ekta_augview

    ekta_augview

    Joined:
    Jun 18, 2023
    Posts:
    3
    Hi, Can you please tell me how you resolved it?
     
  9. TreshderGames

    TreshderGames

    Joined:
    Aug 25, 2019
    Posts:
    1
    Hey,

    I searched this for a long time and finally got it working. The steps that worked for me (on a Galaxy S21):

    1. Install a file manager on your android device (I used "File Manager +" but I think any manager works)
    2. Open the manager and allow it to access your files
    3. Head to main storage --> android --> data --> com."your company came"."the name of the game" --> files
    4. Here you can find all the data you saved in persitenddata

    Tips:
    1. If you haven't set a company name it should be "default company". But you can also search for the name of the game and find the folder.
    2. Once you open the folder you need to accept that the app accesses the data
    3. I didn't have to do it but you might need to go to the settings (In "File Manager +" on the top, the second Icon from the right) and click on "show hidden files".

    I hope that works for you and saves anyone else a ton of time searching because on some devices the path isn't as unity tells in the documentation.
     
    spacepiratee likes this.