0% found this document useful (0 votes)
15 views59 pages

My Work

Uploaded by

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

My Work

Uploaded by

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

Enrollment No : 211260116032

Experiment No: 1

TITLE: Introduction to Android Programming and installation of Android Studio

EXCERCISE:

1) Introduction to Android Programming and installation of Android Studio.

Steps to Install Android Studio:


Step: 1 Android Environment must require jdk. So, install jdk. After installation we
have to set a path. Select Start menu > Computer > System Properties > Advanced
System Properties. Then open Advanced tab > Environment Variables, add new
system variable JAVA_HOME that points to your JDK folder, for example C:\
Program Files\Java\jdk1.7.0_21

Step: 2 Let's launch Android Studio.exe, Make sure before launch Android Studio,
Our Machine should require installed Java JDK. To install Java JDK, take a references
of Android environment setup.

Mobile Application Development (3161612)


Enrollment No : 211260116032

Step: 3 Once you launched Android Studio, it’s time to mention JDK5 path or
later version in android studio installer.

Step: 4 Below the image initiating JDK to android SDK

Mobile Application Development (3161612)


Enrollment No : 211260116032

Step: 5 Need to check the components, which are required to create applications,
below the image has selected Android Studio, Android SDK, Android Virtual
Machine and performance (Intel chip).

Step: 6 Need to specify the location of local machine path for Android studio and
Android SDK, below the image has taken default location of windows 8.1 x64 bit
architecture.

Step: 7 Need to specify the ram space for Android emulator by default it would take
512MB of local machine RAM.

Mobile Application Development (3161612)


Enrollment No : 211260116032

Step: 8 At final stage, it would extract SDK packages into our local machine, it would
take a while time to finish the task and would take approximate 3 to 4 GB of Hard disk
space.

Step: 9 After done all above steps perfectly, you must get finish button and it going to
be open android studio project with Welcome to android studio message as shown
below.

Mobile Application Development (3161612)


Enrollment No : 211260116032

Step: 10 You can start your application development by calling start a new android
studio project. In a new installation frame should ask Application name, package
information and location of the project.

Figure: Android device targeted

Figure: Add activity to mobile

Mobile Application Development (3161612)


Enrollment No : 211260116032

Figure: customize the activity

Figure: android studio home page

Quiz :
1) What is SDK?
Android SDK is a collection of libraries and Software Development tools
that are essential for Developing Android Applications. Whenever Google
releases a new version or update of Android Software, a corresponding SDK
also releases with it.

Mobile Application Development (3161612)


Enrollment No : 211260116032

In the updated or new version of SDK, some more features are


included which are not present in the previous version. Android SDK
consists of some tools which are very essential for the development of
Android Application. These tools provide a smooth flow of the
development process from developing and debugging. Android SDK is
compatible with all operating systems such as Windows, Linux, macOS, etc.

2) Enlist languages in which we can make android app.


•JavaScript
•Kotlin
•Objective C
•C++
•Flutter
•C#
•Python
•Swift

3) Differentiate between JVM and DVM.

JVM DVM
Runs Java bytecode on various platforms Runs Dalvik bytecode specifically on
Android
Target platform Cross-platform Target platform Android only

Execution model Stack-based Execution model Register-based

Application packaging JAR files Application packaging APK files

Mobile Application Development (3161612)


Enrollment No : 211260116032

Experiment No: 2

TITLE: Write an Android application to make a Button to open a new activity


from another activity.

EXCERCISE:

1) Write an Android application to make a Button to open a new activity from


another activity.

activity_main.xml:
<?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/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:ems="10"
android:hint="Enter Your Name"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:onClick="openActivity"
Mobile Application Development (3161612)
Enrollment No : 211260116032

android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/name" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="201260116512"
android:textColor="#673AB7"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.923"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

Mainactivity.java:
package com.example.firstmultiscreen;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle; import
android.view.View;

import android.widget.EditText;

public class MainActivity extends


AppCompatActivity {
private EditText name;
public static final String
EXTRA_NAME =
"com.example.firstmultiscreen.extra.NAME";
@Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void openActivity(View view)
{ name = findViewById(R.id.name);
String nameText =
name.getText().toString();
Intent intent = new Intent(this, MainActivity2.class);
intent.putExtra(EXTRA_NAME,nameText);
startActivity(intent);
Mobile Application Development (3161612)

}
Enrollment No : 211260116032

activity_main2.xml:
<?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=".MainActivity2">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#673AB7"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

Mainactivity2.java:
package com.example.firstmultiscreen;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity2 extends
AppCompatActivity {
private TextView textView;
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
textView = findViewById(R.id.textView);
Intent intent = getIntent();
String name =
intent.getStringExtra(MainActivity.EXTRA_NAME);
textView.setText("Your name is: "+ name);
}
} Mobile Application Development (3161612)
Enrollment No : 211260116032

OUTPUT:

HARSH

YOUR NAME IS HARSH

211260116032
211260116032

Quiz :
1) What are OnResume() and OnPause() call back methods in Activity life cycle.
OnResume() :
When the activity enters the Resumed state, it comes to the foreground, and
then the system invokes the onResume() callback. This is the state in which the app
interacts with the user. The app stays in this state until something happens to take
focus away from the app. Such an event might be, for instance, receiving a phone
call, the user’s navigating to another activity, or the device screen’s turning off.
Mobile Application Development (3161612)
Enrollment No : 211260116032

