[英]WebView - WebPage not available
I (like many others) followed the webview tutorial, but I can't get pages to load.我(和许多其他人一样)遵循了 webview 教程,但我无法加载页面。 Everything comes up as 'Webpage not Available'
一切都显示为“网页不可用”
I have ensured that the emulator does have inte.net access, and just to rule out a problem with the emulator I tried installing it on my phone, which resulted in the same behavior.我已确保模拟器确实具有 inte.net 访问权限,并且只是为了排除模拟器的问题,我尝试将其安装在我的手机上,这导致了相同的行为。
I have read that the biggest issue is people not putting the INTE.NET
permission in my manifest file, which I have tried putting as a child of different elements in the manifest to no avail.我读到最大的问题是人们没有将
INTE.NET
权限放入我的清单文件中,我曾尝试将其作为清单中不同元素的子元素放入但无济于事。 Does anyone know why I can't get this to load?有谁知道为什么我无法加载它?
Here is my code:这是我的代码:
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;
}
}
}
Thanks!谢谢!
Your internet permission should be an immediate child of "manifest" - shouldn't be under "application". 您的互联网许可应该是“清单”的直接子项 - 不应该在“申请”下。
eg 例如
<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>
Hope this helps -serkan 希望这有助于-serkan
If you use VPN
, it can lead to this error.如果您使用
VPN
,可能会导致此错误。 I connected to VPN and started an emulator, then WebView showed an error:我连接到 VPN 并启动了一个模拟器,然后 WebView 显示错误:
I disconnected from the VPN, restarted the emulator, and web page loaded.我断开了与 VPN 的连接,重新启动了模拟器,并加载了 web 页面。 Of course, I wrote
<uses-permission android:name="android.permission.INTE.NET" />
in AndroidManifest.当然,我在AndroidManifest中写了
<uses-permission android:name="android.permission.INTE.NET" />
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.