如何在不打开浏览器的情况下查看 Android 应用程序中的网页?

2024-05-25

嘿,我正在开发一个 Android 应用程序,我想连接到该应用程序内的网络。不过,我在某种程度上尝试过 WebView,但它在我的目录中显示的文件很好,但当连接到 google.com 时,它显示错误!

然后我添加了这个文件<uses-permission android:name="android.permission.INTERNET" />

在我的 Manifest.xml 中,现在 url(google.com) 显示在浏览器中 有什么帮助我可以在我的应用程序中打开浏览器吗?


使用网络视图。

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class WebViewDemo extends Activity 
{
    private WebView mWebView = null;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mWebView = (WebView) findViewById(R.id.webView);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.loadUrl("http://www.google.com/");
    }
}

add <uses-permission android:name="android.permission.INTERNET" />在清单文件中。

这里使用的main.xml 文件。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<WebView  
        android:id="@+id/webView"
        android:scrollbars="none" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />
</LinearLayout>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在不打开浏览器的情况下查看 Android 应用程序中的网页? 的相关文章

随机推荐