0% found this document useful (0 votes)
19 views2 pages

Practical 18.2

The document contains an XML layout file for an Android application with a single button labeled 'Start Dialer'. It also includes a Java class for the MainActivity that sets up an onClickListener for the button to open the dialer when clicked. The intent created does not pre-fill any phone number in the dialer.

Uploaded by

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

Practical 18.2

The document contains an XML layout file for an Android application with a single button labeled 'Start Dialer'. It also includes a Java class for the MainActivity that sets up an onClickListener for the button to open the dialer when clicked. The intent created does not pre-fill any phone number in the dialer.

Uploaded by

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

18.2 activity_main.

xml

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


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="24dp">

<Button
android:id="@+id/dialerButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Dialer"
android:padding="12dp" />
</LinearLayout>

18.2 MainActivity.java

package com.example.practical17;

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

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

Button dialerButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

dialerButton = findViewById(R.id.dialerButton);

dialerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Create intent to open dialer
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:")); // No number is pre-filled
startActivity(intent);
}
});
}
}
18.2 Output

You might also like