make web browser in android

Tutorials with advanced 'difficulty' and more Lines of Code.

make web browser in android

Postby bhynte » Tue Sep 28, 2010 9:46 am

Hellow am a anewbies in forum. This time i want to post tutorial <b>MAKE WEBBROWSER IN ANDROID</b>. OK Lest go... :D

Make Projek in Eclipse as follows :
Projek Name : BrowserIntent
Build Target: Android 2.2
Application name: BrowserIntent
Package name: com.oxlet_wtn.android.browserintent
Create Activity: BrowserIntent
Min SDK Version: 8

follow is browserintent.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package com.oxlet_wtn.android.browserintent;
  3.  
  4. import android.app.Activity;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.view.KeyEvent;
  8. import android.content.Intent;
  9. import android.net.Uri;
  10. import android.view.View.OnClickListener;
  11. import android.view.View.OnKeyListener;
  12. import android.widget.EditText;
  13. import android.widget.Button;
  14.  
  15. public class browserintent extends Activity {
  16.         private EditText urlText;
  17.         private Button goButton;
  18.     /** Called when the activity is first created. */
  19.     @Override
  20.     public void onCreate(Bundle savedInstanceState) {
  21.         super.onCreate(savedInstanceState);
  22.         setContentView(R.layout.main);
  23.  
  24.         urlText =(EditText)findViewById(R.id.url_field);
  25.          goButton=(Button)findViewById(R.id.go_button);
  26.          goButton.setOnClickListener(new OnClickListener() {
  27.  
  28.                         @Override
  29.                         public void onClick(View v) {
  30.                                 // TODO Auto-generated method stub
  31.                                 openBrowser();
  32.                         }
  33.                 });
  34.  
  35.          urlText.setOnKeyListener(new OnKeyListener() {
  36.  
  37.                         @Override
  38.                         public boolean onKey(View v, int keyCode, KeyEvent event) {
  39.                                 // TODO Auto-generated method stub
  40.                                 if (keyCode==KeyEvent.KEYCODE_ENTER){
  41.                                         openBrowser();
  42.                                         return true;
  43.                                 }
  44.  
  45.                                 return false;
  46.                         }
  47.                         });
  48.  
  49.     }
  50.  
  51.     public void openBrowser(){
  52.         Uri uri=Uri.parse(urlText.getText().toString());
  53.         Intent intent=new Intent(Intent.ACTION_VIEW,uri);
  54.         startActivity(intent);
  55.     }
  56.  
  57. }
  58.  
  59.  
  60.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4



Follow is main.xml :
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:orientation="horizontal"
  4.    android:layout_width="fill_parent"
  5.    android:layout_height="fill_parent"
  6.    >
  7. <EditText
  8. android:id="@+id/url_field"
  9. android:layout_weight="1.0"
  10. android:lines="1"
  11. android:inputType="textUri"
  12.    android:layout_width="wrap_content"
  13.    android:layout_height="wrap_content"
  14.    android:imeOptions="actionGo"
  15. android:text="http://"
  16.  
  17.    />
  18.  
  19.    <Button
  20.   android:id="@+id/go_button"
  21.   android:layout_width="wrap_content"
  22.   android:layout_height="wrap_content"
  23.   android:text="@string/go_button"/>
  24. </LinearLayout>
  25.  
  26.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


and this is string.xml :
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <resources>
  3.     <string name="hello">Hello World, browserintent!</string>
  4.     <string name="app_name">Browser Intent</string>
  5. <string name="go_button">Go</string>
  6. </resources>
  7.  
  8.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


My tutorial is over this time. May be useful for you all. :D :D :D @laabroo
litle programer Android
User avatar
bhynte
Freshman
Freshman
 
Posts: 2
Joined: Tue Sep 21, 2010 6:55 am

Top

Re: make web browser in android

Postby shutup7742 » Sat Jan 29, 2011 6:00 pm

You got to remember to insert your permissions into the manifest. in this case you will have to put:
<uses-permission android:name="android.permission.INTERNET"/>
Check out our site: http://www.hot-app.com.
Make money online: http://www.cashcrate.com/1226485.
shutup7742
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Jan 29, 2011 1:14 am

Re: make web browser in android

Postby shutup7742 » Sat Jan 29, 2011 6:41 pm

also I am getting 3 errors, 2 of them seem to be Listeners and the on is a key event. can you help with this?
Code: Select all
goButton.setOnClickListener(new OnClickListener()
urlText.setOnKeyListener(new OnKeyListener()
public boolean onKey(View v, int keyCode, KeyEvent event)
Check out our site: http://www.hot-app.com.
Make money online: http://www.cashcrate.com/1226485.
shutup7742
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Jan 29, 2011 1:14 am


Top

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests