0% found this document useful (0 votes)
3 views36 pages

Android Programs Lab Manual

The document outlines the steps to create several Android applications using Java, including a Hello World app, an orientation-based message display app, a login window app, and an app demonstrating explicit and implicit intents. Each section provides detailed coding instructions for XML layout files and Java activity classes, along with project setup steps. Additionally, it includes instructions for creating a custom-designed opening screen with background resources.

Uploaded by

ameerhansufn
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)
3 views36 pages

Android Programs Lab Manual

The document outlines the steps to create several Android applications using Java, including a Hello World app, an orientation-based message display app, a login window app, and an app demonstrating explicit and implicit intents. Each section provides detailed coding instructions for XML layout files and Java activity classes, along with project setup steps. Additionally, it includes instructions for creating a custom-designed opening screen with background resources.

Uploaded by

ameerhansufn
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

1.

Creating Hello World Application

Steps:
1. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the SDK as API
24(“Nougat”,Android 7.0).Click Finish Button.
4. Update the following code in activity_main.xml and [Link]

=>Coding part of Activity_main.xml

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


<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="40sp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</[Link]>

=>Coding part of [Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
}
}
=>Output of the program

2. Creating an Application that displays message based on screen orientation

Step 1: Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the SDK as API
24(“Nougat”,Android 7.0).Click Finish Button.
4. Update the following code in activity_main.xml and [Link]

=>Coding part of Activity_main.xml

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


<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is Portrait"
android:textSize="40sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.25" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="Launch new activity"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.499" />

</[Link]>

=>Coding part of [Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
}

public void onClick(View v){


Intent intent=new Intent([Link],[Link]);
startActivity(intent);
}

Step 2: Create another new empty views activity and give the name as Nextactivity (Go to app>>
New>>Activity>>Empty Views Activity)

=>Coding part of Activity_nextactivity.xml

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


<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Nextactivity">

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is Landscape Orientation"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</[Link]>
Step 3: Add the screen orientation values in [Link]

=>Coding part of [Link]

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


<manifest xmlns:android="[Link]
xmlns:tools="[Link]

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/[Link]"
tools:targetApi="31">
<activity
android:name=".Nextactivity"
android:exported="false"
android:screenOrientation="landscape"

/>
<activity
android:name=".MainActivity"
android:exported="true"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="[Link]" />

<category android:name="[Link]" />


</intent-filter>
</activity>
</application>
</manifest>

=>Output of the program


3. Create and Application to develop Login window using UI controls

Step 1: Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the SDK as API
24(“Nougat”,Android 7.0).Click Finish Button.
4. Update the following code in activity_main.xml and [Link]

=>Coding part of Activity_main.xml

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


<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="200dp"
android:text="Login Form"
android:textSize="40sp" />

<TextView
android:id="@+id/tvUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name"
android:textSize="24sp" />

<EditText
android:id="@+id/etUserName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter the User Name"
android:inputType="text"
android:textSize="24sp" />

<TextView
android:id="@+id/tvPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:textSize="24sp" />

<EditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter the Password"
android:inputType="textPassword"
android:textSize="24sp" />

<Button
android:id="@+id/btnLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_gravity="center" />

</LinearLayout>

=>Coding part of [Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
}
}
=>Output of the program

4. Create and Application to implement new activity using explicit intent and implicit intent

Step 1: Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the SDK as API
24(“Nougat”,Android 7.0).Click Finish Button.
4. Update the following code in activity_main.xml and [Link]
=>Coding part of Activity_main.xml

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


<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Explicit Activity"
android:textSize="30sp"
android:layout_gravity="center"
android:layout_marginTop="200dp"
/>

<Button
android:id="@+id/btnExplicitContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="200dp"
android:onClick="onClick"
android:text="Explicit Activity" />

</LinearLayout>

=>Coding part of [Link]

package [Link];
import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
[Link](findViewById([Link]), (v, insets) -> {
Insets systemBars = [Link]([Link]());
[Link]([Link], [Link], [Link], [Link]);
return insets;
});
}
public void onClick(View view) {
Intent intent = new Intent([Link], [Link]);
startActivity(intent);
}

Step 2: Create another new empty views activity and give the name as Nextactivity (Go to app>>
New>>Activity>>Empty Views Activity)

Coding part of activity_next.xml

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


<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".NextActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Implicit Activity"
android:textSize="30sp"
android:layout_gravity="center"
android:layout_marginTop="200dp"
/>

