Ilovepdf Merged

Download as pdf or txt
Download as pdf or txt
You are on page 1of 61

ASSIGNMENT – 1

a) Installation of Android Studio.


To install Android Studio, follow these steps:
1. Download Android Studio:
- Visit the official [Android Studio download page](https://developer.android.com/studio).
- Click on the "Download Android Studio" button and agree to the terms and conditions to start the
download.
2. Install Android Studio:
- Open the downloaded file.
- Follow the on-screen instructions to complete the installation.
3. Set Up Android Studio:
- Launch Android Studio.
- Complete the setup wizard, which includes downloading the Android SDK and other necessary
components.
4. Create a New Project:
- Open Android Studio and select "Start a new Android Studio project."
- Follow the prompts to configure your new project.
5. Configure SDK Manager:
- Go to Tools > SDK Manager to ensure you have the necessary SDK platforms and tools installed.
6. Install Emulator (Optional):
- Go to Tools > AVD Manager and create a new virtual device if you plan to test your apps on an emulator.
Once you've completed these steps, you'll be ready to start developing Android applications.
b) Create an Android app to run the first mobile app of the Hello World Application.

1) Select Start a new Android Studio project

2) Provide the following information: Application name, Company domain, Project location and
Package name of application and click next.

3) Select the API level of application and click next.

4) Select the Activity type (Empty Activity).

5) Provide the Activity Name and click finish

After finishing the Activity configuration, Android Studio auto generates the activity class and other
required configuration files. Now an android project has been created. You can explore the android
project and see the simple program.

CODE

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


2. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/
android"
3. xmlns:app="http://schemas.android.com/apk/res-auto"
4. xmlns:tools="http://schemas.android.com/tools"
5. android:layout_width="match_parent"
6. android:layout_height="match_parent"
7. tools:context="first.java.com.welcome.MainActivity">
8.
9. <TextView
10. android:layout_width="wrap_content"
11. android:layout_height="wrap_content"
12. android:text="Hello Android!"
13. app:layout_constraintBottom_toBottomOf="parent"
14. app:layout_constraintLeft_toLeftOf="parent"
15. app:layout_constraintRight_toRightOf="parent"
16. app:layout_constraintTop_toTopOf="parent" />
17.
18. </android.support.constraint.ConstraintLayout>
19. }

MAIN ACTIVITY,JAVA

1. package first.java.com.welcome;
2.
3. import android.support.v7.app.AppCompatActivity;
4. import android.os.Bundle;
5.
6. public class MainActivity extends AppCompatActivity {
7. @Override
8. protected void onCreate(Bundle savedInstanceState) {
9. super.onCreate(savedInstanceState);
10. setContentView(R.layout.activity_main);
11. }
12. }

To run the android application, click the run icon on the toolbar or simply press Shift + F10.

c) Create an apk file for Android.


Creating an APK file for an Android application involves several steps:
1. Set Up Your Environment:
- Ensure you have Android Studio installed.
- Set up the Android SDK and necessary build tools.
2. Prepare Your Project:
- Open your project in Android Studio.
- Make sure your code is complete and error-free.
3. Generate Signed APK:
- Go to `Build` > `Generate Signed Bundle / APK`.
- Select `APK` and click `Next`.
4. Configure the Key Store:
- Create a new key store or use an existing one.
- Fill in the required details (key store path, password, key alias, etc.).
5. Build the APK:
- Choose the build variant (usually `release`).
- Click `Finish`.
6. Locate the APK:
- The generated APK file will be found in the `app/release` directory of your project.
Now you have a signed APK file ready for distribution or installation.

d) Create an Android app Change the logo of the Android app.


Changing the logo of an Android app involves updating the app's launcher icon. Here's how to do it:
1. Prepare Your Icon:
- Create your new icon images in various sizes (typically in PNG format) following Android's icon design
guidelines.
2. Replace Existing Icons:
- In Android Studio, navigate to the `res` folder within your project.
- Locate the `mipmap` directories (`mipmap-hdpi`, `mipmap-mdpi`, `mipmap-xhdpi`, `mipmap-xxhdpi`,
`mipmap-xxxhdpi`).
- Replace the existing `ic_launcher.png` files in each `mipmap` directory with your new icon images, ensuring
they match the original sizes.
3. Update the Resource References (if necessary):
- Open the `AndroidManifest.xml` file.
- Ensure the `android:icon` attribute in the `<application>` tag points to the correct icon resource:

```xml

<application

android:icon="@mipmap/ic_launcher"

... >

</application>

```

4. Rebuild the Project:

- Click on `Build` > `Rebuild Project` to ensure all changes are applied.

Your app's logo (launcher icon) will now be updated.

e) Briefly describe about android activity life cycle and implement it.

Android Activity Lifecycle


The Android activity lifecycle consists of several stages, which are callback methods that an activity goes
through from its creation to its destruction. Here are the primary stages:
1. onCreate(): Called when the activity is first created. This is where you initialize your activity.
2. onStart(): Called when the activity becomes visible to the user.
3. onResume(): Called when the activity starts interacting with the user.
4. onPause(): Called when the system is about to put the activity into the background.
5. onStop(): Called when the activity is no longer visible to the user.
6. onDestroy(): Called before the activity is destroyed.
7. onRestart(): Called after the activity has been stopped and just before it is started again.
Implementing the Activity Lifecycle
Here's a simple implementation of the activity lifecycle methods in an Android activity:
```java
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


private static final String TAG = "MainActivity";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG, "onCreate called");
}

@Override
protected void onStart() {
super.onStart();
Log.d(TAG, "onStart called");
}

@Override
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume called");
}

@Override
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause called");
}

@Override
protected void onStop() {
super.onStop();
Log.d(TAG, "onStop called");
}

@Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "onDestroy called");
}

@Override
protected void onRestart() {
super.onRestart();
Log.d(TAG, "onRestart called");
}
}
```
ASSIGNMENT – 2

Create an application that takes the name from a text box and shows a hello message along with the name
entered in the text box when the user clicks the OK button.

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

// These are the global variables

EditText editName, editPassword;

TextView result;

Button buttonSubmit, buttonReset;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

editName = (EditText) findViewById(R.id.editName);

editPassword = (EditText) findViewById(R.id.editPassword);

result = (TextView) findViewById(R.id.tvResult);

buttonSubmit = (Button) findViewById(R.id.buttonSubmit);

buttonReset = (Button) findViewById(R.id.buttonReset);

/*

Submit Button

*/

buttonSubmit.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String name = editName.getText().toString();

String password = editPassword.getText().toString();

result.setText("Name:\t" + name + "\nPassword:\t" + password );

});
/*

Reset Button

*/

buttonReset.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

editName.setText("");

editPassword.setText("");

result.setText("");

editName.requestFocus();

});

activity_main.xml

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

<RelativeLayout 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="match_parent"

android:background="#FFFF8D"

tools:context="com.example.akshay.mrcet.MainActivity">

<TextView

android:id="@+id/textView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true"

android:layout_alignParentTop="true"

android:text="NAME"
android:textSize="20sp"

android:layout_margin="20dp" />

<TextView

android:id="@+id/textView2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textSize="20sp"

android:text="PASSWORD"

android:layout_marginTop="38dp"

android:layout_below="@+id/textView"

android:layout_alignLeft="@+id/textView"

android:layout_alignStart="@+id/textView" />

<EditText

android:id="@+id/editName"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:ems="10"

android:inputType="textPersonName"

android:hint="Enter Name"

android:layout_alignParentTop="true"

android:layout_alignParentRight="true"

android:layout_alignParentEnd="true"

android:layout_alignLeft="@+id/editPassword"

android:layout_alignStart="@+id/editPassword" />

<EditText

android:id="@+id/editPassword"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:ems="10"
android:hint="Enter Password"

android:inputType="textPassword"

android:layout_alignBottom="@+id/textView2"

android:layout_alignParentRight="true"

android:layout_alignParentEnd="true"

android:layout_marginRight="18dp"

android:layout_marginEnd="18dp" />

<Button

android:id="@+id/buttonSubmit"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true"

android:layout_below="@+id/textView2"

android:layout_marginTop="20dp"

android:text="SUBMIT" />

<Button

android:id="@+id/buttonReset"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="RESET"

android:layout_alignBaseline="@+id/buttonSubmit"

android:layout_alignBottom="@+id/buttonSubmit"

android:layout_centerHorizontal="true" />

<TextView

android:id="@+id/tvResult"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"

android:layout_alignParentStart="true"

android:layout_marginBottom="143dp"

android:textSize="30sp" />
ASSIGNMENT – 3

a)Create an Android app and Implement a Linear Layout

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

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

android:id="@+id/Main_View"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

<TextView

android:id="@+id/txtVw"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_margin="16dp"

android:layout_marginTop="20dp"

android:paddingTop="20dp"

android:text="Enter your name here:"

android:textSize="24dp" />

<EditText

android:id="@+id/editText"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_margin="16dp"

android:hint="Name"

android:inputType="text"/>

<Button

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

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:backgroundTint="@color/colorPrimary"

android:text="show"

android:textColor="@android:color/white" />

</LinearLayout>

package com.example.text_view_application

import androidx.appcompat.app.AppCompatActivity

import android.os.Bundle

import android.widget.Button

import android.widget.EditText

import android.widget.TextView

import androidx.activity.ComponentActivity

import androidx.activity.compose.setContent

import androidx.activity.enableEdgeToEdge

import androidx.compose.foundation.layout.fillMaxSize

import androidx.compose.foundation.layout.padding

import androidx.compose.material3.Scaffold

import androidx.compose.material3.Text

import androidx.compose.runtime.Composable

import androidx.compose.ui.Modifier

import androidx.compose.ui.tooling.preview.Preview

import com.example.text_view_application.ui.theme.Text_View_ApplicationTheme

class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

enableEdgeToEdge()

setContentView(R.layout.activity_main)
val showButton:Button = findViewById(R.id.showInput)

val editText:EditText = findViewById(R.id.editText)

val textView:TextView = findViewById(R.id.txtVw)

b)Create an Android app to add, and subtract two numbers supplied from a user interface having two text
boxes.
Set up the project: Create a new project in Android Studio.
Design the layout: Add two EditText views for input, two Buttons for add and subtract actions, and a
TextView for displaying the result.
Implement the logic: Add onClick listeners for the buttons to perform the add and subtract operations based
on user input and display the result.
package com.example.add_two_numbers;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
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 number1;
EditText number2;
Button Add_button;
TextView result;
int ans=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// by ID we can use each component which id is assign in xml file
number1=(EditText) findViewById(R.id.editText_first_no);
number2=(EditText) findViewById(R.id.editText_second_no);
Add_button=(Button) findViewById(R.id.add_button);
result = (TextView) findViewById(R.id.textView_answer);
// Add_button add clicklistener
Add_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// num1 or num2 double type
// get data which is in edittext, convert it to string
// using parse Double convert it to Double type
double num1 = Double.parseDouble(number1.getText().toString());
double num2 = Double.parseDouble(number2.getText().toString());
// add both number and store it to sum
double sum = num1 + num2;
// set it ot result textview
result.setText(Double.toString(sum));
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView_answer"
android:layout_width="100dp"
android:layout_height="25dp"
android:text="0"
android:layout_marginLeft="130dp"
android:layout_marginTop="300dp"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="@+id/textView_first_no"
android:layout_width="150dp"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="50dp"
android:text="First number"
android:textSize="20dp"/>
<EditText
android:id="@+id/editText_first_no"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_marginLeft="200dp"
android:layout_marginTop="40dp"
android:inputType="number"
/>
<TextView
android:id="@+id/textView_second_no"
android:layout_width="150dp"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="100dp"
android:text="Second number"
android:textSize="20dp" />
<EditText
android:id="@+id/editText_second_no"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_marginLeft="200dp"
android:layout_marginTop="90dp"
android:inputType="number"
/>
<Button
android:id="@+id/add_button"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginLeft="110dp"
android:layout_marginTop="200dp"
android:text="Add"/></RelativeLayout>

c)Create an Android app and Implement a Relative Layout


Step 1: Create a New Project
Step 2: Working with the activity_main.xml file
Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for
the activity_main.xml file.
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout

android:layout_width="fill_parent"

android:layout_height="fill_parent"

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

<Button

android:id="@+id/button1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Top Left Button"

android:layout_alignParentLeft="true"

android:layout_alignParentTop="true"/>

<Button

android:id="@+id/button2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Top Right Button"

android:layout_alignParentTop="true"

android:layout_alignParentRight="true"/>

<Button

android:id="@+id/button3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Bottom Left Button"

android:layout_alignParentLeft="true"

android:layout_alignParentBottom="true"/>

<Button

android:id="@+id/button4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Bottom Right Button"

android:layout_alignParentRight="true"

android:layout_alignParentBottom="true"/>

<Button
android:id="@+id/button5"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="Middle Button"

android:layout_centerVertical="true"

android:layout_centerHorizontal="true"/>

</RelativeLayout>
Step 3: Working with the MainActivity.java file

package com.example.example1;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

d)Create an Android app to multiply, and divide two numbers supplied from a user interface having two texts boxes.
Step 1: Create a new Android Application and Name it Program_Multiplication_Table with the Empty layout.
Step 2: Open the activity_main.xml (values>layout>activity_main.xml) file where we will be creating the
layout of the application.
Step 3: In activity_main.xml file add TextView, EditText, and a Button
Step 4: Assign ID to each component
Step 5: Now, open up the MainActivity file and declare the variables.
Step 6: Read the values entered in the EditText boxes using an ID that has been set in the XML code above.
Step 7: Add a click listener to the Add button
Step 8: When the Add button has been clicked we need to Multiply the values and store it in Buffer
Step 9: Then show the resultant output in the TextView by setting the buffer in the TextView.

// Build the java logic for multiplication table

// using button, text view, edit text

package com.example.program_multiplication_table;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

public class MainActivity

extends AppCompatActivity

implements View.OnClickListener {

// define the global variable

// variable number1, number2 for input input number

// Add_button, result textView

EditText editText;

Button button;

TextView result;

int ans = 0;

@Override

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// by ID we can use each component

// whose id is assigned in the XML file

editText = (EditText)findViewById(R.id.editText);

button = (Button)findViewById(R.id.button);

result = (TextView)findViewById(R.id.textView);

// set clickListener on button

button.setOnClickListener(this);
}

@Override

public void onClick(View v)

if(v.getId()==R.id.button) {

StringBuffer buffer = new StringBuffer();

// get the input number from editText

String fs = editText.getText().toString();

// convert it to integer

int n = Integer.parseInt(fs);

// build the logic for table

for (int i = 1; i <= 10; i++) {

ans = (i * n);

buffer.append(n + " X " +

i + " = " + ans + "\n\n");

// set the buffer textview

result.setText(buffer);

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

<androidx.constraintlayout.widget.ConstraintLayout

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="match_parent"

tools:context=".MainActivity"

tools:layout_editor_absoluteY="25dp">

<!-- Add the button for run table logic and print result-->

<!-- give id "button"-->

<Button

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

android:layout_height="wrap_content"

android:layout_marginTop="16dp"

android:text="TABLE"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toEndOf="@+id/editText"

app:layout_constraintTop_toTopOf="parent" />

<!-- Text view for result view-->

<!-- give the id TextView-->

<TextView

android:id="@+id/textView"

android:layout_width="0dp"

android:layout_height="0dp"

android:layout_marginStart="36dp"

android:layout_marginEnd="36dp"

android:layout_marginBottom="18dp"

android:textColor="@color/black"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/editText" />

<!-- edit Text for take input from user-->

<!-- give the id editText-->

<EditText

android:id="@+id/editText"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginBottom="20dp"

android:layout_marginEnd="9dp"

android:layout_marginRight="9dp"

android:layout_marginTop="16dp"

android:ems="10"

android:inputType="number"

app:layout_constraintBottom_toTopOf="@+id/textView2"
app:layout_constraintEnd_toStartOf="@+id/button"

app:layout_constraintHorizontal_chainStyle="packed"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

tools:ignore="UnknownId" />

</androidx.constraintlayout.widget.ConstraintLayout>
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

ASSIGNMENT – 4

(a) Create a screen that has input boxes foe user name, password, address, gender (radio buttons
for the male and female), Age (Numeric), Date of Birth (Date picket), State (Spinner), and a Submit
Button. On clicking the submit button, print all the below the Submit Button (any use layout).
XML CODE: -
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/userNameLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name:"
android:layout_marginTop="20dp"/>
<EditText
android:id="@+id/userNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/userNameLabel"
android:layout_marginTop="5dp"/>
<TextView
android:id="@+id/passwordLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password:"
android:layout_below="@id/userNameEditText"
android:layout_marginTop="20dp"/>
<EditText
android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/passwordLabel"
android:layout_marginTop="5dp"
android:inputType="textPassword"/>
<TextView
android:id="@+id/genderLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender:"
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

android:layout_below="@id/passwordEditText"
android:layout_marginTop="20dp"/>
<RadioGroup
android:id="@+id/genderRadioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/genderLabel"
android:orientation="horizontal">
<RadioButton
android:id="@+id/maleRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"/>
<RadioButton
android:id="@+id/femaleRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"/>
</RadioGroup>
<TextView
android:id="@+id/dobLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date of Birth:"
android:layout_below="@id/genderRadioGroup"
android:layout_marginTop="20dp"/>
<DatePicker
android:id="@+id/datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/dobLabel"
android:layout_marginTop="5dp"/>
<TextView
android:id="@+id/stateLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="State:"
android:layout_below="@id/datePicker"
android:layout_marginTop="20dp"/>
<Spinner
android:id="@+id/stateSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

android:layout_below="@id/st'ateLabel"
android:layout_marginTop="5dp"/>
<Button
android:id="@+id/submitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_below="@id/stateSpinner"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"/>
<TextView
android:id="@+id/resultTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:textSize="16sp"
android:layout_below="@id/submitButton"
android:layout_marginTop="20dp"/>
</RelativeLayout>

JAVA CODE: -
package com.example.a4a;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText userNameEditText, passwordEditText;
RadioGroup genderRadioGroup;
RadioButton maleRadioButton, femaleRadioButton;
DatePicker datePicker;
Spinner stateSpinner;
TextView resultTextView;
Button submitButton;
@Override

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
userNameEditText= findViewById(R.id.userNameEditText);
passwordEditText = findViewById(R.id.passwordEditText);
genderRadioGroup = findViewById(R.id.genderRadioGroup);
maleRadioButton = findViewById(R.id.maleRadioButton);
femaleRadioButton = findViewById(R.id.femaleRadioButton);
datePicker = findViewById(R.id.datePicker);
stateSpinner = findViewById(R.id.stateSpinner);
submitButton = findViewById(R.id.submitButton);
resultTextView = findViewById(R.id.resultTextView);
submitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
StringBuilder result = new StringBuilder();
result.append("User Name:
").append(userNameEditText.getText()).append("\n");
result.append("Password: ").append(passwordEditText.getText()).append("\n");
result.append("Gender: ").append(maleRadioButton.isChecked() ? "Male" :
"Female").append("\n");
int day = datePicker.getDayOfMonth();
int month = datePicker.getMonth() + 1;
int year = datePicker.getYear();
result.append("Date of Birth:
").append(day).append("/").append(month).append("/").append(year).append("\n");
result.append("State: ").append(stateSpinner.getSelectedItem()).append("\n");

resultTextView.setText(result.toString());
}
});
}
}

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

OUTPUT: -

(b) Create an Android app that will check whether the given number supplied as an input is prime
or not.
XML CODE: -
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/numberEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter a number"
android:inputType="number"/>
<Button
android:id="@+id/checkButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/numberEditText"
android:layout_centerHorizontal="true"
android:text="Check Prime"/>
<TextView
android:id="@+id/resultTextView"
android:layout_width="wrap_content"

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

android:layout_height="wrap_content"
android:layout_below="@id/checkButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"/>
</RelativeLayout>

JAVA CODE: -
package com.example.prime;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button check;
EditText text1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText numberEditText = findViewById(R.id.numberEditText);
Button checkButton = findViewById(R.id.checkButton);
TextView resultTextView = findViewById(R.id.resultTextView);
checkButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String input = numberEditText.getText().toString().trim();
if (!input.isEmpty()) {
int number = Integer.parseInt(input);
boolean isPrime = isPrime(number);
if (isPrime) {
resultTextView.setText(number + " is a prime number.");
} else {
resultTextView.setText(number + " is not a prime number.");
}
} else {
resultTextView.setText("Please enter a number.");
}
}
});
}
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

private boolean isPrime(int number) {


if (number <= 1) return false;
if (number <= 3) return true;
if (number % 2 == 0 || number % 3 == 0) return false;
for (int i = 5; i * i <= number; i += 6) {
if (number % i == 0 || number % (i + 2) == 0)
return false;
}
return true;
}
}

OUTPUT: -

(c) Create an Android app that will check whether a given two numbers are palindrome or not.

XML CODE: -

<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context=".MainActivity">
<EditText
android:id="@+id/firstNumberEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
android:hint="Enter first number"
android:inputType="number" />
<EditText
android:id="@+id/secondNumberEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/firstNumberEditText"
android:layout_marginTop="16dp"
android:hint="Enter second number"
android:inputType="number" />
<Button
android:id="@+id/checkButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/secondNumberEditText"
android:layout_marginTop="16dp"
android:text="Check" />
<TextView
android:id="@+id/resultTextView"
android:layout_width="266dp"
android:layout_height="137dp"
android:gravity="center"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="79dp"
android:layout_marginTop="297dp"
android:layout_marginEnd="82dp"
android:layout_marginBottom="313dp"
android:text="TextView" />
</RelativeLayout>

JAVA CODE: -
package com.example.palindrome;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

private EditText firstNumberEditText;


private EditText secondNumberEditText;
private Button checkButton;
private TextView resultTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firstNumberEditText = findViewById(R.id.firstNumberEditText);
secondNumberEditText = findViewById(R.id.secondNumberEditText);
checkButton = findViewById(R.id.checkButton);
resultTextView = findViewById(R.id.resultTextView);
checkButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String firstNumberStr = firstNumberEditText.getText().toString();
String secondNumberStr = secondNumberEditText.getText().toString();

if (isPalindrome(firstNumberStr) && isPalindrome(secondNumberStr)) {


resultTextView.setText("Both numbers are palindromes!");
} else {
resultTextView.setText("At least one of the numbers is not a palindrome.");
}
}
});
}
private boolean isPalindrome(String str) {
int left = 0;
int right = str.length() - 1;
while (left < right) {
if (str.charAt(left) != str.charAt(right)) {
return false;

}
left++;
right--;
}
return true;
}
}

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

OUTPUT: -

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

ASSIGNMENT – 5

(a) Create an android app to show and implement table layout.

XML CODE: -

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


<LinearLayout 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"
android:orientation="vertical"
android:padding="30dp"
tools:context=".MainActivity">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<TextView
android:text="Name"
android:textStyle="bold"
android:padding="8dp"
android:layout_column="1"/>
<TextView
android:text="Age"
android:textStyle="bold"
android:padding="8dp"
android:layout_column="2"/>
<TextView
android:text="Gender"
android:textStyle="bold"
android:padding="8dp"
android:layout_column="3"/>
<TextView
android:text="DEPT."
android:textStyle="bold"
android:padding="8dp"
android:layout_column="4"/>
<TextView
android:text="Contact No."
android:textStyle="bold"

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