OnPause() :
The system calls this method as the first indication that the user is leaving
your activity (though it does not always mean the activity is being destroyed); it
indicates that the activity is no longer in the foreground (though it may still be
visible if the user is in multi-window mode). Use the onPause() method to
pause or adjust operations that should not continue (or should continue in
moderation) while the Activity is in the Paused state, and that you expect to
resume shortly. There are several reasons why an activity may enter this state.

2) Explain types of intent.

Explicit Intent
Explicit intent going to be connected internal world of application,
suppose if you wants to connect one activity to another activity, we can do
this quote by explicit intent, below image is connecting first activity to second
activity by clicking button. These intents designate the target component by its
name and they are typically used for application-internal messages - such as
an activity starting a subordinate service or launching a sister activity.

Implicit Intent
These intents do not name a target and the field for the
component name is left blank. Implicit intents are often used to activate
components in other applications.

Mobile Application Development (3161612)


Enrollment No : 211260116032

Experiment No: 3

TITLE: Write an Android application for calculator.

EXCERCISE:

1) Write an Android application for calculator.

Activity_main.xml:
<?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">

<TextView
android:id="@+id/enrollment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="201260116512"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.949"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<EditText
android:id="@+id/num1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="176dp"
android:ems="10"
Mobile Application Development (3161612)
Enrollment No : 211260116032

android:hint="Enter Number 1"


android:inputType="number"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/num2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="Enter number 2"
android:inputType="number"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/num1" /
>

<TextView
android:id="@+id/result"
android:layout_width="wrap_content“
android:layout_height="wrap_content"
android:layout_marginTop="68dp"
android:textSize="24sp"
app:layout_constraintBottom_toTopOf="@+id/num1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.039" />
<Button
android:id="@+id/add"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginEnd="36dp"
android:onClick="sum" android:text="+"
app:layout_constraintBottom_toBottomOf=
"@+id/sub"
app:layout_constraintEnd_toStartOf="@+i
Mobile Application Development (3161612)
d/sub" />
Enrollment No : 211260116032

<Button
android:id="@+id/sub"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:onClick="sub" android:text="-"
app:layout_constraintBottom_toBottomOf
="@+id/mul"
app:layout_constraintEnd_toStartOf="@+
id/mul" />

<Button
android:id="@+id/mul"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginEnd="36dp"
android:onClick="mul" android:text="*"
app:layout_constraintBottom_toBottomOf="@+id/div"
app:layout_constraintEnd_toStartOf="@+id/div" />

<Button
android:id="@+id/div"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginTop="56dp"
android:layout_marginEnd="48dp"
android:onClick="div" android:text="/"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/num2" /
>

</androidx.constraintlayout.widget.ConstraintLayout>

Mobile Application Development (3161612)


Enrollment No : 211260116032

Mainactivity.java:
package com.example.practicle4;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View; import
android.widget.EditText; import
android.widget.TextView;

public class MainActivity extends AppCompatActivity {

EditText num1;
EditText num2; TextView
result;
public void sum(View view){ int
i,j,ans;
result
=findViewById(R.id.result);
i =
Integer.parseInt(num1.getText
().toString());
j = Integer.parseInt(num2.getText().toString()); ans
= i + j; result.setText(Integer.toString(ans));
}
public void sub(View view){ int
i,j,ans;
result
=findViewById(R.id.result);
i =
Integer.parseInt(num1.getText
().toString());
j = Integer.parseInt(num2.getText().toString()); ans
= i - j; result.setText(Integer.toString(ans));
}
public void mul(View view){ int
i,j,ans;
result
=findViewById(R.id.result);
i =
Integer.parseInt(num1.getText
().toString());
j = Integer.parseInt(num2.getText().toString()); ans
= i * j; result.setText(Integer.toString(ans));
}
public void div(View view){ int
i,j,ans;
result
=findViewById(R.id.result);
i =
Integer.parseInt(num1.getText
Mobile Application Development (3161612)
().toString());
j = Integer.parseInt(num2.getText().toString()); ans
Enrollment No : 211260116032

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
num1 =(EditText) findViewById(R.id.num1);
num2 =(EditText) findViewById(R.id.num2);
}
}

OUTPUT:

211260116032

Mobile Application Development (3161612)


Enrollment No : 211260116032

QUIZ:

1) Explain EditText
In android, EditText is a user interface control which is used to allow the user to
enter or modify the text. While using EditText control in our android applications, we
need to specify the type of data the text field can accept using the inputType
attribute.

For example, if it accepts plain text, then we need to specify the inputType as “text”.
In case if EditText field is for password, then we need to specify the inputType as
“textPassword”.

2) Explain Toggle Button in Android.


A toggle button allows the user to change a setting between two states.

You can add a basic toggle button to your layout with the Toggle Button object.
Android 4.0 (API level 14) introduces another kind of toggle button called a switch
that provides a slider control, which you can add with a Switch object. SwitchCompat
is a version of the Switch widget which runs on devices back to API 7.

If you need to change a button's state yourself, you can use the
CompoundButton.setChecked() or CompoundButton.toggle() method.

3) Explain any four UI Components of Android application.


1. Views: These are the building blocks of an Android app's interface. They are
responsible for displaying text, images, buttons, lists, and other interactive
elements.
2. Layouts: Layouts define the arrangement of Views on the screen. They
determine how Views are positioned and sized relative to each other.
3. Activities: Activities represent a single screen within your app. They contain the
layout and Views and handle user interactions within that screen. Each Activity
has a lifecycle that defines its creation, display, and destruction.
4. Intents: Intents are messaging mechanisms that allow components to
communicate with each other. They can be used to launch new Activities, start
Services, or share data between components.