<Button
android:id="@+id/btnImplicitContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="200dp"
android:onClick="onClick"
android:text="Implicit Activity" />

</LinearLayout>

=>Coding part of [Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class NextActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_next);
[Link](findViewById([Link]), (v, insets) -> {
Insets systemBars = [Link]([Link]());
[Link]([Link], [Link], [Link], [Link]);
return insets;
});

public void onClick(View view) {


Uri webpage= [Link]("[Link]
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
startActivity(intent);
}

=>Output of the program

// 5 Create an application that displays custom designed Opening Screen

Project creation Steps:


1. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the SDK as API
24(“Nougat”,Android 7.0).Click Finish Button.
Next follow the below steps to create background files

Step [Link] background resources (bg_inner.xml)

a. To create resource file, click app>> res >> drawable >> new >>Drawable Resource File

b. Set filename as bg_inner.xml, root element as shape and then click ok.

Modify the bg_inner.xml file.

Step [Link] image to the project

a. Copy the image file (Ctrl +C) from the file location

b. Click app>>res>> drawable>> right click Paste(Ctrl+V)

Coding part of bg_inner.xml

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


<shape xmlns:android="[Link]
<gradient
android:startColor="#84FFFF"
android:endColor="#f08"
android:angle="100"/>
<corners android:radius="20dp"/>
</shape>

Step 3. Change the activity_main.xml file and [Link]

=>Coding part of Activity_main.xml

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


<RelativeLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="@drawable/bg_inner"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome !!!"
android:textSize="40sp"
android:layout_centerInParent="true"
/>
</RelativeLayout>

=>Coding part of [Link]

package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
[Link](findViewById([Link]), (v, insets) -> {
Insets systemBars = [Link]([Link]());
[Link]([Link], [Link], [Link], [Link]);
return insets;
});

Handler handler=new Handler();


[Link](new Runnable() {
@Override
public void run() {
Intent intent=new Intent([Link],[Link]);
startActivity(intent);
finish();
}
},3000);

}
}

Step 4. Create one more empty views activity and give the name as NextActivity(Go to app>>
New>>Activity>>Empty Views Activity) and change the activity_next.xml file and no changes in the
[Link] file

Coding part of activity_next.xml

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


<RelativeLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:app2="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".NextActivity"
android:gravity="center"
android:background="@drawable/android"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome to home Page"
android:textColor="@color/black"
android:textSize="32sp"
android:textStyle="bold"
android:layout_centerInParent="true"
/>
</RelativeLayout>
=>Coding part of [Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class NextActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_next);
[Link](findViewById([Link]), (v, insets) -> {
Insets systemBars = [Link]([Link]());
[Link]([Link], [Link], [Link], [Link]);
return insets;
});
}
}

=>Output of the program

6. Create and Application to show all views

Steps:
1. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the SDK as API
24(“Nougat”,Android 7.0).Click Finish Button.
4. Update the following code in activity_main.xml and [Link]

=>Coding part of Activity_main.xml

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


<ScrollView xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a TextView"
android:textSize="18sp"
android:layout_marginBottom="16dp"/>

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your text here"
android:layout_marginBottom="16dp" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me"
android:layout_marginBottom="16dp" />

<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Check Me"
android:layout_marginBottom="16dp" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Which Section You belong to"
android:textSize="20sp"
android:layout_marginBottom="16dp"/>
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="16dp" />

<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A section" />

<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B Section" />

<Switch
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Switch Testing"
android:layout_marginBottom="16dp"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select your favourite Programming Language"
android:textSize="20sp"
android:layout_marginBottom="16dp"/>
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Progress Bar"
android:textSize="20sp"
android:layout_marginBottom="16dp"/>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/[Link]"
android:progress="25"
android:layout_marginBottom="16dp" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select the number between 1 to 50"
android:textSize="20sp"
android:layout_marginBottom="16dp"/>
<NumberPicker
android:id="@+id/numberPicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"/>
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select your date of birth"
android:textSize="20sp"
android:layout_marginBottom="16dp"/>
<DatePicker
android:id="@+id/datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"/>
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set the next class hour time"
android:textSize="20sp"
android:layout_marginBottom="16dp"/>
<TimePicker
android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"/>

</LinearLayout>

</ScrollView>

=>Coding part of [Link]

package [Link];

