4 Create an Android Application which receives URL form the user and open appropriate page in the system browser with the help of Implicit Intents using Android Studio.

Activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 

 xmlns:android="http://schemas.android.com/apk/res/android"                                          xmlns:app="http://schemas.android.com/apk/res-auto"                                                 xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

 android:layout_height="wrap_content"

 tools:context=".MainActivity" 

android:orientation="vertical">

<EditText 

    android:layout_width="match_parent" 

    android:layout_height="wrap_content" 

    android:id="@+id/url" 

    android:hint="Enter URL"/>

<Button

    android:layout_width="match_parent" 

    android:layout_height="wrap_content" 

    android:id="@+id/button1" 

    android:text="Go to URL" 

    android:layout_gravity="center" 

    android:onClick="URI"/>


</LinearLayout>

Layout Preview:



MainActivity.java:

package com.uday.android.a5a4_lc5; 

import android.content.Intent; 

import android.net.Uri;

import android.os.Bundle; 

import android.view.View;

import androidx.appcompat.app.AppCompatActivity; 

public class MainActivity extends AppCompatActivity 

{

    @Override

    protected void onCreate(Bundle savedInstanceState) 

{                  

             super.onCreate(savedInstanceState); 

            setContentView(R.layout.activity_main);

}

public void URI(View view) 

{

        Uri u = Uri.parse("https://www.google.com"); 

       Intent i = new Intent(Intent.ACTION_VIEW,u); 

       startActivity(i);

}

}

OUTPUT:



Post a Comment

0 Comments