Mobile Application Development (3161612)


Enrollment No : 211260116032

Experiment No: 4
TITLE: Write an Android application that creates a simple Dialog box .
EXCERCISE:
1) Write an Android application that creates a simple Dialog box with only
1 button.
Activity_main.xml:
<?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">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open Dialog"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="201260116512"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.912"
app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
Mobile Application Development (3161612)
Enrollment No : 211260116032

Mainactivity.java:
package com.example.practicle5;
import androidx.appcompat.app.AppCompatActivity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle; import
android.view.View; import
android.widget.Button;

public class MainActivity extends AppCompatActivity


{ Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{ AlertDialog.Builder builder = new
AlertDialog.Builder(MainActivity.this);

builder.setMessage("Do you want to exit ?");


builder.setTitle("Alert !");
builder.setCancelable(false);

builder.setNegativeButton("No", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int
which) { dialog.cancel();
}
});

AlertDialog alertDialog = builder.create();


alertDialog.show();
}
});

Mobile Application Development (3161612)


Enrollment No : 211260116032

Output:

211260116032 211260116032

QUIZ:

1) What is a Dialog Box?

A Dialog Box in dreams can be a:

•Portal to communication: Explore yourself, guides, or subconscious through


conversations.
•Emotional window: Dive into the depths of specific emotions through
interactive experiences.
•Interactive story: Make choices shaping your dream's narrative based on
personal themes.
•Collective bridge: Connect to shared dreams and universal symbols for
deeper understanding.

Mobile Application Development (3161612)


Enrollment No : 211260116032

2) Explain each type of Dialog Box.

In android, you can create following types of Dialogs:


 Alert Dialog
 Date Picker Dialog
 Time Picker Dialog
 Custom Dialog

Alert Dialog: This Dialog is used to show a title, buttons (maximum 3 buttons
allowed), a list of selectable items, or a custom layout.
Date Picker Dialog: This dialog provides us with a pre-defined UI that allows the
user to select a date.
Time Picker Dialog: This dialog provides us with a pre-defined UI that allows the
user to select suitable time.
Custom Dialog: You can create your own custom dialog with custom
characteristics.

3) Enlist and define types of Menus in android.

Android Menus:
Android offers three main types of menus, each with a specific purpose:
1. Options Menu:
•Appears in the action bar (top).
•Holds app-wide actions like settings, search, or new items.
•Defined in XML and accessed through code.

2. Context Menu:
•Pops up on long-pressing an element.
•Offers actions related to the specific item.
•Can be a floating menu or an action mode (top bar).
•Defined and handled through code.

3. Popup Menu:
•Triggers from a button or view click.
•Offers a list of options related to that element.
•Defined in XML and triggered through code.

Mobile Application Development (3161612)


Enrollment No : 211260116032

Experiment No: 5
TITLE: Write an application to mark the daily route of travel in map.

EXCERCISE:
1) Write an application to mark the daily route of travel in map.

Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android
" xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity" />

MapsActivity.java:
package com.example.trackyourpath;
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle; import android.view.View;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.FragmentActivity;
import com.directions.route.AbstractRouting;
import com.directions.route.Route;
import com.directions.route.RouteException;
import com.directions.route.Routing;
import com.directions.route.RoutingListener;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;

Mobile Application Development (3161612)


Enrollment No : 211260116032

import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions;
import com.google.android.gms.tasks.Task;
import com.google.android.material.snackbar.Snackbar;
import java.util.ArrayList;
import java.util.List;

public class MapsActivity extends FragmentActivity


implements RoutingListener,
OnMapReadyCallback {

final static int LOCATION_REQUEST_CODE = 23;


GoogleMap googleMap;
FusedLocationProviderClient
fusedLocationProviderClient;
Location srcLocation;
LatLng start, end;
//polyline object
private List<Polyline>
polyLines = null;

@Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
fusedLocationProviderClient =
LocationServices.getFusedLocationProviderClient(this);
getMyLocation();

SupportMapFragment mapFragment =
(SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map);
@OverridemapFragment.getMapAsync(this);
public} void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions, @NonNull int[] grantResults)
{
super.onRequestPermissionsResult(requestCode,
permissions,
grantResults);
Mobile Application Development (3161612)
Enrollment No : 211260116032

if (requestCode == LOCATION_REQUEST_CODE) {
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
getMyLocation();
}
}
}

private void getMyLocation() {


if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new
String[]{Manifest.permission.ACCESS_FINE_LOCATION
}, LOCATION_REQUEST_CODE
);
return;
}
Task<Location> task =
fusedLocationProviderClient.getLastLocation();
task.addOnSuccessListener(location -> {
if (location != null) {
srcLocation = location;
LatLng latLng = new LatLng(location.getLatitude(),
location.getLongitude());
CameraUpdate cameraUpdate =
CameraUpdateFactory.newLatLngZoom(latLng, 16f);
googleMap.animateCamera(cameraUpdate)
;
}
});

if (googleMap != null)
{ googleMap.setMyLocationEnabled(true);
googleMap.setOnMapClickListener(lat
Lng -> { end = latLng;
googleMap.clear();
if (srcLocation != null) {
start = new
LatLng(srcLocation.getLatitude(),
srcLocation.getLongitude());
findRoutes(start,
end);
Mobile Application Development (3161612)
}
Enrollment No : 211260116032

});
}
}

@Override

public void onMapReady(GoogleMap


googleMap) { this.googleMap =
googleMap; getMyLocation();
}