import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
[Link](findViewById([Link]), (v, insets) -> {
Insets systemBars = [Link]([Link]());
[Link]([Link], [Link], [Link], [Link]);
return insets;
});
Spinner spinner = findViewById([Link]);
ArrayList<String> arrayList = new ArrayList<>();
[Link]("Select Language");
[Link]("JAVA");
[Link]("ANDROID");
[Link]("C Language");
[Link]("CPP Language");
[Link]("Python Programming");

ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,


[Link].simple_spinner_item, arrayList);
[Link]([Link].simple_spinner_dropdown_item);
[Link](arrayAdapter);

NumberPicker numberPicker1 = findViewById([Link].numberPicker1);


[Link](1);
[Link](50);

}
}
=> Output of the program

7 Create a menu in application

Steps:
1. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the SDK as API
24(“Nougat”,Android 7.0).Click Finish Button.

Steps to be followed to create the menu

Step1. Create Android resource directory by clicking res>>new>>Android Resource directory, give
the name as menu

Step2. Right click menu folder click new>> Menu Resource File, give the name of the file as menus.

Add the following code in [Link]

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


<menu xmlns:android="[Link]
<item android:id="@+id/php" android:title="PHP"/>
<item android:id="@+id/java" android:title="JAVA"/>
<item android:id="@+id/csharp" android:title="C#"/>
</menu>
Step 3. =>Coding part of Activity_main.xml ( Remove Helloworld textview control)

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


<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
</[Link]>

Step 4. =>Coding part of [Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
}

@Override
public boolean onCreatePanelMenu(int featureId,Menu menu)
{
MenuInflater inflater=getMenuInflater();
[Link]([Link],menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
if([Link]()==[Link]) {
[Link](this, "Php Page", Toast.LENGTH_SHORT).show();
}
if([Link]()==[Link]) {
[Link](this, "Java Page", Toast.LENGTH_SHORT).show();
}
if([Link]()==[Link]) {
[Link](this, "C# Page", Toast.LENGTH_SHORT).show();
}
return true;
}
}
Step 5. Change the theme value [Link] file

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


<manifest xmlns:android="[Link]
xmlns:tools="[Link]
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/[Link]"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="[Link]" />

<category android:name="[Link]"/>
</intent-filter>
</activity>
</application>
</manifest>

=>Output of the program


8. Create an application to read/ write the Local data.

Steps:
1. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the SDK as API
24(“Nougat”,Android 7.0).Click Finish Button.
4. Update the following code in activity_main.xml and [Link]

=>Coding part of Activity_main.xml

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


<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="200dp"
android:text="Login Form"
android:textSize="40sp" />

<TextView
android:id="@+id/tvUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name"
android:textSize="24sp" />

<EditText
android:id="@+id/etUserName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter the User Name"
android:inputType="text"
android:textSize="24sp" />

<TextView
android:id="@+id/tvPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:textSize="24sp" />

<EditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter the Password"
android:inputType="textPassword"
android:textSize="24sp" />

<Button
android:id="@+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="onSaveClick"
android:text="Save" />
<Button
android:id="@+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="onNextClick"
android:text="Next" />

</LinearLayout>

=>Coding part of [Link]

package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


EditText etUserName,etPassword;

@Override
protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);

etUserName = findViewById([Link]);
etPassword = findViewById([Link]);
}

public void onSaveClick(View view) {

SharedPreferences sharedPreferences = getSharedPreferences("MyPrefs",


Context.MODE_PRIVATE);
[Link] editor = [Link]();
[Link]("username",[Link]().toString());
[Link]("password", [Link]().toString());
[Link]();
[Link](getApplicationContext(),"Saved successfully",Toast.LENGTH_LONG).show();
}

public void onNextClick(View view) {


Intent intent = new Intent(this, [Link]);
startActivity(intent);
}
}

Next Step. Create one more empty views activity and give the name as NextActivity (Go to app>>
New>>Activity>>Empty Views Activity)
Coding part of activity_next.xml

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


<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="200dp"
android:text="Your Details"
android:textSize="40sp" />

<TextView
android:id="@+id/tvUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name"
android:textSize="24sp" />

<EditText
android:id="@+id/etUserName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter the User Name"
android:inputType="text"
android:textSize="24sp" />

<TextView
android:id="@+id/tvPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:textSize="24sp" />

<EditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter the Password"
android:inputType="text"
android:textSize="24sp" />

</LinearLayout>

