Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we view webpages in our android application without opening browser?

Hey i am developing an android application , and i want to connect to web inside that application. However i have tried WebView to someextent but its displaying file's on my directory fine but when connecting to google.com it display's an error !

Then i added this file <uses-permission android:name="android.permission.INTERNET" />

in my Manifest.xml and now the the url(google.com) is being displayed in the browser Any help how i can open the browser inside my application ?

like image 868
Anuj Avatar asked Dec 12 '22 11:12

Anuj


2 Answers

Using webview.

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" /> in manifest file.

main.xml file which used here.

<?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>
like image 136
Chirag Avatar answered Dec 22 '22 00:12

Chirag


Another way to do this is via Intents:

Uri uri = Uri.parse("http://www.gmail.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

You need to specify permission in manifest file

    <uses-permission android:name="android.permission.INTERNET" />
like image 22
Sumit Avatar answered Dec 21 '22 22:12

Sumit