android:padding="8dp"
android:layout_column="5"/>
<TextView
android:layout_height="match_parent"
android:layout_column="6"
android:padding="8dp"
android:text="Gread"
android:textStyle="bold" />
</TableRow>
<TableRow>
<TextView
android:text="Ram"
android:padding="8dp"
android:layout_column="1"/>
<TextView
android:text="25"
android:padding="8dp"
android:layout_column="2"/>
<TextView
android:text="Male"
android:padding="8dp"
android:layout_column="3"/>
<TextView
android:text="BBA"
android:padding="8dp"
android:layout_column="4"/>
<TextView
android:text="1001"
android:padding="8dp"
android:layout_column="5"/>
<TextView
android:text="A+"
android:padding="8dp"
android:layout_column="6"/>
</TableRow>
<TableRow>
<TextView
android:text="Rahul"
android:padding="8dp"
android:layout_column="1"/>
<TextView

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
android:text="30"
android:padding="8dp"
android:layout_column="2"/>
<TextView
android:text="Male"
android:padding="8dp"
android:layout_column="3"/>
<TextView
android:text="MCA"
android:padding="8dp"
android:layout_column="4"/>
<TextView
android:text="1002"
android:padding="8dp"
android:layout_column="5"/>
<TextView
android:text="A"
android:padding="8dp"
android:layout_column="6"/>
</TableRow>
<TableRow>
<TextView
android:text="Sumit"
android:padding="8dp"
android:layout_column="1"/>
<TextView
android:text="30"
android:padding="8dp"
android:layout_column="2"/>
<TextView
android:text="Male"
android:padding="8dp"
android:layout_column="3"/>
<TextView
android:text="BCA"
android:padding="8dp"
android:layout_column="4"/>
<TextView
android:text="1003"
android:padding="8dp"
android:layout_column="5"/>
<TextView
android:text="A+"

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

android:padding="8dp"
android:layout_column="6"/>
</TableRow>
</TableLayout>
</LinearLayout>

JAVA CODE: -
package com.example.table_layout;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

OUTPUT: -

(b)Create an android app to implement table layout and button click event.

XML CODE: -

<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context=".MainActivity">

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

<TableLayout
android:id="@+id/tableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<TextView
android:text="Name"
android:textStyle="bold"
android:padding="8dp"/>
<TextView
android:id="@+id/name"
android:padding="8dp"/>
</TableRow>
<TableRow>
<TextView
android:text="Age"
android:textStyle="bold"
android:padding="8dp"/>
<TextView
android:id="@+id/age"
android:padding="8dp"/>
</TableRow>
<TableRow>
<TextView
android:text="DEPT"
android:textStyle="bold"
android:padding="8dp"/>
<TextView
android:id="@+id/dept"
android:padding="8dp"/>
</TableRow>
</TableLayout>
<Button
android:id="@+id/updateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tableLayout"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="Update Data"/>
</RelativeLayout>

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

JAVA CODE: -
package com.example.button_checking;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private TextView name,age,dept;
private Button updateButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = findViewById(R.id.name);
age = findViewById(R.id.age);
dept = findViewById(R.id.dept);
updateButton = findViewById(R.id.updateButton);
updateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateData();

}
});
}
private void updateData() {
name.setText("Puja Kumari");
age.setText("22");
dept.setText("BCA");
}
}
OUTPUT: -

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

c)Develop an Android Application that can check an Armstrong Number.


XML CODE: -
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context=".MainActivity">
<EditText
android:id="@+id/numberEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter a number"
android:inputType="number"/>
<Button
android:id="@+id/checkButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/numberEditText"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="Check Armstrong"/>
<TextView
android:id="@+id/resultTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/checkButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text=""
android:textSize="18sp"/>
</RelativeLayout>

JAVA CODE: -
package com.example.armstrong_number;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

public class MainActivity extends AppCompatActivity {


private EditText numberEditText;
private Button checkButton;
private TextView resultTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
numberEditText = findViewById(R.id.numberEditText);
checkButton = findViewById(R.id.checkButton);
resultTextView = findViewById(R.id.resultTextView);
checkButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String numberStr = numberEditText.getText().toString();
if (!numberStr.isEmpty()) {
int number = Integer.parseInt(numberStr);
if (isArmstrong(number)) {
resultTextView.setText(number + " is an Armstrong number!");
} else {
resultTextView.setText(number + " is not an Armstrong number!");
}
} else {
resultTextView.setText("Please enter a number!");
}
}
});
}

private boolean isArmstrong(int number) {


int originalNumber, remainder, result = 0, n = 0;
originalNumber = number;
while (originalNumber != 0) {
originalNumber /= 10;
++n;
}
originalNumber = number;
while (originalNumber != 0) {
remainder = originalNumber % 10;
result += Math.pow(remainder, n);
originalNumber /= 10;
}

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

return result == number;


}
}

OUTPUT: -

(d) Develop an Android Application that can calculate the sum of digit of a given number.

XML CODE: -
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/numberInput"
android:layout_width="match_parent"

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

android:layout_height="wrap_content"
android:hint="Enter a number"
android:inputType="number" />
<Button
android:id="@+id/calculateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/numberInput"
android:layout_centerHorizontal="true"
android:text="Calculate" />
<TextView
android:id="@+id/resultText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/calculateButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="Sum of Digits:"
android:textSize="20sp" />
</RelativeLayout>

JAVA CODE: -

package com.example.sum_of_dig;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText numberInput = findViewById(R.id.numberInput);
Button calculateButton = findViewById(R.id.calculateButton);
final TextView resultText = findViewById(R.id.resultText);
calculateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