=>Coding part of [Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class NextActivity extends AppCompatActivity {


EditText etUserName,etPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_next);

etUserName = findViewById([Link]);
etPassword = findViewById([Link]);

SharedPreferences sharedPreferences = getSharedPreferences("MyPrefs",


Context.MODE_PRIVATE);
String username = [Link]("username", "");
String password = [Link]("password", "");
[Link](username);
[Link](password);

}
}

=>Output of the program

//9 Create / Read / Write data with database (SQLite)

Steps:
1. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the SDK as API
24(“Nougat”,Android 7.0).Click Finish Button.
4. Update the following code in activity_main.xml and [Link]

=>Coding part of Activity_main.xml

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


<AbsoluteLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="50dp"
android:layout_y="20dp"
android:text="Student Details"
android:textSize="30sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"
android:layout_y="110dp"
android:text="Enter Rollno:"
android:textSize="20sp" />

<EditText
android:id="@+id/Rollno"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="175dp"
android:layout_y="100dp"
android:inputType="number"
android:textSize="20sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"
android:layout_y="160dp"
android:text="Enter Name:"
android:textSize="20sp" />

<EditText
android:id="@+id/Name"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="175dp"
android:layout_y="150dp"
android:inputType="text"
android:textSize="20sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"
android:layout_y="210dp"
android:text="Enter Marks:"
android:textSize="20sp" />

<EditText
android:id="@+id/Marks"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="175dp"
android:layout_y="200dp"
android:inputType="number"
android:textSize="20sp" />

<Button
android:id="@+id/Insert"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="25dp"
android:layout_y="300dp"
android:onClick="onClickInsert"
android:text="Insert"
android:textSize="30dp" />

<Button
android:id="@+id/Delete"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="200dp"
android:layout_y="300dp"
android:onClick="onClickDelete"
android:text="Delete"
android:textSize="30dp" />

<Button
android:id="@+id/Update"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="25dp"
android:layout_y="400dp"
android:onClick="onClickUpdate"
android:text="Update"
android:textSize="30dp" />

<Button
android:id="@+id/View"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="200dp"
android:layout_y="400dp"
android:onClick="onClickView"
android:text="View"
android:textSize="30dp" />

<Button
android:id="@+id/ViewAll"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_x="100dp"
android:layout_y="500dp"
android:onClick="onClickViewAll"
android:text="View All"
android:textSize="30dp" />

</AbsoluteLayout>

=>Coding part of [Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {

EditText Rollno,Name,Marks;
SQLiteDatabase db;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);

Rollno=findViewById([Link]);
Name=findViewById([Link]);
Marks=findViewById([Link]);

db=openOrCreateDatabase("StudentDB", Context.MODE_PRIVATE, null);


[Link]("CREATE TABLE IF NOT EXISTS student(rollno VARCHAR,name VARCHAR,marks
INT);");

}
public void onClickInsert(View view) {

if ([Link]().toString().trim().length() == 0 ||
[Link]().toString().trim().length() == 0 ||
[Link]().toString().trim().length() == 0) {
showMessage("Error", "Please enter all values");
return;
}
[Link]("INSERT INTO student VALUES('" + [Link]() + "','" + [Link]() +
"','" + [Link]() + "');");

showMessage("Success", "Record added");


clearText();

public void onClickDelete(View view) {

if([Link]().toString().trim().length()==0)
{
showMessage("Error", "Please enter Rollno");
return;
}
Cursor c=[Link]("SELECT * FROM student WHERE rollno='"+[Link]()+"'",
null);
if([Link]())
{
[Link]("DELETE FROM student WHERE rollno='"+[Link]()+"'");
showMessage("Success", "Record Deleted");
}
else
{
showMessage("Error", "Invalid Rollno");
}
clearText();
}

public void onClickUpdate(View view){

if([Link]().toString().trim().length()==0)
{
showMessage("Error", "Please enter Rollno");
return;
}
Cursor c=[Link]("SELECT * FROM student WHERE rollno='"+[Link]()+"'",
null);
if([Link]()) {
[Link]("UPDATE student SET name='" + [Link]() + "',marks='" +
[Link]() +
"' WHERE rollno='"+[Link]()+"'");
showMessage("Success", "Record Modified");
}
else {
showMessage("Error", "Invalid Rollno");
}
clearText();
}

public void onClickView(View view) {

if([Link]().toString().trim().length()==0)
{
showMessage("Error", "Please enter Rollno");
return;
}
Cursor c=[Link]("SELECT * FROM student WHERE rollno='"+[Link]()+"'",
null);
if([Link]())
{
[Link]([Link](1));
[Link]([Link](2));
}
else
{
showMessage("Error", "Invalid Rollno");
clearText();
}
}

public void onClickViewAll(View view) {


Cursor c=[Link]("SELECT * FROM student", null);
if([Link]()==0)
{
showMessage("Error", "No records found");
return;
}
StringBuffer buffer=new StringBuffer();
while([Link]())
{
[Link]("Rollno: "+[Link](0)+"\n");
[Link]("Name: "+[Link](1)+"\n");
[Link]("Marks: "+[Link](2)+"\n\n");
}
showMessage("Student Details", [Link]());
}
public void showMessage(String title,String message)
{
[Link] builder=new [Link](this);
[Link](true);
[Link](title);
[Link](message);
[Link]();
}
public void clearText()
{
[Link]("");
[Link]("");
[Link]("");
[Link]();
}
}

