Search Unity

Using unity app how to read the asset in android SDCard?

Discussion in 'Scripting' started by schetty, Oct 9, 2015.

  1. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    I am trying to read one file from my android sd card from my unity application, but its not reading.

    using the asset bundle i have exported my file and kept in my android device sd card and i am trying to fetch it and show into my scene.

    Here is the code i have used for this:

    Code (csharp):
    1.  
    2. public string URL;
    3. public string URLAndroid=Application.persistentDataPath+/cube.unity3d;publicstringAssetName;
    4. private string path;
    5.  
    6. IEnumeratorStart(){
    7.  
    8. //path = System.IO.Path.Combine (Application.persistentDataPath, "/cube.unity3d");
    9.  
    10. // Download the file from the URL. It will not be saved in the Cache
    11. using(WWW www = WWW.LoadFromCacheOrDownload(URLAndroid,1))
    12. {
    13. yieldreturn www;
    14.  
    15. if(www.error !=null)
    16. thrownewException("WWW download had an error:"+ www.error);
    17.  
    18. AssetBundle bundle = www.assetBundle;
    19.  
    20. if(AssetName=="")
    21. Instantiate(bundle.mainAsset);
    22. else
    23. Instantiate(bundle.LoadAsset(AssetName));
    24.  
    25. // Unload the AssetBundles compressed contents to conserve memory
    26. bundle.Unload(false);
    27.  
    28. }// memory is freed from the web stream (www.Dispose() gets called implicitly)}
    29.  
    Here i have used the URLAndroid as a normal downloading method and i have tried to fetch the model using system.io method but its not happening. I have created the corresponding folder in my android device and kept my assets eventhough its not happening.

    Plesae help me to solve this issue.
     
  2. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    any chance to read and get the asset bundle file from android sd card?