fir daus
fir daus

Reputation: 3

Open url in webview

I am new here in Android dev. In the below code, it will open up the Android browser.

1.Is there any possible way that i can do to open the url (matricNo) in webView instead of in Android browser without having to build new java file as in this link?

final void addToAttendance(String matricNo) {
String url =  matricNo;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
activity.startActivity(intent);  
}

Upvotes: 0

Views: 3853

Answers (2)

Anjali
Anjali

Reputation: 206

In Activity

public void onClick(View v) 
            {
                // TODO Auto-generated method stub
                //Context context = null;
                Intent intent=new Intent(MainActivity.this,WebActivity.class);
                intent.setData(Uri.parse("www.javacodegeeks.com"));
                startActivity(intent);  
            }
        });

In Another Activity

 WebView wv=(WebView)findViewById(R.id.webView1);
         wv.getSettings().setJavaScriptEnabled(true);
         wv.loadUrl(this.getIntent().getDataString());

Upvotes: 8

Jitesh Dalsaniya
Jitesh Dalsaniya

Reputation: 1917

Use following code.

public class WebViewActivity extends Activity {

    private WebView webView;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview);

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

    }

}

webview.xml

 <?xml version="1.0" encoding="utf-8"?>
 <WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
 />

Upvotes: 0

Related Questions