• 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
1
Question by geronika2004 · Feb 09, 2013 at 03:26 PM · android

Copy database from Assets to Android sdcard?

I need to copy database from Assets to sdcard on the Android. Why this does not work:

 if (!(File.Exists(Application.persistentDataPath+"/db.db")))
 {
  File.Copy(Application.dataPath+"/db.db",Application.persistentDataPath+"/db.db");
 }
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Feb 09, 2013 at 05:10 PM

Well, have you checked that the file is even there? Unity packs all assets into it's own asset database format. You can't really access any assets via file access. I guess what you want has been described here. However read the documentation about the streamingAssetsPath carefully. On android you have no file access rights to your application folder unless you are on a "rooted" device. Furthermore, as you can read in the docs, all assets are packed into the apk file so Application.streamingAssetsPath will return an URL which can be used to load the files via the WWW class.

Comment
Add comment · Show 3 · 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 geronika2004 · Feb 09, 2013 at 05:16 PM 0
Share

[Bunny83] Thank you very much, will try that. I have got rooted device and put file manually, does the Application.persistentDataPath has read/write ability? $$anonymous$$y main goal is to read/write sqlite database:

 SqliteConnection con =new $$anonymous$$ono.Data.SqliteClient.SqliteConnection(connectionString);

I checked DLL loads, and file also exists at the path, under windows connection works but in android it does not work :(

avatar image Bunny83 · Feb 09, 2013 at 08:06 PM 1
Share

Yes Application.persistentDataPath has read and write premission even on normal non-rooted devices. However Application.dataPath is read and write protected.

Application.persistentDataPath is also hidden from external access (on non rooted devices of course). Only the application itself can access it.

If you just want to initialize your database with some data, you might simply export your database as SQL and include this as textasset in your application. Now you can easily create a new database file in the persistentDataPath and just insert your data.

avatar image geronika2004 · Feb 10, 2013 at 08:23 AM 0
Share

Thank you!

avatar image
0

Answer by Compguru910 · May 28, 2013 at 08:09 PM

Also, you might want to check that it is not there on the phone as opposed to using the Windows Explorer. I was recently working on an app that wrote a file to the SD card. For some reason Windows Explorer didnt have access to some of the SD card folder (or internal storage). What I had to do was use a File Explorer app for Android to find the file.

Comment
Add comment · 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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

11 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

Related Questions

Loading from mobile internal storage and/or sd card 0 Answers

Android SD card problem 1 Answer

unity 3d android application load 3ds models from sdcard 1 Answer

How can I save and read data on Android? 1 Answer

How am I able to get the root path of an SDcard for any one android device? 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