My Work
My Work
Experiment No: 1
EXCERCISE:
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.
Step: 3 Once you launched Android Studio, it’s time to mention JDK5 path or
later version in android studio installer.
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.
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.
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.
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.
JVM DVM
Runs Java bytecode on various platforms Runs Dalvik bytecode specifically on
Android
Target platform Cross-platform Target platform Android only
Experiment No: 2
EXCERCISE:
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;
}
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
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.
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.
Experiment No: 3
EXCERCISE:
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
<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>
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;
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
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”.
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.
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;
builder.setNegativeButton("No", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int
which) { dialog.cancel();
}
});
Output:
211260116032 211260116032
QUIZ:
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.
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.
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;
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;
@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();
}
}
}
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
@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();
}
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>
OUTPUT:
Quiz:
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.
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" />
<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>
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;
@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);
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();
}
});
}
stringBuilder.append(RandomAudioFileName.charAt(random.nextInt(
RandomAudioFileN ame.length())));
i++;
}
return stringBuilder.toString();
}
@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;
@Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_player);
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>
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
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
Experiment No: 7
EXCERCISE:
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"
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;
{ RecyclerView recyclerView;
FloatingActionButton add_button;
@Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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>
AddActivity.java :
package com.example.customerdetails;
@Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add);
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()
));
}
});
}
}
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;
@Override
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE " + TABLE_NAME +
" (" + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,
" +
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();
}
}
}
OUTPUT:
Practical 7
QUIZ: 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;
@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();
}
});
}
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();
}
}
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
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();
}
}
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();
}});
}
}
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.
Experiment No: 9
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;
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
@Override
public void onFailure(Call<Post> call,
Throwable t)
{ textViewResult.setText(t.getMessage());
}
});
}
}
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.
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>
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;
@Override
protected void onCreate(Bundle
savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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();
}
}
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.