简体   繁体   中英

Do I need to set Internet permission for opening a website in Android?

In my activity I have some links that when user click on it, WebView will open and load a page from Internet.

My Question is, do I have to set permission in manifest file for accessing Internet? Because when I run the program, emulator says web page is not available.

My code is:

final TextView tv01 = (TextView) findViewById(R.id.pck_01);


        final WebView wv = new WebView(this);
        tv01.setOnClickListener(new View.OnClickListener() {    
            @Override
            public void onClick(View v) {
                wv.loadUrl("http://www.stackoverflow.com");
                setContentView(wv);
            }
        });

Yes you will need to have the following permission added to the manifest to access and URL outside of the device:

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

Seems to be confirmed here as well:

Does Android WebView need permissions for opening external URLs?

android.permission.INTERNET is required, however: there is a way around this . If you just want to launch a web page in a separate browser app, you don't need permission at all.

Just do:

public void launchURL(String urlString)
{
        Uri uri = Uri.parse(urlString);
        Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(launchBrowser);
}

You need

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

in your manifest if you want to use webviews in your application.

Yes, set android.permission.INTERNET in your android manifest file. Read some details about Webview here

You will need the following in your Android Manifest:

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

Check out this page for more information on the Android Manifest.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM