[請益]關於Unity做出的Android遊戲開啟外部檔案
看板GameDesign (遊戲設計)作者solitarysky (solitaryeagle)時間10年前 (2014/12/25 02:32)推噓0(0推 0噓 14→)留言14則, 2人參與討論串1/1
各位前輩們好
小弟目前為新手正在努力自學中
最近自己使用Unity製作了一個Android小遊戲, 想要讓它自動更新
伺服器部分處理完了, 也可以下載檔案
也做了檔案下載進度條
但.....下載完後卻打不開(囧)
試過了許多的方法, 也在外文網查了許多文章
但都沒用...... >_<
懇求各位前輩幫忙!
(Player的Write Access 為 External(SD Card))
//ServerFileName為檔案的名稱 ex:test.apk
string filePath= Application.persistentDataPath + "/" + ServerFileName;
查出來的確切路徑為:
/storage/emulated/0/android/data/com.mygame/files/
....
using System.IO;
using System.Diagnostics;
....
//寫入檔案
System.IO.FileInfo file = new System.IO.FileInfo(filePath);
file.Directory.Create();
//下載用www方式
System.IO.File.WriteAllBytes(filePath, www.bytes);
開啟檔案使用過的方法為:
---------------------------------------------------------------
(1.)//想說用電腦瀏覽器的話, 這樣打得開, 手機上應該也可以.......
Application.OpenURL("file://" +filePath);
(2.) // C# System.Diagnostics
Process.Start(@"file://" +filePath);
(3.)
System.IO.File.OpenRead("file://" +filePath);
(4.)
WWW OpenFile = new WWW("file://" + filePath);
yield return OpenFile
---------------------------------------------------------------
以上在電腦上Unity模擬測試可以正常開啟檔案, 以及在手機的瀏覽器輸入filePath也
可開啟
試了好幾天, 找不出原因
猜測為手機權限不足, 所以無法開啟檔案?
不知道如何開啟權限 orz
也很蠢的想說如果用htm寫個網址導向, Application.OpenURL(導向網址)
htm => <meta http-equiv="refresh" content="1; url=file://filePath>
結果當然也不能~"~
聽說更新也可以用AssetBundles, 但我還沒搞懂...
所以想說先用"下載apk方式, 讓Android手機安裝", 來達到更新
又查到似乎可以用java修改AndroidManifest.xml並寫入Plugins
但沒學過.....要搞懂可能要一段時間
請問有經驗的大大們能提示大概要怎麼開啟檔案嗎?
拜託了!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 49.158.119.53
※ 文章網址: http://www.ptt.cc/bbs/GameDesign/M.1419445936.A.D5E.html
→
12/25 08:06, , 1F
12/25 08:06, 1F
→
12/25 08:06, , 2F
12/25 08:06, 2F
→
12/25 08:07, , 3F
12/25 08:07, 3F
→
12/25 08:10, , 4F
12/25 08:10, 4F
→
12/25 08:10, , 5F
12/25 08:10, 5F
→
12/25 11:59, , 6F
12/25 11:59, 6F
→
12/25 11:59, , 7F
12/25 11:59, 7F
→
12/25 12:00, , 8F
12/25 12:00, 8F
→
12/25 12:07, , 9F
12/25 12:07, 9F
→
12/25 12:09, , 10F
12/25 12:09, 10F
→
12/25 12:10, , 11F
12/25 12:10, 11F
→
12/25 12:16, , 12F
12/25 12:16, 12F
→
12/25 12:16, , 13F
12/25 12:16, 13F
→
12/25 12:19, , 14F
12/25 12:19, 14F
GameDesign 近期熱門文章
PTT遊戲區 即時熱門文章
40
67