Friday, December 09, 2011
Browser Calling in Android :
# We have to open an URL as "www.google.com" by calling android browser :
// Source Code of registration.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<WebView
android:id="@+id/mywebview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
// Source Code of InternetSurfActivity.xml :
package com.myApp.InternetSurf;
import android.webkit.WebView;
import android.app.Activity;
import android.os.Bundle;
public class InternetSurfActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView wv=(WebView) findViewById(R.id.mywebview);
wv.loadUrl("http://www.google.com");
}
}
Output :
# We have to open an URL as "www.google.com" by calling android browser :
- Create a new project named as "InternetSurf" and class name will be such as "InternetSurfActivity.java".
- Create an xml file named as "mywebview.xml" and copy and paste below code to this xml file.
// Source Code of registration.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<WebView
android:id="@+id/mywebview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
// Source Code of InternetSurfActivity.xml :
package com.myApp.InternetSurf;
import android.webkit.WebView;
import android.app.Activity;
import android.os.Bundle;
public class InternetSurfActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView wv=(WebView) findViewById(R.id.mywebview);
wv.loadUrl("http://www.google.com");
}
}
Output :

Author: Mohammad
Mohammad is the founder of STC Network which offers Web Services and Online Business Solutions to clients around the globe. Read More →
Related Posts:
Subscribe to:
Post Comments (Atom)
0 comments: