GTU DE Sem6 – 3360704 – 4 – Create and Login application as above On successful login open browser with any URL

GTU DE Sem6 – 3360704 – 4 – Create and Login application as above On successful login open browser with any URL

1

This program explain how to Browser Intent. This example explain how to verify user details and if it is correct redirect them to some website using Browser Intent. To move to another activity in Android basically used Intent. So here again we have to use Intent to move but Here we are not going to another activity instead we want to move to browser. Kindly refer following code for the same.

Jump to Android Program 5

FileName: MainActivity.java

/*

Mobile Computing and Application Development : 3360704

GTU DE Sem6 - 3360704 - 4 - Create and Login application as above . On successful login , open browser with any URL
  
*/

package gtu.de.mcad.ex04;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {

	EditText et1,et2;
	Button b1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		et1 = (EditText) findViewById(R.id.editText1);
		et2 = (EditText) findViewById(R.id.editText2);
		b1 = (Button) findViewById(R.id.button1);
		
		b1.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
			
				String s1 = et1.getText().toString();
				String s2 = et2.getText().toString();
				
				if(s1.equals("admin") && s2.equals("admin"))
				{
					Intent i= new Intent("android.intent.action.VIEW");
					i.setData(Uri.parse("http://www.adarshspatel.in"));
					startActivity(i);
				}
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		
		return super.onOptionsItemSelected(item);
	}
}

 FileName: activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText1"
        android:layout_marginTop="52dp"
        android:layout_toLeftOf="@+id/editText2"
        android:text="Password"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText1"
        android:layout_alignTop="@+id/textView2"
        android:ems="10"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText2"
        android:layout_centerHorizontal="true"

 

Output

DE Sem6 - 3360704 - 4 - Create and Login application as above . On successful login , open browser with any URL

Output

DE Sem6 - 3360704 - 4 - Create and Login application as above . On successful login , open browser with any URL

Leave a Reply