=>Output of the program

10. Create an application to send SMS

Steps:
1. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the SDK as API
24(“Nougat”,Android 7.0).Click Finish Button.
4. Update the following code in activity_main.xml and [Link]

=>Coding part of Activity_main.xml

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


<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="16dp"
android:orientation="horizontal">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone Number:"
android:width="165sp"
android:textSize="18sp" />

<EditText
android:id="@+id/etPhoneNumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="Enter number"
android:inputType="phone" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="16dp"
android:orientation="horizontal">

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message to be Sent:"
android:width="165sp"
android:textSize="18sp" />

<EditText
android:id="@+id/etMessage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Enter message"
android:inputType="textMultiLine" />

</LinearLayout>

<Button
android:id="@+id/btnSendSMS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="32dp"
android:onClick="onClick"
android:text="SEND SMS" />

</LinearLayout>

=>Coding part of [Link]

package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

private static final int SMS_PERMISSION_CODE = 101;


EditText etPhoneNumber, etMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
etPhoneNumber = findViewById([Link]);
etMessage = findViewById([Link]);

if (!checkSMSPermission()) {
requestSMSPermission();
}
}
private boolean checkSMSPermission() {
return [Link](this,
[Link].SEND_SMS) == PackageManager.PERMISSION_GRANTED;
}

private void requestSMSPermission() {


[Link](this, new
String[]{[Link].SEND_SMS}, SMS_PERMISSION_CODE);
}
public void onClick(View view) {
String strPhoneNumber = [Link]().toString();
String strMessage = [Link]().toString();
try {
SmsManager smsManager = [Link]();
[Link](strPhoneNumber,null,strMessage,null, null);
[Link](getApplicationContext(), "Message Sent", Toast.LENGTH_LONG).show();
} catch (Exception e) {
[Link](getApplicationContext(), [Link](), Toast.LENGTH_LONG).show();
}
}
}

=>Output of the program


11. Create an application to send Email

Steps:
1. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the SDK as API
24(“Nougat”,Android 7.0).Click Finish Button.
4. Update the following code in activity_main.xml and [Link]

=>Coding part of Activity_main.xml

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


<LinearLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/etTo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="To"/>
<EditText
android:id="@+id/etSubject"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/etTo"
android:hint="Subject"/>
<EditText
android:id="@+id/etMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/etSubject"
android:hint="Message"/>
<Button
android:id="@+id/btnSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:layout_below="@id/etMessage"
android:text="Send"/>
</LinearLayout>

=>Coding part of [Link]

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
EditText etTo, etSubject, etMessage;

@Override
protected void onCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
setContentView([Link].activity_main);
etTo = findViewById([Link]);
etSubject = findViewById([Link]);
etMessage = findViewById([Link]);
}

public void onClick(View v){


String strTo = [Link]().toString().trim();
String strSubject = [Link]().toString().trim();
String strMessage = [Link]().toString().trim();
Intent intent = new Intent(Intent.ACTION_SEND);
[Link]("text/plain");
[Link](Intent.EXTRA_EMAIL, new String[]{strTo});
[Link](Intent.EXTRA_SUBJECT, strSubject);
[Link](Intent.EXTRA_TEXT, strMessage);
if ([Link](getPackageManager()) != null)
{
startActivity([Link](intent, "Choose an email client"));
}
}
}

12. Create an Application to Display Map based on the Current/given location

Steps:
1. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the SDK as API
24(“Nougat”,Android 7.0).Click Finish Button.
4. Update the following code in activity_main.xml and [Link]

=>Coding part of Activity_main.xml

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


<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<fragment
android:id="@+id/map"
android:name="[Link]"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>

=>Coding part of [Link]