void findRoutes(LatLng s, LatLng e) {


if (s == null || e == null)
{ Toast.makeText(MapsActivity.this, "Unable
to get location",
Toast.LENGTH_SHORT).show();
} else {
Routing routing = new Routing.Builder()
.travelMode(AbstractRouting.TravelMode.DRIV
ING)
.withListener(this)
.alternativeRoutes(true)
.waypoints(s, e)
// define your api key here.
.key("AIzaSyBqXOzJpvCZje0eLRWgSylDuPTUAcUu0
5k")
.buil
d();
routing.exec
ute();
}
}

@Override
public void
onRoutingFailure(R
outeException e) {
View parentLayout =
findViewById(android.R.id.content); Snackbar
snackbar = Snackbar.make(parentLayout,
e.toString(),
Snackbar.LENGTH_LONG);
snackbar.show();
}
Mobile Application Development (3161612)
Enrollment No : 211260116032

@Override
public void onRoutingSuccess(ArrayList<Route> route, int
shortestRouteIndex) {
if (polyLines != null)
{ polyLines.clear();
}

PolylineOptions polyOptions = new PolylineOptions();


LatLng polylineStartLatLng = null;
LatLng polylineEndLatLng = null;
polyLines = new ArrayList<>();

for (int i = 0; i < route.size(); i++) {


if (i == shortestRouteIndex) {

polyOptions.color(getResources().getColor(R.color.design_default
_color_primary)
);
polyOptions.width(7);
polyOptions.addAll(route.get(shortestRouteIndex)
.getPoints()); Polyline polyline =
googleMap.addPolyline(polyOptions);
polylineStartLatLng =
polyline.getPoints().get(0);
int k = polyline.getPoints().size();
polylineEndLatLng =
polyline.getPoints().get(k - 1);
polyLines.add(polyline);
}
}
MarkerOptions startMarker = new
MarkerOptions();
startMarker.position(polylineStartL
atLng); startMarker.title("My
Location");
googleMap.addMarker(startMarker);
MarkerOptions endMarker = new
MarkerOptions();
endMarker.position(polylin
eEndLatLng);
endMarker.title("Destinati
on");
googleMap.addMarker(endMar
ker);
}

@Override
public void
onRoutingCancelled
()
{ findRoutes(start
, end);
}
Mobile Application Development (3161612)
}
Enrollment No : 211260116032

AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk
/res/android" package="com.example.trackyourpath">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"
/>
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_roun
d" android:supportsRtl="true"
android:theme="@style/Theme.Trackyourpath">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<meta-data
android:name="com.google.android.gms.version" android
:value="@integer/google_play_services_version" />

<activity
android:name=".MapsActivity"
android:exported="true"
android:label="@string/title_a
ctivity_maps">
<intent-filter>
<action
android:name="android.inten
t.action.MAIN" />
<category
android:name="android.inten
t.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Mobile Application Development (3161612)


Enrollment No : 211260116032

OUTPUT:

Quiz:

1) Why should you keep your API key secure?

API keys are an integral part of any application development. They are used to
access third-party services or internal APIs, and can be used to authenticate and
authorize users. However, API keys can also be vulnerable to misuse and abuse,
so it is important to ensure they are securely managed and monitored.

Mobile Application Development (3161612)


Enrollment No : 211260116032

Experiment No: 6
TITLE: Write an application to record video and audio on topic ‚Intent‛ and
play the audio and video.

EXCERCISE:
1) Write an application to record video and audio on topic ‚Intent‛ and
play the audio and video.

Activity_main.xml:
<?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:gravity="center"
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">

<Button
android:id="@+id/recordVideo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"
android:text="@string/record_video" />

<Button
android:id="@+id/playVideo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="50dp"
android:text="@string/play_video" />

Mobile Application Development (3161612)


Enrollment No : 211260116032

<Button
android:id="@+id/recordAudio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="50dp"
android:text="@string/record_audio" />

<Button
android:id="@+id/stopRecordAudio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="50dp"
android:text="@string/stop_recording_audio" />

<Button
android:id="@+id/playAudio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="50dp"
android:text="Play Audio" />

<Button
android:id="@+id/stopPlayingAudio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="50dp"
android:text="@string/stop_playing_audio" />
</LinearLayout>

Mobile Application Development (3161612)


Enrollment No : 211260116032

MainActivity.java:
package com.example.practicle9;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.widget.Button;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import java.io.IOException;
import java.util.Random;
import static
android.Manifest.permission.RECORD_AUDIO;
import static
android.Manifest.permission.WRITE_EXTERNAL_STORA
GE;

