Friday, 15 June 2012

Accessing Android Default Browser To Access A site Through Java Code


<?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" >
 
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="www.refisoft.blogspot.in" />
 
</LinearLayout>

package com.refisoft;

import android.app.Activity;
import android.content.Intent;

import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class RefisoftActivity extends Activity implements
  OnClickListener {
 Button button;
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  button = (Button) findViewById(R.id.button1);
  button.setOnClickListener(this);
 }

 public void onClick(View v) {
  // TODO Auto-generated method stub
  if (v.getId() == R.id.button1) {
    Intent tobrowser = 
                 new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.refisoft.blogspot.in"));
     startActivity(tobrowser);

  }

 }

}





AndroidManifest.xml Add Like this For Internet permission


<uses-permission android:name="android.permission.INTERNET"></uses-permission>



Thanks All...........................................................................







1 comment: