Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
8 views7 pages

MAD18

The document contains two Android application implementations that utilize XML layouts and Java code. The first implementation allows users to enter a URL and navigate to it using an implicit intent, while the second implementation enables users to dial a phone number entered in an EditText field. Both applications employ edge-to-edge design and handle user interactions through buttons.

Uploaded by

pratikdlagade02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views7 pages

MAD18

The document contains two Android application implementations that utilize XML layouts and Java code. The first implementation allows users to enter a URL and navigate to it using an implicit intent, while the second implementation enables users to dial a phone number entered in an EditText field. Both applications employ edge-to-edge design and handle user interactions through buttons.

Uploaded by

pratikdlagade02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Intent18:

Xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:gravity="center">

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Your URL here"
android:id="@+id/editUri"
android:layout_margin="20dp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editUri"
android:text="Navigate"
android:id="@+id/btn"
android:onClick="ImplicitIntent"
android:layout_centerHorizontal="true"/>
</RelativeLayout>

Java file:
package com.tmsimple.intent18;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {


EditText texturl;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
texturl=findViewById(R.id.editUri);
}
public void ImplicitIntent(View view){
Intent intent =new Intent(Intent.ACTION_VIEW,
Uri.parse(texturl.getText().toString()));
startActivity(intent);
}
}

Output:
Intent2:
Xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:gravity="center">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edit1"
android:hint="Enter the Phone Number"
android:inputType="phone"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/edit1"
android:layout_centerHorizontal="true"
android:layout_margin="20dp"
android:text="Dial"
android:id="@+id/btn"
/>
</RelativeLayout>

Java file:
package com.tmsimple.intent18;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

EditText number;
Button dial;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
number=findViewById(R.id.edit1);
dial=findViewById(R.id.btn);

dial.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "Clicked on Dial",
Toast.LENGTH_SHORT).show();
Uri uri=Uri.parse("tel:"+number.getText().toString());

Intent intent=new Intent(Intent.ACTION_DIAL,uri);


try {
startActivity(intent);
}catch (SecurityException s){
Toast.makeText(MainActivity.this, "An error Occured",
Toast.LENGTH_SHORT).show();
}
}
});

}
}
Output:

You might also like