Search Unity

Question Android - Use SQLite database in other folder than StreamingAssets folder

Discussion in 'Getting Started' started by Gng357, Jul 14, 2021.

  1. Gng357

    Gng357

    Joined:
    Oct 29, 2018
    Posts:
    3
    I made a cross matching words game for Android devices. Currently I am using an SQLite Database in StreamingAssets folder for the words in the game and everything works great.

    The problem is that my database in StreamingAssets folder is easily accessible to anyone.

    Is there any way to move and access my database from other folder except StreamingAssets?

    I am using the code below to access my database on Android:

    Code (CSharp):
    1.  
    2. string databaseName = "/MyDatabase.db";
    3. StartCoroutine(SetDatabase(databaseName));
    4. return Path.Combine("URI=file:" + Application.persistentDataPath + databaseName);
    5.  
    6. private IEnumerator SetDatabase(string databaseName)
    7. {
    8.    string path = Path.Combine("jar:file://" + Application.dataPath + "!/assets" + databaseName);
    9.    UnityWebRequest unityWebRequest = UnityWebRequest.Get(path);
    10.    yield return unityWebRequest.SendWebRequest();
    11.  
    12.    while (!unityWebRequest.isDone) { }
    13.  
    14.    if (unityWebRequest.isNetworkError || unityWebRequest.isHttpError)
    15.          AppHelper.Dbg("SetDefinitionsDatabaseForAndroid()", this + ": " +unityWebRequest.error);
    16.  
    17.    /// Retrieve results as binary data.
    18.    byte[] data = unityWebRequest.downloadHandler.data;
    19.  
    20.    /// Writes the DB in the persistent memory.
    21.    File.WriteAllBytes(Path.Combine(Application.persistentDataPath + databaseName), data);
    22. }
    23.        
     
  2. chrolokoy

    chrolokoy

    Joined:
    Nov 8, 2022
    Posts:
    1
    Hello can I get your Unity package about SQLite for Android. I am struggling to my thesis project please
     
  3. Oksana-Iashchuk

    Oksana-Iashchuk

    Joined:
    Sep 10, 2012
    Posts:
    126
    have a look at https://u3d.as/3ka , maybe it helps
     
    Last edited: Jan 12, 2023
  4. RichAllen2023

    RichAllen2023

    Joined:
    Jul 19, 2016
    Posts:
    1,026
    You = Fail.

    Students are supposed to do their OWN work.

    @Gng357 there might be a way to make your database private.