問題描述:
PhoneGap+Sencha Touch開發的應用,打包后的APP或者調試期間,在啟動的時候提示如下信息:
方法3:改名法
Application Error - The connection to the server was unsuccessful.
(file:///android_asset/www/index.html)
(file:///android_asset/www/index.html)
問題分析:
這個應該是PhoneGap某些版本的BUG,尤其在index.html加載的內容較多時容易出現。
解決方法:
方法1:更新到PhoneGap的最新版本;
方法2:設置加載超時屬性
super.setIntegerProperty("loadUrlTimeoutValue",10000);
完整代碼如下(設置超時為 10 秒)
@Override
publicvoid onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/home/index.html");
super.setIntegerProperty("loadUrlTimeoutValue",10000);
}
方法3:改名法
把index.html更名為main.html,然后新建一個index.html頁面,內容如下:
<!doctype html> <html> <head> <title>tittle</title> <script> window.location='./main.html'; </script> <body> </body> </html>
主要原理就是通過一個過渡頁面,把加載首頁的內容最小化。
找到項目中res/xml目錄下的config.xml,把你的外網的域名地址添加到配置中
<access origin="http://example.com" /> <!--allow any secure requests to example.com -->
<access origin="http://example.com" /> <!--allow any secure requests to example.com -->