public class MainActivity extends AppCompatActivity { public


static final int RequestPermissionCode = 1; private final
static int VIDEO_CAPTURE_CODE = 101;
Button btnRecordVideo, btnPlayVideo, btnRecordAudio,
btnStopRecordingAudio, btnPlayAudio, btnStopPlayingAudio;
Uri videoUri = null;
String audioSavePathInDevice = null;
MediaRecorder audioRecorder; MediaPlayer
audioPlayer;
Random random;
String RandomAudioFileName =
"ABCDEFGHIJKLMNOP";

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

btnRecordVideo =
findViewById(R.id.recordVideo);
btnPlayVideo =Application
Mobile findViewById(R.id.playVideo);
Development (3161612)
btnRecordAudio =
findViewById(R.id.recordAudio);
Enrollment No : 211260116032
btnPlayVideo.setEnabled(false);
btnStopRecordingAudio.setEnabled(false);
btnPlayAudio.setEnabled(false);

random = new Random();


btnRecordVideo.setOnClickListener(v -> {

Intent intent = new


Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (intent.resolveActivity(getPackageManager()) != null)
{ startActivityForResult(intent, VIDEO_CAPTURE_CODE);
}
});
btnPlayVideo.setOnClickListener(v -> {
if (videoUri != null) {
Intent intent = new Intent(this, VideoPlayer.class);
intent.putExtra("videoUri", videoUri.toString());
startActivity(intent);
}
});
btnRecordAudio.setOnClickListener(v -> {
if (checkPermission())
{ audioSavePathInDevice =
Environment.getExternalStorageDirectory().getAbsolutePath() + "/" +
createRandomAudioFileName(5) + "AudioRecording.3gp";
makeAudioRecorder();
try {
audioRecorder.prepare(); audioRecorder.start();
btnRecordAudio.setEnabled(false);
btnStopRecordingAudio.setEnabled(true);
Toast.makeText(this, "Recording started...",
Toast.LENGTH_SHORT).show();
} catch (IllegalStateException | IOException e)
{ e.printStackTrace();
}
} else {
requestPermission();
}
});
btnStopRecordingAudio.setOnClickListener(v ->
{ audioRecorder.stop(); btnRecordAudio.setEnabled(true);
btnStopRecordingAudio.setEnabled(false);
btnPlayAudio.setEnabled(true);
btnStopPlayingAudio.setEnabled(false); Toast.makeText(this,
"Audio Recorded Successfully!!",
Toast.LENGTH_SHORT).show();
});
btnPlayAudio.setOnClickListener(v ->
{ btnRecordAudio.setEnabled(false);

Mobile Application Development (3161612)


Enrollment No : 211260116032

btnStopRecordingAudio.setEnabled(false);
btnStopPlayingAudio.setEnabled(true); audioPlayer =
new MediaPlayer();
try {
audioPlayer.setDataSource(audioSavePathInDevice);
audioPlayer.prepare();
} catch (IOException e) {
e.printStackTrace();

audioPlayer.start();
}
Toast.makeText(this, "Playing audio...",
Toast.LENGTH_SHORT).show();
});
btnStopPlayingAudio.setOnClickListener(v ->
{ btnStopRecordingAudio.setEnabled(false);
btnRecordAudio.setEnabled(true);
btnStopPlayingAudio.setEnabled(false);
btnPlayAudio.setEnabled(true);
if (audioPlayer != null) {
audioPlayer.stop();
audioPlayer.release();
makeAudioRecorder();
}
});
}

public void makeAudioRecorder(){


audioRecorder = new MediaRecordera();
audioRecorder.setAudioSource(MediaRecorder.AudioSource.MC);
audioRecorder.setOutputFormat(MediaRecorder.OutputFormat.TH
REE_GPP)
audioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AM
R_NB);
audioRecorder.setOutputFile(audioSavePathInDevice);
}

public String createRandomAudioFileName(int


string) { StringBuilder stringBuilder = new
StringBuilder(string); int i = 0;
while (i < string) {

stringBuilder.append(RandomAudioFileName.charAt(random.nextInt(
RandomAudioFileN ame.length())));
i++;
}
return stringBuilder.toString();
}

Mobile Application Development (3161612)


Enrollment No : 211260116032

@Override
protected void onActivityResult(int requestCode, int
resultCode, @Nullable Intent
data) {
super.onActivityResult(requestCode, resultCode,
data);
if (requestCode == VIDEO_CAPTURE_CODE &&
resultCode == RESULT_OK) { videoUri =
data.getData();
if (videoUri != null) {
btnPlayVideo.setEnabled(true);
}
}
} private void requestPermission()
{ ActivityCompat.requestPermissions(MainAc
tivity.this, new
String[]{WRITE_EXTERNAL_STORAGE,
RECORD_AUDIO},
RequestPermissionCode);
}
@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions, @NonNull int[]
grantResults) {
super.onRequestPermissionsResult(requestCode,
permissions,
grantResults);
if (requestCode == RequestPermissionCode) {
if (grantResults.length > 0) {
boolean storagePermission =
grantResults[0] ==
PackageManager.PERMISSION_GRANTED;
boolean recordPermission =
grantResults[1] ==
PackageManager.PERMISSION_GRANTED;
if (!
storagePermission && !
recordPermission) {
Toast.makeText(MainActivity.this,
"Permission Denied", Toast.LENGTH_LONG).show();
}
}
}
}
public boolean checkPermission() {
int result =
ContextCompat.checkSelfPermission(getApplicationCo
ntext(),
WRITE_EXTERNAL_STORAGE);
int result1 =
ContextCompat.checkSelfPermission(getApplicationContext
(), RECORD_AUDIO);
return result ==
PackageManager.PERMISSION_GRANTED && result1 ==
Mobile Application Development (3161612)
PackageManager.PERMISSION_GRANTED;
}
}
Enrollment No : 211260116032

activity_video_player.xml:
<?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" android:padding="16dp"
tools:context=".VideoPlayer">
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

VideoPlayer.java:
package com.example.practicle9;

import androidx.appcompat.app.AppCompatActivity;

import android.net.Uri;
import android.os.Bundle;
import android.widget.VideoView;

public class VideoPlayer extends AppCompatActivity {


VideoView videoView;

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

videoView = findViewById(R.id.videoView); Uri videoUri =


Uri.parse(getIntent().getExtras().getString("videoUri"));
videoView.setVideoURI(videoUri);
videoView.start();
}
}
Mobile Application Development (3161612)
Enrollment No : 211260116032

AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk
/res/android" package="com.example.practicle9">
<uses-permission android:name="android.permission.RECORD
_AUDIO" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
/>
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Practicle9">
<activity
android:name=".VideoPlayer"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action
android:name="android.inten
t.action.
MAIN" />

<category
android:name="android.inten
t.category.

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

</manifest>

Mobile Application Development (3161612)


Enrollment No : 211260116032

String.xml:
<resources>
<string name="app_name">practicle9</string>
<string name="play_audio" />
<string name="record_video">Record Video</string>
<string name="play_video">Play Video</string>
<string name="record_audio">Record Audio</string>
<string name="stop_recording_audio">Stop Recording
Audio</string>
<string name="stop_playing_audio">Stop Playing Audio</string>
</resources>

OUTPUT:

PRACTICAL 6

Mobile Application Development (3161612)


Enrollment No : 211260116032

Quiz:
1) What is android media player.
The MediaPlayer API is a built-in Android class used for playing audio and
video files. It supports several different media formats and can play media files that are
stored in your application's resources, on the local file system, or at a URI accessible over
the Internet

2) Describe the API or classes to handle audio and video in Android.


Audio: 1. MediaPlayer class: - Handles audio playback.
2. AudioManager class: - Manages audio settings.
3. SoundPool class: - Manages short audio clips.
Video: 1. VideoView class: - Displays videos.
2. MediaPlayer class (for video): - Handles video playback.
3. MediaController class: - Provides video playback controls.

Mobile Application Development (3161612)


Enrollment No : 211260116032

Experiment No: 7

TITLE: Write an android application to insert Customer Details (cID,


cName, cOrderID) in SQLite Database in Android.

EXCERCISE:

1) Write an android application to insert Customer Details (cID,


cName,cOrderID) in SQLite Database in Android.

Activity_main.xml:
<?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">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="409dp"
android:layout_height="729dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.floatingactionbutton.
FloatingActionButton android:id="@+id/add_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

Mobile Application Development (3161612)


Enrollment No : 211260116032

android:layout_marginEnd="45dp"
android:layout_marginBottom="43dp"

android:background="@color/black"
android:clickable="true"
android:focusable="true"
app:layout_constraintBottom_toBottom
Of="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.988"
app:srcCompat="@drawable/baseline_add"/>
</
androidx.constraintlayout.widget.ConstraintLayout
>
. MainActivity.java :
package com.example.customerdetails;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle; import
android.view.View;

import com.google.android.material.floatingactionbutton.
FloatingActionButton;

public class MainActivity extends AppCompatActivity

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

Mobile Application Development (3161612)


Enrollment No : 211260116032

recyclerView = findViewById(R.id.recyclerview);
add_button = findViewById(R.id.add_button);
add_button.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,
AddActivity.class); startActivity(intent);
}
});
}
}

Activity_add.xml :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk
/res/android" xmlns:tools="
http://schemas.android.com/tools" xmlns:app="
http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AddActivity"
android:padding="30dp">

<EditText
android:id="@+id/c_ID_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="148dp"
android:ems="10"
android:hint="Customer id"
android:inputType="number"
app:layout_constraintEnd_toEndOf="parent
"
app:layout_constraintHorizontal_bias="0.315"
app:layout_constraintStart_toStartOf="parent
"
app:layout_constraintTop_toTopOf="parent" />
Mobile Application Development (3161612)
Enrollment No : 211260116032

<EditText android:id="@+id/c_NAME_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp" android:ems="10"
android:hint="Customer name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.315"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/c_ID_input" />

<EditText android:id="@+id/c_ORDERID_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:ems="10"
android:hint="Customer Orderid"
android:inputType="number"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.315"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/
c_NAME_input"/>

<Button android:id="@+id/add_button"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginTop="40dp"
android:text="ADD"
android:textAllCaps="false"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/c_ORDERID_input"
</androidx.constraintlayout.widget.ConstraintLayout>

Mobile Application Development (3161612)


Enrollment No : 211260116032

AddActivity.java :
package com.example.customerdetails;

import androidx.appcompat.app.AppCompatActivity; import


android.os.Bundle;
import android.view.View; import
android.widget.Button; import
android.widget.EditText;

public class AddActivity extends AppCompatActivity

{ EditText c_NAME_input, c_ORDER_input;


Button add_button;

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

c_NAME_input = findViewById(R.id.c_NAME_input); c_ORDER_input


= findViewById(R.id.c_ORDERID_input); add_button =
findViewById(R.id.add_button);

add_button.setOnClickListener(new
View.OnClickListener() { @Override
public void onClick(View v)
{ MyDatabaseHelper mydb = new
MyDatabaseHelper(AddActivity.this);
mydb.addCustomer(c_NAME_input.getText().toString().
trim(),
Integer.valueOf(c_ORDER_input.getText().toString().trim()
));
}
});
}
}

Mobile Application Development (3161612)


Enrollment No : 211260116032

MyDatabaseHelper.java :
package com.example.customerdetails;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

import androidx.annotation.Nullable;

