我在我的Android應用程序中使用了一個名爲AndEngine(我完全陌生)的遊戲引擎。我需要根據屏幕上的遊戲杆位置(上傳到.cgi服務器)從應用程序加載不同的URL。困境是我無法打開URL連接!這看起來可能很簡單,但我已到處尋找,嘗試了多種解決方案,而且沒有任何工作。在基本的Android中,我一直使用WebView(loadUrl()方法),並且運行良好。但是,我不知道如何在使用AndEngine的情況下創建webview。我的首選是連接沒有顯示(加載在AndEngine場景下面),因爲我需要屏幕來處理其他事情。我也嘗試了其他解決方案。我只是嘗試這樣的代碼,但是當我檢查了服務器,什麼也沒有開通:如何在AndEngine中使用webview或打開網址 - Android
@Override
public void onLoadResources() {
//methods n/a to this question
try {
URL url = new URL(setUrl);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
readStream(con.getInputStream());
} catch (Exception e) {
e.printStackTrace();
}
return scene; // AndEngine return statement
}
private void readStream(InputStream in) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(in));
String line = "";
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
**我用HTTPConnection類之前(不含AndEngine)打開一個URL試過,但無濟於事。所以這可能是我在這裏做錯了事。使用AndEngine GLES2。如果需要更多信息,請告訴我(這是我的第一個問題)。
也試過用
@Override
protected int getLayoutID() {
return R.layout.main;
}
上AndEngine建立我的.xml佈局,但它說:「型控制方法getLayoutID()必須覆蓋或實現超法」
編輯對Nicolas Gramlich的迴應:設置了Internet權限,編譯器最初爲1.6。仍然不知道問題是什麼。
我想在Android中使用AndEngine,在mycase中,我想用webview打開一個新的活動,但是當我這樣做時,它會花費太多時間來加載新視圖...任何想法在這裏。 – CoDe 2012-08-10 08:20:20
你能再詳細一點嗎?你是否想要打開一個包含webview的新活動?而且我也體驗過webview加載速度有點慢,這取決於我的連接 – davanp 2012-08-11 00:17:35