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
Using java Syntax Highlighting
- package com.oxlet_wtn.android.browserintent;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.KeyEvent;
- import android.content.Intent;
- import android.net.Uri;
- import android.view.View.OnClickListener;
- import android.view.View.OnKeyListener;
- import android.widget.EditText;
- import android.widget.Button;
- public class browserintent extends Activity {
- private EditText urlText;
- private Button goButton;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- urlText =(EditText)findViewById(R.id.url_field);
- goButton=(Button)findViewById(R.id.go_button);
- goButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- openBrowser();
- }
- });
- urlText.setOnKeyListener(new OnKeyListener() {
- @Override
- public boolean onKey(View v, int keyCode, KeyEvent event) {
- // TODO Auto-generated method stub
- if (keyCode==KeyEvent.KEYCODE_ENTER){
- openBrowser();
- return true;
- }
- return false;
- }
- });
- }
- public void openBrowser(){
- Uri uri=Uri.parse(urlText.getText().toString());
- Intent intent=new Intent(Intent.ACTION_VIEW,uri);
- startActivity(intent);
- }
- }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
Follow is main.xml :
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <EditText
- android:id="@+id/url_field"
- android:layout_weight="1.0"
- android:lines="1"
- android:inputType="textUri"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:imeOptions="actionGo"
- android:text="http://"
- />
- <Button
- android:id="@+id/go_button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/go_button"/>
- </LinearLayout>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4
and this is string.xml :
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <string name="hello">Hello World, browserintent!</string>
- <string name="app_name">Browser Intent</string>
- <string name="go_button">Go</string>
- </resources>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4
My tutorial is over this time. May be useful for you all.
@laabroo