public class MyDatabaseHelper extends SQLiteOpenHelper {


private Context context;
private static final String DATABASE_NAME ="
Customer_library.db"; private static int DATABASE_VERSION = 1

private static final String TABLE_NAME ="Customer";


private static final String COLUMN_ID ="c_ID";
private static final String COLUMN_NAME ="c_NAME";
private static final String COLUMN_ORDERID ="c_ORDERID";

public MyDatabaseHelper(@Nullable Context context)


{ super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.context = context;
}

@Override
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE " + TABLE_NAME +
" (" + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,

Mobile Application Development (3161612)


Enrollment No : 211260116032

" +
COLUMN_NAME + " TEXT, " +
COLUMN_ORDERID + " INTEDER);";
db.execSQL(query);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion,
int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
void addCustomer(String c_NAME,Integer c_ORDERID)
{ SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(COLUMN_NAME, c_NAME); cv.put(COLUMN_ORDERID,
c_ORDERID);
long result = db.insert(TABLE_NAME,null,cv);
if(result == -1){
Toast.makeText(context,"Failed",Toast.LENGTH_SH
ORT).
show();
}
else {
Toast.makeText(context,"Added
Successfully",Toast.LENGTH_SHORT).show();
}

}
}

Mobile Application Development (3161612)


Enrollment No : 211260116032

OUTPUT:
Practical 7

QUIZ: 211260116032

Answer the Followings:


1) SQLite is a ?
C. Relational database
2) What do you mean by NoSQL? How it is differ from
relational database?
NoSQL is a flexible, schema-less database category
designed for dynamic data, offering horizontal scalability
and sacrificing some ACID properties.

Differences: NoSQL allows flexible data models, dynamic


schemas, and horizontal scalability, while traditional
RDBMS relies on fixed schemas, vertical scaling, and strong
ACID properties.
Mobile Application Development (3161612)
Enrollment No : 211260116032

Experiment No: 8
TITLE: Write an android application to perform CRUD
operation on Firebase.

EXCERCISE:
1) Write an android application to perform CRUD
operation on Firebase.

import android.os.Bundle;

import android.text.TextUtils;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

import androidx.annotation.NonNull;
import
androidx.appcompat.app.AppCompatActivity;

import com.google.firebase.database.DataSnapshot; import


com.google.firebase.database.DatabaseError; import
com.google.firebase.database.DatabaseReference; import
com.google.firebase.database.FirebaseDatabase; import
com.google.firebase.database.ValueEventListener;

public class MainActivity extends AppCompatActivity

{ private EditText editTextName, editTextAge;


private Button buttonAdd, buttonUpdate, buttonDelete,
buttonRetrieve;

private DatabaseReference databaseReference;

Mobile Application Development (3161612)


Enrollment No : 211260116032

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

editTextName = findViewById(R.id.editTextName);
editTextAge = findViewById(R.id.editTextAge);
buttonAdd = findViewById(R.id.buttonAdd);
buttonUpdate = findViewById(R.id.buttonUpdate);
buttonDelete = findViewById(R.id.buttonDelete);
buttonRetrieve = findViewById(R.id.buttonRetrieve);

databaseReference =
FirebaseDatabase.getInstance().getReference().child("Users")
;
buttonAdd.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) { addUser();
}
});
buttonUpdate.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v)
{ updateUser();
}
});
buttonDelete.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v)
{ deleteUser();
}
});

buttonRetrieve.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v)
{ retrieveUsers();
}
});
}

Mobile Application Development (3161612)


Enrollment No : 211260116032

private void addUser() {


String name = editTextName.getText().toString().trim();
String ageStr = editTextAge.getText().toString().trim();

if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(ageStr))


{ int age = Integer.parseInt(ageStr);
String id = databaseReference.push().getKey();

if (id != null) {
User user = new User(id, name, age);
databaseReference.child(id).setValue(user);
Toast.makeText(this, "User added successfully",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Error generating user ID",
Toast.LENGTH_SHORT).show();

}
} else {
Toast.makeText(this, "Please enter name and
age", Toast.LENGTH_SHORT).show();
}
}

private void updateUser() {


String id =
editTextName.getText().toString().trim(); String
name = editTextName.getText().toString().trim();
String ageStr =
editTextAge.getText().toString().trim();

if (!TextUtils.isEmpty(id) && !
TextUtils.isEmpty(name) &&
!TextUtils.isEmpty(ageStr)) {
int age =
Integer.parseInt(ageStr); User user
= new User(id, name, age);
databaseReference.child(id).setValue(user);
Toast.makeText(this, "User updated
successfully",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Please enter user ID, name,
Mobile Application Development (3161612)
and age", Toast.LENGTH_SHORT).show();
}
Enrollment No : 211260116032

private void deleteUser() {


String id = editTextName.getText().toString().trim();

if (!TextUtils.isEmpty(id))
{ databaseReference.child(id).removeValue();
Toast.makeText(this, "User deleted successfully",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Please enter user ID",
Toast.LENGTH_SHORT).show();
}
}

private void retrieveUsers()


{ databaseReference.addListenerForSingleValueEvent(new
ValueEventListener()
{
@Override
public void onDataChange(@NonNull DataSnapshot snapshot)
{ StringBuilder stringBuilder = new StringBuilder();
for (DataSnapshot dataSnapshot : snapshot.getChildren())
{ User user = dataSnapshot.getValue(User.class);

if (user != null) {
stringBuilder.append("ID: ").append(user.getId()).append("\
n"); stringBuilder.append("Name:
").append(user.getName()).append("\n");
stringBuilder.append("Age:
").append(user.getAge()).append("\n\n");
}}
Toast.makeText(MainActivity.this,
stringBuilder.toString(), Toast.LENGTH_LONG).show();
}

@Override
public void onCancelled(@NonNull DatabaseError error)
{ Toast.makeText(MainActivity.this, "Error retrieving
users",
Toast.LENGTH_SHORT).show();
}});
}
}

Mobile Application Development (3161612)


Enrollment No : 211260116032

OUTPUT:

QUIZ:
1)Describe firebase database.
The Firebase Realtime Database is a cloud-hosted NoSQL database
that lets you store and sync data between your users in real
time.

2)What are CRUD operations.


. CRUD is an acronym that comes from the world of computer
programming and refers to the four functions that are
considered necessary to implement a persistent storage
application: create, read, update and delete.

Mobile Application Development (3161612)


Enrollment No : 211260116032

Experiment No: 9

TITLE: Write an android application to perform API


calling with Retrofit.

EXCERCISE:
1) Write an android application to perform API calling
with Retrofit.

