0

我有以下代码,但是当我运行它时,它告诉我“http://www.google.com”不可用,这完全是垃圾。如果我在没有HelloWebViewClient全班的情况下运行代码,它会正确打开 google,但在预装的 Android 浏览器中除外。我想在应用程序中打开它。谢谢。

我的代码:

public class MainActivity extends Activity {    
    Button btnGo;
    Editable guiNumber;
    WebView webView;

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

        btnGo = (Button) findViewById(R.id.btnGo);
        webView = (WebView) findViewById(R.id.viewWeb);

        webView.setVisibility(View.GONE);
        webView.setWebViewClient(new HelloWebViewClient());
        webView.getSettings().setJavaScriptEnabled(true);

        btnGo.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                guiNumber = enterGUI.getText();

                if (guiNumber.length() == 8) {
                    guiNumber.replace(4, 8, "");
                    gui = Integer.parseInt(enterGUI.getText().toString());
                    System.out.println(gui);

                    InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
                    imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

                    webView.setVisibility(View.VISIBLE);
                    webView.requestFocus();
                    webView.loadUrl("http://google.com");
                }
                else {
                    enterGUI.setError("Your GUI/ILGU number must be 8 digits long");
                }
            }
        });
    }

    private class HelloWebViewClient extends WebViewClient {

          public boolean shouldOverrideUrlLoading(WebView view, String url) {
           view.loadUrl(url);
           return true;
          }
    }
}

和清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.frostplant.clublink" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="6" android:targetSdkVersion="15"/>
<uses-permisssion android:name="android.permission.INTERNET"/>
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme">
<activity android:name=".MainActivity" android:label="@string/title_activity_main">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
4

2 回答 2

3

授予您的应用程序访问 Internet 的权限:android.permission.INTERNET这将允许您的应用程序使用网络。

于 2012-07-17T16:11:29.417 回答
1

You have mistakenly typed 3 "s"s in your permission line:

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

This should be:

<uses-permission android:name="android.permission.INTERNET"/>
于 2012-07-17T18:22:04.840 回答