Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Mad Assignment 10

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

MAD ASSIGNMENT 10

Name:Aniket Joshi

Roll No:09

DIV: N

Prn: 12310510

Implement an application to make a phone call


XML:

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

<!--Relative Layout-->

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<!-- Edit text for phone number -->

<EditText

android:id="@+id/editText"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:layout_marginTop="30dp" />

<!-- Button to make call -->

<Button

android:id="@+id/button"
android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentStart="true"

android:layout_alignParentTop="true"

android:layout_alignParentEnd="true"

android:layout_alignParentBottom="true"

android:layout_marginStart="168dp"

android:layout_marginTop="157dp"

android:layout_marginEnd="155dp"

android:layout_marginBottom="526dp"

android:padding="5dp"

android:text="Make Call!!" />

</RelativeLayout>

JAVA:
package com.example.callingassignment;

import android.annotation.SuppressLint;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

import android.widget.Button;

import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

// define objects for edit text and button

EditText edittext;

Button button;

@SuppressLint("MissingInflatedId")

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Getting instance of edittext and button

button = findViewById(R.id.button);

edittext = findViewById(R.id.editText);

// Attach set on click listener to the button for initiating intent

button.setOnClickListener(arg -> {

// getting phone number from edit text and changing it to

String

String phone_number = edittext.getText().toString();

// Getting instance of Intent with action as ACTION_CALL

Intent phone_intent = new Intent(Intent.ACTION_CALL);

// Set data of Intent through Uri by parsing phone number

phone_intent.setData(Uri.parse("tel:" + phone_number));

// start Intent

startActivity(phone_intent);

});}

OUTPUT:

You might also like