import android.os.Bundle;
import android.util.Log;
import
android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import
retrofit2.converter.gson.GsonC
onverterFactory;

public class MainActivity extends

AppCompatActivity { private TextView

textViewResult;
private JsonPlaceholderApi jsonPlaceholderApi;

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

textViewResult =
findViewById(R.id.text_view_result);

// Retrofit setup
Retrofit retrofit = new
Retrofit.Builder()
.baseUrl("https://Mobile Application Development (3161612)
jsonplaceholder.typicode.com/") //
Base URL of the API
Enrollment No : 211260116032

// Create instance of the API interface


jsonPlaceholderApi =
retrofit.create(JsonPlaceholderApi.class);

// Call API method and handle response


Call<Post> call = jsonPlaceholderApi.getPost(1); //
Example call to retrieve a post with ID 1
call.enqueue(new Callback<Post>() {
@Override

public void onResponse(Call<Post> call, Response<Post>


response)
{ if (!response.isSuccessful())
{ textViewResult.setText("Code
: " + response.code());
return;
}
Post post =
response.body();
String content = "";
if (post != null) {
content += "ID: " + post.getId() + "\
n"; content += "User ID: " +
post.getUserId() +
"\n"; content += "Title: " +
post.getTitle() + "\n"; content +=
"Text: " + post.getText() + "\n\n";
}
textViewResult.setText(content);
}

@Override
public void onFailure(Call<Post> call,
Throwable t)
{ textViewResult.setText(t.getMessage());
}
});
}
}

Mobile Application Development (3161612)


Enrollment No : 211260116032

OUTPUT:

QUIZ:
1.What is an API and an API call.
. Application programming interfaces (APIs) are a way
for one program to interact with another. API calls are
the medium by which they interact.

2.What are other ways except retrofit library to


make an API call from android application.
. Other ways to make API calls in Android include using
HttpURLConnection, Volley, OkHttp, AsyncTask, Kotlin
Coroutines with HttpClient, and libraries like Apollo-
Android for GraphQL.

Mobile Application Development (3161612)


Enrollment No : 211260116032

Experiment No: 10
TITLE: Write an Android application to perform text to
speech and generate apk file.

EXCERCISE:
1) Write an Android application to perform text to
speech and generate apk file

Activity_main.xml:
<?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:paddingLeft="16dp"
android:paddingTop="16dp"
android:paddingRight="16dp"
android:paddingBottom="16dp"
tools:context=".MainActivity">

<EditText android:id="@+id/inputText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter text to speak"
android:layout_marginBottom="16dp"
android:inputType="textMultiLine"
android:maxLines="3"
android:layout_above="@id/speakButton" />

<Button
android:id="@+id/speakButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Speak"
android:layout_centerInParent="true"
android:layout_alignParentBottom="true" />

</RelativeLayout>

Mobile Application Development (3161612)


Enrollment No : 211260116032

MainActivity.java:
package com.example.practical10;

import
androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import
android.speech.tts.TextToSpeech.OnInitListener;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.util.Locale;

public class MainActivity extends AppCompatActivity implements

OnInitListener { private TextToSpeech textToSpeech;


private EditText inputText;
private Button speakButton;

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

textToSpeech = new TextToSpeech(this, this);


inputText = findViewById(R.id.inputText);
speakButton =
findViewById(R.id.speakButton);

speakButton.setOnClickListener(new
View.OnClickListener() { @Override
public void onClick(View v) {
String textToRead =
inputText.getText().toString(); if (!
textToRead.isEmpty()) {
textToSpeech.speak(textToRead,
TextToSpeech.QUEUE_FLUSH,
null, null);
}
}
});
}
Mobile Application Development (3161612)
Enrollment No : 211260116032

@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = textToSpeech.setLanguage(Locale.US);

if (result == TextToSpeech.LANG_MISSING_DATA ||
result == TextToSpeech.LANG_NOT_SUPPORTED)
{ Log.e("TextToSpeech", "Language is not supported or missing
data");
} else {
speakButton.setEnabled(true);
}
} else {
Log.e("TextToSpeech", "Initialization failed");
}
}
@Override
protected void onDestroy() {
if (textToSpeech != null)
{
textToSpeech.stop();
textToSpeech.shutdown();
}
super.onDestroy();
}
}

Mobile Application Development (3161612)


Enrollment No : 211260116032

OUTPUT:

QUIZ:
1.What is an apk file.
An APK file (Android Package Kit file format) is the file
format for applications used on the Android operating
system (OS). An APK file contains all the data an app
needs, including all of the software program's code, assets
and resources.

2.Write steps to publishing android applications.


Steps to publishing applications :
1.Prepare 9. Upload
APK
2.Keystore 10. Pricing
3.Release Build 11. In-App Purchases
4.Sign 12. Publish
5.Optimize 13. Monitor & Update
6.Release APK
7.Developer Account
Mobile Application Development (3161612)

You might also like