String numberStr = numberInput.getText().toString();


int number = Integer.parseInt(numberStr);
int sum = calculateSumOfDigits(number);
resultText.setText("Sum of Digits: " + sum);
}
});
}
private int calculateSumOfDigits(int number) {
int sum = 0;
while (number != 0) {
sum += number % 10;
number /= 10;
}
return sum;
}
}

OUTPUT: -

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

ASSIGNMENT – 6

(a) Develop an Android Application to implement Implicit Intent.

XML CODE: -

<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/btn_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_marginStart="101dp"
android:layout_marginTop="194dp"
android:text="1" />
<Button
android:id="@+id/btn_0"
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="237dp"
android:layout_marginTop="194dp"
android:layout_marginEnd="86dp"
android:layout_marginBottom="489dp"
android:text="0" />
<Button
android:id="@+id/btn_call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
android:layout_alignParentBottom="true"
android:layout_marginStart="172dp"
android:layout_marginTop="301dp"
android:layout_marginEnd="151dp"
android:layout_marginBottom="382dp"
android:text="Call" />
</RelativeLayout>

JAVA CODE: -

package com.example.implicit_intent;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private StringBuilder phoneNumber = new StringBuilder();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnCall = findViewById(R.id.btn_call);
View.OnClickListener numberClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Button button = (Button) v;
phoneNumber.append(button.getText().toString());
}
};
findViewById(R.id.btn_1).setOnClickListener(numberClickListener);
findViewById(R.id.btn_0).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
phoneNumber.append("0");
}
});
btnCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String number = phoneNumber.toString();
Uri uri = Uri.parse("tel:" + number
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

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


startActivity(intent);
}
});
}
}

OUTPUT: -

(b) Develop an android Application to Explicit Intent.

XML CODE: -

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


<androidx.constraintlayout.widget.ConstraintLayout
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="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/n"
android:layout_width="235dp"
android:layout_height="51dp"
android:text=""
android:hint="Enter Username"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.148" />
<EditText
android:id="@+id/p"
android:layout_width="235dp"
android:layout_height="51dp"
android:text=""
android:hint="Enter Password"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.488"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.244" />
<Button
android:id="@+id/submit"
android:layout_width="235dp"
android:layout_height="47dp"
android:text="Check"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.423" />
</androidx.constraintlayout.widget.ConstraintLayout>

JAVA CODE: -

package com.example.pass_checking; import


androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View; import
android.widget.Button; import
android.widget.EditText; import
android.widget.TextView; import
android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText n;
EditText p;
Button submit;
@Override
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
n = findViewById(R.id.n);
p = findViewById(R.id.p);
submit = findViewById(R.id.submit);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = n.getText().toString();
String pass = p.getText().toString();
if(name.equals("admin")&& pass.equals("12345"))
{
Intent intent = new Intent(MainActivity.this,page2.class);
startActivity(intent);
}
else if (name.equals("") || pass.equals(""))
{
Toast.makeText(getApplicationContext(),"Enter UserName &
Password",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getApplicationContext(),"Invalid",Toast.LENGTH_SHORT).show();
}
}
});
}
}

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

OUTPUT: -

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

ASSIGNMENT – 7

a) Create an Android App that will check whether given user name and password matches with the
predefine user name and password.

XML CODE: -

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


<androidx.constraintlayout.widget.ConstraintLayout
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="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/n"
android:layout_width="235dp"
android:layout_height="51dp"
android:text=""
android:hint="Enter Username"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.148" />
<EditText
android:id="@+id/p"
android:layout_width="235dp"
android:layout_height="51dp"
android:text=""
android:hint="Enter Password"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.488"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.244" />
<Button
android:id="@+id/submit"
android:layout_width="235dp"

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
android:layout_height="47dp"
android:text="Check"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.423" />
</androidx.constraintlayout.widget.ConstraintLayout>

JAVA CODE: -

package com.example.pass_checking;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle; import
android.view.View; import
android.widget.Button; import
android.widget.EditText; import
android.widget.TextView; import
android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText n;
EditText p;
Button submit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
n = findViewById(R.id.n);
p = findViewById(R.id.p);
submit = findViewById(R.id.submit);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = n.getText().toString();
String pass = p.getText().toString();
if(name.equals("admin")&& pass.equals("12345"))
{
Intent intent = new Intent(MainActivity.this,page2.class);
startActivity(intent);
}
else if (name.equals("") || pass.equals(""))
{
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

Toast.makeText(getApplicationContext(),"Enter UserName &


Password",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getApplicationContext(),"Invalid",Toast.LENGTH_SHORT).show();
}
}
});
}
}

OUTPUT: -

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

ASSIGNMENT – 8

a)Create an android application using fragments.

XML CODE: -

<?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"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="News" />
<Button
android:id="@+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Sports" />
<Button
android:id="@+id/b3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Shopping " />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="682dp"
android:orientation="vertical">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragmentContainerView4"
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>