package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {
private GoogleMap mMap;
private double latitude = 0.0;
private double longitude = 0.0;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager()
.findFragmentById([Link]);
if (mapFragment != null) {
[Link](this);
} else {
[Link](this, "Map Fragment Not Found", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onMapReady(@NonNull GoogleMap googleMap) {
mMap = googleMap;
// Add a marker at current or given location and move the camera
LatLng location = new LatLng(latitude, longitude);
[Link](new MarkerOptions().position(location).title("Marker"));
[Link]([Link](location, 15));
}
}

Coding part of [Link]

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


<manifest xmlns:android="[Link]
xmlns:tools="[Link]
<usespermission android:name="[Link].ACCESS_FINE_LOCATION" />
<usespermission android:name="[Link].ACCESS_COARSE_LOCATION" />
<usespermission android:name="[Link]" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/[Link]"
tools:targetApi="31">
<metadata
android:name="[Link].API_KEY"
android:value="YOUR_API_KEY_HERE" />

<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="[Link]" />

<category android:name="[Link]" />


</intent-filter>
</activity>
</application>

</manifest>

13. Create an Application with Login module. Check User name and password. On successful login
change textview “Login Successful”. On Login fail alert using Toast “Login Fail”

Steps:
1. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the SDK as API
24(“Nougat”,Android 7.0).Click Finish Button.
4. Update the following code in activity_main.xml and [Link]

=>Coding part of Activity_main.xml

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


<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="200dp"
android:text="Login Form"
android:textSize="40sp" />

<TextView
android:id="@+id/tvUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name"
android:textSize="24sp" />
<EditText
android:id="@+id/etUserName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter the User Name"
android:inputType="text"
android:textSize="24sp" />

<TextView
android:id="@+id/tvPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:textSize="24sp" />

<EditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter the Password"
android:inputType="textPassword"
android:textSize="24sp" />

<Button
android:id="@+id/btnLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="onClick"
android:text="Login" />

<TextView
android:id="@+id/tvMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome!!!"
android:textColor="#E91E63"
android:textSize="20sp" />

</LinearLayout>

=>Coding part of [Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

EditText etUserName,etPassword;
TextView tvMessage;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);

etUserName=(EditText)findViewById([Link]);
etPassword=(EditText)findViewById([Link]);
tvMessage=(TextView)findViewById([Link]);
}

public void onClick(View v)


{

[Link]("Welcome!!!");
if([Link]().toString().isEmpty())
{
[Link](this,"User name is empty", Toast.LENGTH_LONG).show();
return;
}
if([Link]().toString().isEmpty())
{
[Link](this,"Password is empty", Toast.LENGTH_LONG).show();
return;
}
if([Link]().toString().equals("Admin") &&
[Link]().toString().equals("Admin"))
{
[Link]("Login successful!!!");
}
else
{
[Link](this, "Login Fail", Toast.LENGTH_LONG).show();
}
}
}

=>OUTPUT OF THE PROGRAM


14. Learn to deploy Android applications

Steps to Deploy an Android Application

1. Prepare App (use Program 1 Hello world for this program)

2. Generate Signed APK (Android Package Kit):

a. In Android Studio, navigate to Build > Generate Signed Bundle/APK.

b. Follow the prompts to create a new keystore or use an existing one. A keystore is a binary file
that contains a set of private keys.
c. Configure the build type (release) and signing configuration.

d. Generate the signed APK file.

3. Test your signed APK:


a. Before distributing your app, test the signed APK to ensure that the signing process didn't
introduce any issues.
b. Install the APK on various devices and perform thorough testing.

c. Release on Google Play Console:

d. Sign in to the Google Play Console ([Link]

e. Create a new app entry if this is your first release or select an existing app.

f. Complete all the required information for the app listing, including the title, description,
screenshots, and categorization
g. Upload your signed APK file.

h. Set pricing and distribution options.

i. Optimize your store listing for search and conversion.


Once everything is set, click the "Publish" button to release your app to the Google Play Store.

4. Other Distribution Channels (Optional):

 Besides Google Play, you can distribute your app through other channels such as Amazon
Appstore, Samsung Galaxy Store, or third party app marketplaces.

 Each distribution channel may have its own requirements and submission process, so be sure
to follow their guidelines.

5. Monitor and Update:

 Keep an eye on user feedback and app performance metrics through the Google Play Console.

 Regularly update your app to fix bugs, add new features, and improve user experience based on
feedback.

You might also like