Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by tantanix · Feb 05, 2019 at 03:05 PM · androidaudioclipstreamingassetspersistentdatapath

Where to store files in Android that can be accessed later via path?

I have an audio file that I want to be able to access later via a path. To the curious mind, I need that audio file in an FFmpeg command. streamingAssetsPath and persistentDataPath do not work in Android. If I use streamingAssetsPath, I get "Protocol not found" error. If I use persistentDataPath, I get "No such file or directory" error.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image xxmariofer · Feb 05, 2019 at 03:28 PM 0
Share

i have used multiple times persistentDataPath in android and never had an issue, make sure the file you are searching there exists. and for strea$$anonymous$$g assets is because is inside a jar and you need to access it using the www class for example.

avatar image tantanix xxmariofer · Feb 05, 2019 at 03:44 PM 0
Share

If I use persistentDataPath, where should I put the audio files in the project folder? For instance, strea$$anonymous$$gAssetsPath points to "\Assets\Strea$$anonymous$$gAssets".

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Bunny83 · Feb 05, 2019 at 04:41 PM

You have to understand how Android handles apps internally. Your app is essentially just a single zip archive, the APK file that you create. It contains everything that is related to your app inside this archive. However it should be clear that when installing an app the only actual file that is put on the users device is that one APK file. So there is no place where you can put a file that appears automagically on the users device when you install the app.


However if you need a certain asset as a standalone file on the device, you have to create that file manually. A common way is to place the file in the streaming asset path of your project. This way the file doesn't get compiled into Unity's internal assetdatabase but it's simply packed inside the APK archive in a special subfolder. The only ways to get access to files inside the APK is to either use Unity's WWW class which can handle the special file URIs with the custom scheme jar:file://. Another way is to use any third party library which can read / handle comressed files. Once you can read the content, you can simply store it as actual file inside the persistant data path,


So the usual process is like this:

  • try reading the file from the persistant data path.

  • if the file doesn't exist yet, "extract" the file from the streaming assets path using the WWW class and save it to the persistant data path.


So your file will be extracted at the first run or whenever the file gets deleted from the persistant data path.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tantanix · Feb 05, 2019 at 05:01 PM 0
Share

Thanks for the long response. I am aware of how it works in Android. I have tried all of them and none of it seem to work. And that's why I'm here. I guess there's really no choice but to manually place the files in the persistentDataPath on runtime on the first run.

avatar image Bonfire-Boy tantanix · Feb 06, 2019 at 02:01 PM 0
Share

What do you mean by "tried all of them"? Bunny's response seems pretty thorough to me. I've used what's described above as "usual process" many many times and it works fine.

avatar image tantanix Bonfire-Boy · Feb 06, 2019 at 03:26 PM 0
Share

We have the same hack/solution. Extract the files from strea$$anonymous$$g assets and then save to persistent data path on the first run. This is the solution I'm trying to avoid. When I said "tried all of them" I meant I've tried everything I know how to avoid the hack.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

225 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why am I unable to locate font files(.ttf) in unity android game in persistentDataPath? 1 Answer

Loading an image from streamingassets fails every time on Android 1 Answer

Open an HTML file from streamingAssets - Android 0 Answers

loading Images from streaming assets in Android 0 Answers

StreamingAssets and reading a binary file (Android) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges