Thursday, 9 August 2012

Open a URL in the default browser with button(Android)

package app.Test;

import com.test.android.R;

import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.net.Uri;
import android.view.KeyEvent;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.View;
import android.widget.Button;

 public class appTest extends Activity {

    private Button btn;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        BtnListener();
   }

   private void BtnListener() {
        Button btn = (Button) findViewById(R.id.button1);
        btn.setOnClickListener(new OnClickListener(){
            public void onClick(View arg0){              
                Intent i = new Intent(Intent.ACTION_VIEW,Uri.parse("http://google.com");
                    startActivity(i);
            }
        });   
    }
}

No comments:

Post a Comment