[英]WebView - WebPage not available
我(和許多其他人一樣)遵循了 webview 教程,但我無法加載頁面。 一切都顯示為“網頁不可用”
我已確保模擬器確實具有 inte.net 訪問權限,並且只是為了排除模擬器的問題,我嘗試將其安裝在我的手機上,這導致了相同的行為。
我讀到最大的問題是人們沒有將INTE.NET
權限放入我的清單文件中,我曾嘗試將其作為清單中不同元素的子元素放入但無濟於事。 有誰知道為什么我無法加載它?
這是我的代碼:
Manifest:
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".AndroidTestActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<uses-permission android:name="android.permission.INTERNET" />
</activity>
</application>
</manifest>
AndroidTestActivity
public class AndroidTestActivity extends Activity {
WebView webview;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://www.google.com/m");
Intent intent = getIntent();
// To get the action of the intent use
System.out.println(intent.getAction());
// We current open a hard-coded URL
try {
webview.setWebViewClient(new AndroidTestClient());
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
webview.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
private class AndroidTestClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
謝謝!
您的互聯網許可應該是“清單”的直接子項 - 不應該在“申請”下。
例如
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypackage.name"
android:installLocation="auto"
android:versionCode="3210" android:versionName="1.1.0">
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk android:minSdkVersion="6" android:targetSdkVersion="10"/>
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<!-- activities go here -->
</application>
</manifest>
希望這有助於-serkan
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.