Halaman

Jumat, 20 Januari 2012

Creating Web View on Android


How to Creat Web View on Android

To create a program that can display the page url in the Android can be done using WebView object (for an explanation WebView search on google yah).
 In this case, for example we want to create a program to open the page http://vicky-cyber.blogspot.com
 
1. Creat New Project, then input the following parameters:
 
 
1
Creating a New ProjectClick Finish if all parameters are filled,



2. Open File main.xml exist in the folder / OpenWeb / res / layout /
  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  3.     android:orientation="vertical" 
  4.     android:layout_width="fill_parent" 
  5.     android:layout_height="fill_parent" 
  6.     > 
  7. <WebView 
  8.     android:id="@+id/webview1" 
  9.     android:layout_width="fill_parent" 
  10.     android:layout_height="fill_parent" 
  11.     /> 
  12. </LinearLayout> 
  13.   
3. Open File openweb.java exist in the folder / OpenWeb / src / com / unikomcenter / OpenWeb / 
  1. package com.unikomcenter.openweb; 
  2.  
  3. import android.app.Activity; 
  4.  
  5. import android.os.Bundle; 
  6. import android.webkit.WebView; 
  7.  
  8. public class openweb extends Activity { 
  9.     WebView browser; 
  10.     /** Called when the activity is first created. */ 
  11.     @Override 
  12.     public void onCreate(Bundle unikomcenter) { 
  13.         super.onCreate(unikomcenter); 
  14.         setContentView(R.layout.main); 
  15.         browser=(WebView) findViewById(R.id.webview1); 
  16.         browser.loadUrl("http://m.unikom.ac.id/"); 
  17.         // alamat url yang akan dibuka 
  18.     } 
  19.   
3. Open File Manifesto that exist in the folder / OpenWeb / AndroidManifest.xml
  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
  3.       package="com.unikomcenter.openweb" 
  4.       android:versionCode="1" 
  5.       android:versionName="1.0"> 
  6.       <uses-permission android:name="android.permission.INTERNET" /> 
  7.       //Meminta permisi supaya bisa menggunakan jalur Internet 
  8.  
  9.  
  10.  
  11.     <application android:icon="@drawable/icon"         android:label="@string/app_name"> 
  12.         <activity android:name=".openweb" 
  13.                   android:label="@string/app_name"> 
  14.             <intent-filter> 
  15.                 <action android:name="android.intent.action.MAIN" /> 
  16.                 <category android:name="android.intent.category.LAUNCHER" /> 
  17.             </intent-filter> 
  18.         </activity> 
  19.     </application> 
  20. </manifest> 
When Completed, please Run, and here is the output Web page with pemgrograman Android Open.
1
The program output in the Android Emulator
1


Note:Have been tried in samsung tab, and samsung y