android - WebView 页面不可用 - Android

标签 android android-webview

我有一个应该显示 www.google.com 的基本 WebView 应用程序。虽然可以通过内置浏览器访问该网站,但我无法从 WebView 访问该网站。我在各种论坛上浏览了大量问题并采纳了所有建议,但似乎没有任何效果。我已确保:
1. 允许互联网访问的 uses-permission 标签是 manifest 标签的子标签。
2. 为WebView启用javascript。
list 文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sriram.hellowebview"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.INTERNET"></uses-permission>

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".helloWebview"
            android:label="@string/title_activity_hello_webview" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>  

布局:

<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

   <WebView
       android:id="@+id/helloWebview"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
     />
</LinearLayout>  

代码:

/* Program to create sample webview.
 * Steps:
 * 1. Create webview.
 * 2. Show some website in it.
 * 3. Show some transitions as well.
 */

package com.sriram.hellowebview;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.webkit.WebView;

public class helloWebview extends Activity {

    WebView myWebview;
    String url = "www.google.com";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hello_webview);

        Log.v(this.toString(), "Starting activity.");

        myWebview = (WebView) findViewById(R.id.helloWebview);

        Log.v(this.toString(), "Getting settings.");
        myWebview.getSettings().setJavaScriptEnabled(true);

        Log.v(this.toString(), "Loading URL now.");
        myWebview.loadUrl(url);
        Log.v(this.toString(), "Loaded URL.");

        //open all links within the same webview.
        //myWebview.setWebViewClient(new WebViewClient());
        //Log.v(this.toString(), "All done here.");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_hello_webview, menu);
        return true;
    }
}

最佳答案

String url = "https://www.google.co.in/";

否则

super.loadUrl("https://www.google.co.in//");

关于android - WebView 页面不可用 - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15631861/

相关文章:

android - Webview 从 assets 目录加载所有 HTML 文件

Android 4.4.2(api级别= 19)Webview问题

android - repo 和 jiri 的主要区别是什么?

android - 来自多个文件的 SharedPreferences

android - SQLite 和填充 ListView ,android

android - 如何知道android手机何时连接了adb

android - Google Maps Platform 拒绝了您的请求。 'pb' 参数无效

android - singleCursorHandlerTouchEvent -getEditableSupport FASLE 错误

android - 在PagerAdapter中预加载Fragment的WebView

android - 使用不包含MediaQuery的上下文调用MediaQuery.of()。错误