JAVA CODE: -

package com.example.fragmentation;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button b1,b2,b3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = findViewById(R.id.b1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.fragmentContainerView4, News.class,null)
.setReorderingAllowed(true)
.addToBackStack("name")
.commit();
}
});
b2 = findViewById(R.id.b2);
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.fragmentContainerView4,sports.class,null)
.setReorderingAllowed(true)
.addToBackStack("name")
.commit();
}
});

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

b3 = findViewById(R.id.b3);
b3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.fragmentContainerView4,shopping.class,null)
.setReorderingAllowed(true)
.addToBackStack("name")
.commit();
}
});
}
}

OUTPUT: -

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

ASSIGNMENT – 9

a)Write an android app to develop a calculator.

XML CODE: -

<?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="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:id="@+id/textViewResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textSize="24sp"
android:textStyle="bold"
android:text="0" />
<GridLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:columnCount="4"
android:rowCount="5"
android:layout_marginTop="16dp"
android:padding="5dp"
android:alignmentMode="alignMargins"
android:columnOrderPreserved="false">
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="1"
android:textSize="20sp" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="2"
android:textSize="20sp" />
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1" android:text="3"
android:textSize="20sp" />
<Button
android:id="@+id/buttonAdd"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="+"
android:textSize="20sp" />
<Button
android:id="@+id/button4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="4"
android:textSize="20sp" />
<Button
android:id="@+id/button5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="5"
android:textSize="20sp" />
<Button
android:id="@+id/button6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="6"
android:textSize="20sp" />
<Button
android:id="@+id/buttonSubtract"
android:layout_width="0dp"
android:layout_height="wrap_content"

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

android:layout_columnWeight="1"
android:text="-"
android:textSize="20sp" />
<Button
android:id="@+id/button7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="7"
android:textSize="20sp" />
<Button
android:id="@+id/button8"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="8"
android:textSize="20sp" />
<Button
android:id="@+id/button9"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="9"
android:textSize="20sp" />
<Button
android:id="@+id/buttonMultiply"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="*"
android:textSize="20sp" />
<Button
android:id="@+id/buttonClear"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnSpan="2"
android:layout_columnWeight="2"
android:text="C"
android:textSize="20sp" />
<Button
android:id="@+id/button0"
android:layout_width="0dp"
android:layout_height="wrap_content"

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
android:layout_columnWeight="1"
android:text="0"
android:textSize="20sp" />
<Button
android:id="@+id/buttonDecimal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="."
android:textSize="20sp" />
<Button
android:id="@+id/buttonDivide"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="/"
android:textSize="20sp" />
<Button
android:id="@+id/buttonEqual"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnSpan="4"
android:layout_columnWeight="4"
android:text="="
android:textSize="20sp" />
</GridLayout>
</LinearLayout>

JAVA CODE: -

package com.example.calulator;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private TextView textViewResult;
private StringBuilder currentNumber;
private double operand1, operand2;
private char operator;
private Button clr,buttonDecimal;
@Override

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textViewResult = findViewById(R.id.textViewResult);
currentNumber = new StringBuilder();
for (int i = 0; i < 10; i++) {
int id = getResources().getIdentifier("button" + i, "id", getPackageName());
Button button = findViewById(id);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
currentNumber.append(((Button) v).getText());
textViewResult.setText(currentNumber.toString());
}
});
}
findViewById(R.id.buttonAdd).setOnClickListener(operatorClickListener);
findViewById(R.id.buttonSubtract).setOnClickListener(operatorClickListener);
findViewById(R.id.buttonMultiply).setOnClickListener(operatorClickListener);
findViewById(R.id.buttonDivide).setOnClickListener(operatorClickListener);
findViewById(R.id.buttonDecimal).setOnClickListener(operatorClickListener);
findViewById(R.id.buttonClear).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
currentNumber.setLength(0
);
operand1=0;
operand2=0;
operator = '\0';
textViewResult.setText(" ");
}
});
findViewById(R.id.buttonEqual).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!textViewResult.getText().toString().isEmpty()) {
operand2 = Double.parseDouble(currentNumber.toString());
double result = performOperation();
textViewResult.setText(String.valueOf(result));
currentNumber.setLength(0);
currentNumber.append(result);
}
}
});
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

}
private View.OnClickListener operatorClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!textViewResult.getText().toString().isEmpty()) {
operand1 = Double.parseDouble(currentNumber.toString());
currentNumber.setLength(0); // Clear the StringBuilder for next number input
operator = ((Button) v).getText().charAt(0);
}
}
};
private double performOperation() {
double result = 0;
switch (operator) {
case '+':
result = operand1 + operand2;
break;
case '-':
result = operand1 - operand2;
break;
case '*':
result = operand1 * operand2;
break;
case '/':
if (operand2 != 0) {
result = operand1 / operand2;
} else {
textViewResult.setText("Error");
}
break;
}
return result;
}
}

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024

OUTPUT: -

Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021

You might also like