As I was trying to play around with WebKit, I tried to load an web page through it in Android. A good starting point for WebKit may be found at
http://developer.apple.com/documentation/Cocoa/Conceptual/DisplayWebContent/DisplayWebContent.html .
The source code of my android application is pretty straight forward.
It goes like this:
public class WebKitExample extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webView;
setContentView(R.layout.main);
webView = (WebView)findViewById(R.id.appView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.google.com");
}
}
We need to add the XML resource in the main.layout as the following:
(WebView android:id="@+id/appView"
android:layout_height="wrap_content"
android:layout_width="fill_parent" /)
We also need to add the permission to the manifest file as the following:
(uses-permission android:name = "android.permission.INTERNET" /)
And the application will look like the following in the emulator.
Although the example shown here is pretty simple but it can be a starting point in learning Webkit in Android. Hope this helps the newbies of Android.
No comments:
Post a Comment