Manikandan Development Manual
Manikandan Development Manual
RECORD
SEMESTER: V
21UCS509
MOBILE APPLICATIONS DESIGN AND
DEVELOPMENT LABORATORY
NAME:
ROLL No.
REG. No.
DEPT.
SETHU INSTITUTE OF TECHNOLOGY
PULLOOR-626 115, KARIAPATTI
TALUK.VIRUDHUNAGAR DISTRICT
PRACTICAL RECORD
BONAFIDE CERTIFICATE
Reg.No:
MARK SIGNATURE
EX.NO DATE TITLE OF THE
. EXPERIMENT
1. 04-07-23 Android Application that uses GUI
components, Font and Colors
2. 18-07-23 Develop an android application to
demonstrate simple event handling.
3. 01-08-23 Develop an android application to
implement Menus.
4. 22-08-23 Develop an android application to
implement Fragments.
5. 29-08-23 Develop an android application
customized Sending Email, Sending
SMS and Phone Calls using Intent
and intent filter
Aim:
To develop a Simple Android Application that uses GUI components, Font and Colors.
Procedure:
1 .Start the program .
2. Importing necessary packages .
3. Then develop and design XML file and JAVA file .
4. Run the program in android studio and display the output .
5. Stop .
▪ Then select the Minimum SDK as shown below and click Next.
▪ Then select the Empty Activity and click Next.
▪ Then delete the code which is there and type the code as given below.
▪
package com.example.exp1;
import android.app.Activity;
import android.graphics.*;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity
{
float font =24;
int i=1;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView t1=(TextView)
findViewById(R.id.textView1);
Button b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
t1.setTextSize(font);
font=font+4;
if(font==40)
font=20;
}
});
Button b2 = (Button) findViewById(R.id.button2);
b2.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
switch(i)
{
case 1:
t1.setTextColor(Color.parseColor("#0000FF"));
break;
case 2:
t1.setTextColor(Color.parseColor("#00FF00"));
break;
case 3:
t1.setTextColor(Color.parseColor("#FF0000"));
break;
case 4:
t1.setTextColor(Color.parseColor("#800000"));
break;
}
i++;
if(i==5)
i=1;
}
});
}
}
Output:
Result:
Thus the given program To develop a Simple Android Application that uses GUI components, Font and
Colors output is verified and executed successfully .
EX No: 2 Develop an android application to demonstrate simple event handling. Date:
Events are the actions performed by the user in order to interact with the application, for e.g.
pressing a button or touching the screen. The events are managed by the android framework in
the FIFO manner i.e. First In – First Out. Handling such actions or events by performing the
desired task is called Event Handling.
Overview of the input event management
• Event Listeners: It is an interface in the View class. It contains a single callback method.
Once the view to which the listener is associated is triggered due to user interaction, the
callback methods are called.
• Event Handlers: It is responsible for dealing with the event that the event listeners
registered for and performing the desired action for that respective event.
• Event Listeners Registration: Event Registration is the process in which an Event
Handler gets associated with an Event Listener so that this handler is called when the
respective Event Listener fires the event.
• Touch Mode: When using an app with physical keys it becomes necessary to give focus to
buttons on which the user wants to perform the action but if the device is touch-enabled
and the user interacts with the interface by touching it, then it is no longer necessary to
highlight items or give focus to particular View. In such cases, the device enters touch
mode and in such scenarios, only those views for which the is Focusable InTouchMode() is
true will be focusable, e.g. plain text widget.
For e.g. if a button is pressed then this action or event gets registered by the event listener
and then the task to be performed by that button press is handled by the event handler, it can
be anything like changing the color of the text on a button press or changing the text itself, etc.
Event Listeners and their respective event handlers
• OnClickListener() – This method is called when the user clicks, touches, or focuses on
any view (widget) like Button, ImageButton, Image, etc. Event handler used for this is
onClick().
• OnLongClickListener() – This method is called when the user presses and holds a
particular widget for one or more seconds. Event handler used for this is onLongClick().
• OnMenuItemClickListener() – This method is called when the user selects a menu
item. Event handler used for this is onMenuItemClick().
• OnTouch() – This method is called either for a movement gesture on the screen or a press
and release of an on-screen key. Event handler used for this is onTouch().
There are various other event listeners available which can be used for different requirements
and can be found in the official documentation.
Aim :
package com.example.myapplication;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progress = new ProgressDialog(this);
b1=(Button)findViewById(R.id.button);
b2=(Button)findViewById(R.id.button2);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView txtView = (TextView) findViewById(R.id.textView);
txtView.setTextSize(25);
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView txtView = (TextView) findViewById(R.id.textView);
txtView.setTextSize(55);
}
});
}
}
Code for Activity_main.xml:
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Event Handling "
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="30dp"/>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20sp"
android:gravity="center"
android:text="21IT048 "
android:textSize="20sp"
android:fontFamily="sans-serif-medium"
android:textStyle="bold" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tutorials point "
android:textColor="#ff87ff09"
android:textSize="30dp"
android:layout_above="@+id/imageButton"
android:layout_centerHorizontal="true"
android:layout_marginBottom="40dp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:src="@drawable/abc"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Small font"
android:id="@+id/button"
android:layout_below="@+id/imageButton"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Font"
android:id="@+id/button2"
android:layout_below="@+id/button"
android:layout_alignRight="@+id/button"
android:layout_alignEnd="@+id/button" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="@+id/textView"
android:layout_below="@+id/button2"
android:layout_centerHorizontal="true"
android:textSize="25dp" />
</RelativeLayout>
Sample Output :
Result :
Thus the given program To Develop an android application to demonstrate simple event handling
output is verified and executed successfully .
Ex No: 3 Develop an android application to implement Menus. Date:
In Android apps, you can make use of three standard menus supported within the platform: the
context menu, the options menu, and submenus. This is a common feature in almost all apps, so
your users will be used to the menu appearing in this way
To implement an options menu for an Activity in an Android app, a few fairly straightforward
steps are required.
Step 1: Open an Activity Class
Select your application package and choose “File”, “New”, then “Class” and enter a name of your
choice. Remember to make your class extend the Activity class and add it to the application
Manifest.
Step 2: Create a Resources Folder
The “res” folder holds all of your application resources. To create a menu, you need a menu
folder, so create one inside the “res” folder by selecting it and choosing “File”, “New”, then
“Folder” and entering “menu” as the name.
Aim :
Procedure :
package com.example.optionsmenu;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
Output :
Result :
Thus the given program To Develop an android application to implement Menus output is verified
and executed successfully .
Ex No: 4 Develop an android application to implement Fragments. Date:
Android Fragment is the part of activity, it is also known as sub-activity. There can be more
than one fragment in an activity. Fragments represent multiple screen inside one activity.
Android fragment lifecycle is affected by activity lifecycle because fragments are included in
activity.
Each fragment has its own life cycle methods that is affected by activity life cycle because
fragments are embedded in activity.
The FragmentManager class is responsible to make interaction between fragment objects.
activity_main.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20sp"
android:gravity="center"
android:text="21IT048 "
android:textSize="20sp"
android:fontFamily="sans-serif-medium"
android:textStyle="bold" />
<!-- display two Button's and a FrameLayout to replace the Fragment's -->
<Button
android:id="@+id/firstFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/button_background_color"
android:text="First Fragment"
android:textColor="@color/white"
android:textSize="20sp" />
<Button
android:id="@+id/secondFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@color/button_background_color"
android:text="Second Fragment"
android:textColor="@color/white"
android:textSize="20sp" />
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp" />
</LinearLayout>
MainActivity class :
package com.android.fragmentexample;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// get the reference of Button's
firstFragment = (Button) findViewById(R.id.firstFragment);
secondFragment = (Button) findViewById(R.id.secondFragment);
Result :
Thus the given program To Develop an android application to demonstrate simple event handling
output is verified and executed successfully .
Ex No: 5 Develop an android application customized Sending Email, Sending SMS and Phone
Calls using Intent and intent filter.
Date:
An Intent is a messaging object you can use to request an action from another app component.
Although intents facilitate communication between components in several ways, there are three
fundamental use cases:
• Starting an activity
An Activity represents a single screen in an app. You can start a new instance of an Activity by
passing an Intent to startActivity(). The Intent describes the activity to start and carries any
necessary data.
If you want to receive a result from the activity when it finishes, call startActivityForResult().
Your activity receives the result as a separate Intent object in your
activity's onActivityResult() callback. For more information, see the Activities guide.
• Starting a service
A Service is a component that performs operations in the background without a user interface.
With Android 5.0 (API level 21) and later, you can start a service with JobScheduler. For more
information about JobScheduler, see its API-reference documentation.
For versions earlier than Android 5.0 (API level 21), you can start a service by using methods of
the Service class. You can start a service to perform a one-time operation (such as downloading a
file) by passing an Intent to startService(). The Intent describes the service to start and carries
any necessary data.
If the service is designed with a client-server interface, you can bind to the service from another
component by passing an Intent to bindService(). For more information, see the Services guide.
• Delivering a broadcast
A broadcast is a message that any app can receive. The system delivers various broadcasts for
system events, such as when the system boots up or the device starts charging. You can deliver a
broadcast to other apps by passing an Intent to sendBroadcast() or sendOrderedBroadcast().
The rest of this page explains how intents work and how to use them. For related information,
see Interacting with Other Apps and Sharing Content.
Intent types
There are two types of intents:
• Explicit intents specify which application will satisfy the intent, by supplying either the target
app's package name or a fully-qualified component class name. You'll typically use an explicit
intent to start a component in your own app, because you know the class name of the activity or
service you want to start. For example, you might start a new activity within your app in
response to a user action, or start a service to download a file in the background.
• Implicit intents do not name a specific component, but instead declare a general action to
perform, which allows a component from another app to handle it. For example, if you want to
show the user a location on a map, you can use an implicit intent to request that another capable
app show a specified location on a map.
Figure 1 shows how an intent is used when starting an activity. When the Intent object names a
specific activity component explicitly, the system immediately starts that component.
Aim:
To Develop an android application customized Sending Email, Sending SMS and Phone
Calls using Intent and intent filter.
Procedure:
1 .Start the program .
2. Importing necessary packages .
3. Then develop and design XML file and JAVA file .
4. Run the program in android studio and display the output .
5. Stop .
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:orientation="vertical" >
<EditText
android:id="@+id/txtTo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="To"/>
<EditText
android:id="@+id/txtSub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Subject"/>
<EditText
android:id="@+id/txtMsg"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="Message"/>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20sp"
android:gravity="center"
android:text="21IT048 "
android:textSize="20sp"
android:fontFamily="sans-serif-medium"
android:textStyle="bold" />
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Send"
android:id="@+id/btnSend"/>
</LinearLayout>
package com.sendmailexample;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
eTo = (EditText)findViewById(R.id.txtTo);
eSubject = (EditText)findViewById(R.id.txtSub);
eMsg = (EditText)findViewById(R.id.txtMsg);
btn = (Button)findViewById(R.id.btnSend);
btn.setOnClickListener(new View.OnClickListener() {
@Override
it.putExtra(Intent.EXTRA_SUBJECT,eSubject.getText().toString());
it.putExtra(Intent.EXTRA_TEXT,eMsg.getText());
it.setType("message/rfc822");
});
}
Output :
Result :
Thus the given program To Develop an android application customized Sending
Email,Sending SMS and Phone Calls using Intent and intent filter output is verified and executed
successfully .
Ex No: 6 Develop an android application to implement a Location Based Services. Date:
Android location APIs make it easy for you to build location-aware applications, without
needing to focus on the details of the underlying location technology.
This becomes possible with the help of Google Play services, which facilitates adding location
awareness to your app with automated location tracking, geofencing, and activity recognition.
This tutorial shows you how to use Location Services in your APP to get the current location, get
periodic location updates, look up addresses etc.
The Location Object
The Location object represents a geographic location which can consist of a latitude, longitude,
time stamp, and other information such as bearing, altitude and velocity. There are following
important methods which you can use with Location object to get location specific information −
Sr.No. Method & Description
2 float getAccuracy()
Get the estimated accuracy of this location, in meters.
3 double getAltitude()
Get the altitude if available, in meters above sea level.
4 float getBearing()
Get the bearing, in degrees.
5 double getLatitude()
Get the latitude, in degrees.
6 double getLongitude()
Get the longitude, in degrees.
7 float getSpeed()
Get the speed if it is available, in meters/second over ground.
8 boolean hasAccuracy()
True if this location has an accuracy.
9 boolean hasAltitude()
True if this location has an altitude.
10 boolean hasBearing()
True if this location has a bearing.
11 boolean hasSpeed()
True if this location has a speed.
12 void reset()
Clears the contents of the location.
19 String toString()
Returns a string containing a concise, human-readable description of this object.
1 setExpirationDuration(long millis)
Set the duration of this request, in milliseconds.
2 setExpirationTime(long millis)
Set the request expiration time, in millisecond since boot.
3 setFastestInterval(long millis)
Explicitly set the fastest interval for location updates, in milliseconds.
4 setInterval(long millis)
Set the desired interval for active location updates, in milliseconds.
5 setNumUpdates(int numUpdates)
Set the number of location updates.
6 setPriority(int priority)
Set the priority of the request.
Now for example, if your application wants high accuracy location it should create a location
request with setPriority(int) set to PRIORITY_HIGH_ACCURACY and setInterval(long) to 5
seconds. You can also use bigger interval and/or other priorities like PRIORITY_LOW_POWER
for to request "city" level accuracy or PRIORITY_BALANCED_POWER_ACCURACY for
"block" level accuracy.
Activities should strongly consider removing all location request when entering the background
(for example at onPause()), or at least swap the request to a larger interval and lower quality to
save power consumption.
Displaying a Location Address
Once you have Location object, you can use Geocoder.getFromLocation() method to get an
address for a given latitude and longitude. This method is synchronous, and may take a long time
to do its work, so you should call the method from the doInBackground() method of
an AsyncTask class.
The AsyncTask must be subclassed to be used and the subclass will
override doInBackground(Params...) method to perform a task in the background
and onPostExecute(Result) method is invoked on the UI thread after the background
computation finishes and at the time to display the result. There is one more important method
available in AyncTask which is execute(Params... params), this method executes the task with
the specified parameters.
Example
Following example shows you in practical how to to use Location Services in your app to get the
current location and its equivalent addresses etc.
AIM :
PROCEDURE :
<Button
android:id = "@+id/button"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:text = "getlocation"/>
</LinearLayout>
Code forMainActivity.java:
package com.example.myapplication;
import android.Manifest;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.test.mock.MockPackageManager;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
Button btnShowLocation;
private static final int REQUEST_CODE_PERMISSION = 2;
String mPermission = Manifest.permission.ACCESS_FINE_LOCATION;
// GPSTracker class
GPSTracker gps;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
if (ActivityCompat.checkSelfPermission(this, mPermission)
!= MockPackageManager.PERMISSION_GRANTED) {
@Override
public void onClick(View arg0) {
// create class object
gps = new GPSTracker(MainActivity.this);
}
});
}
}
Output :
Result :
Thus the given program To Develop an android application to implement a Location Based Services
output is verified and executed successfully .
Ex No : 7 Develop an application to capture image using built in camera Date:
These are the following two ways, in which you can use camera in your application
• Using existing android camera application in our application
• Directly using Camera API provided by android in our application
•
Using existing android camera application in our application
You will use MediaStore.ACTION_IMAGE_CAPTURE to launch an existing camera
application installed on your phone. Its syntax is given below
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
Apart from the above, there are other available Intents provided by MediaStore. They are listed
as follows
Sr.No Intent type and description
ACTION_IMAGE_CAPTURE_SECURE
1
It returns the image captured from the camera , when the device is secured
ACTION_VIDEO_CAPTURE
2
It calls the existing video application in android to capture video
EXTRA_SCREEN_ORIENTATION
3
It is used to set the orientation of the screen to vertical or landscape
EXTRA_FULL_SCREEN
4
It is used to control the user interface of the ViewImage
INTENT_ACTION_VIDEO_CAMERA
5
This intent is used to launch the camera in the video mode
EXTRA_SIZE_LIMIT
6
It is used to specify the size limit of video or image capture size
Now you will use the function startActivityForResult() to launch this activity and wait for its
result. Its syntax is given below
startActivityForResult(intent,0)
This method has been defined in the activity class. We are calling it from main activity. There
are methods defined in the activity class that does the same job , but used when you are not
calling from the activity but from somewhere else. They are listed below
Sr.No Activity function description
Aim:
To Develop an application to capture image using built in camera .
Procedure:
1 .Start the program .
2. Importing necessary packages .
3. Then develop and design XML file and JAVA file .
4. Run the program in android studio and display the output .
5. Stop .
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20sp"
android:gravity="center"
android:text="21IT048 "
android:textSize="20sp"
android:fontFamily="sans-serif-medium"
android:textStyle="bold" />
<Button
android:id="@+id/camera_button"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginStart="150dp"
android:text="Camera" />
<ImageView
android:id="@+id/click_image"
android:layout_width="350dp"
android:layout_height="450dp"
android:layout_marginStart="30dp"
android:layout_marginTop="70dp"
android:layout_marginBottom="10dp" />
</RelativeLayout>
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.widget.Button;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// By ID we can get each component which id is assigned in XML file get Buttons and
imageview.
camera_open_id = findViewById(R.id.camera_button);
click_image_id = findViewById(R.id.click_image);
// Camera_open button is for open the camera and add the setOnClickListener in this button
camera_open_id.setOnClickListener(v -> {
// Create the camera_intent ACTION_IMAGE_CAPTURE it will open the camera for
capture the image
Intent camera_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Start the activity with camera_intent, and request pic id
startActivityForResult(camera_intent, pic_id);
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == pic_id) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
click_image_id.setImageBitmap(photo);
}
}
}
Output :
Result :
Thus the given program To Develop an application to capture image using built in camera
output is verified and executed successfully .
Ex No : 8 Develop a simple Video player like application using video view and
videoRecorder. Date:
By the help of MediaController and VideoView classes, we can play the video files in android.
MediaController class
The android.widget.MediaController is a view that contains media controls like play/pause,
previous, next, fast-forward, rewind etc.
VideoView class
The android.widget.VideoView class provides methods to play and control the video player.
The commonly used methods of VideoView class are as follows:
Method Description
public void setVideoURI (Uri uri) sets the URI of the video
file.
Aim:
To Develop a simple Video player like application using video view and videoRecorder.
Procedure:
5. Stop .
Code for activity_main.xml :
<RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20sp"
android:gravity="center"
android:text="21IT048 "
android:textSize="20sp"
android:fontFamily="sans-serif-medium"
android:textStyle="bold" />
<VideoView
android:id="@+id/videoView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
</RelativeLayout>
Code for MainActivity.java:
package com.example.videoplayerexample;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.MediaController;
import android.widget.VideoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Creating MediaController
MediaController mediaController= new MediaController(this);
mediaController.setAnchorView(videoView);
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
Output :
Result :
Thus the given program Develop a simple Video player like application using video view
and videoRecorder output is verified and executed successfully .
Ex No: 9 Develop an application that creates an alert upon receiving a message and
call.
Date:
▪ Then select the Minimum SDK as shown below and click Next.
▪ Then select the Empty Activity and click Next.
Aim:
To Develop an application that creates an alert upon receiving a message and call.
Procedure:
5. Stop .
Code for activity_main.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20sp"
android:gravity="center"
android:text="21IT048 "
android:textSize="20sp"
android:fontFamily="sans-serif-medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message"
android:textSize="30sp" />
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="30sp" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:layout_gravity="center"
android:text="Notify"
android:textSize="30sp"/>
</LinearLayout>
package com.example.exno10;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity
Button notify;
EditText e;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e= (EditText) findViewById(R.id.editText);
notify.setOnClickListener(new View.OnClickListener()
@Override
noti.flags |= Notification.FLAG_AUTO_CANCEL;
manager.notify(0, noti);
});
}}
Output :
Result :
Thus the given program To Develop an application that creates an alert
upon receiving a message and call output is verified and executed successfully .
Ex No: 10 Develop an android application to demonstrate Firebase Database. Date:
Step 2:
Firebase either from Firebase Assistant or manually using console. After that, we will add all the
required libraries and plugin to our app.gradle file. And we will also add mavenLocal() as our
repository and all projects.
Step 3:
In the next step, we will go to the Firebase console and look at the Real-time database. In
Developers-> Database, there will be two options, i.e., cloud Firestore and Real-time database.
Step 4:
In the next step, we will create a database by clicking on the Create database. After clicking on
Create database, a popup box is open where we actually create a database with specific rules. We
will talk about these rules later in this section. But for now, we will select start in test mode
where anybody can access our data, and later we change these rules. And last we select on
Enable.
Step 5:
After clicking on Enable, the real-time database will be enabled with a database by default. Here,
we have Data, Rules, Backups, and, Usage for data storing, security rules, backups, and usage,
respectively.
Before understanding the next steps, we will talk about the Firebase Database Rules.
The Real-time database provides a declarative rules language. It defines how our data should be
structured, how it should be indexed, and when our data can be read from and written to. By
default, read and write access to our database is restricted, so only authenticated users can read or
write data.
To get started without setting up Authentication, we can configure our rules for public access.
These rules make our database open to anyone, even people not using our app, read and write
access to our database.
{
"rules": {
".read": true,
".write": true
}
}
If we want to allow authenticated users for accessing read and write to our database, then we will
use the following rules:
{
"rules": {
".read": "auth!=null",
".write": "auth!=null"
}
}
This will make sure that user only who have been authenticated using firebase can read and write
to our database.
Step 6:
In the next step, we will go to the console and go to database rules and modify these rules to
authenticated users.
After performing the required changes in the rules, we will publish them.
Now, our database is set with specific rules, and we can use it now. In the next section, we will
learn how we perform read and write operations in a Real-time database.
Aim:
Procedure:
1 .Start the program .
2. Importing necessary packages .
3. Then develop and design XML file and JAVA file .
4. Run the program in android studio and display the output .
5. Stop .
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20sp"
android:gravity="center"
android:text="21IT048 "
android:textSize="20sp"
android:fontFamily="sans-serif-medium"
android:textStyle="bold" />
android:layout_margin="10dp"
android:hint="Enter employee address"
android:inputType="textPostalAddress" />
</RelativeLayout>
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;
// Firebase Database.
FirebaseDatabase firebaseDatabase;
DatabaseReference databaseReference;
EmployeeInfo employeeInfo;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
employeeNameEdt = findViewById(R.id.idEdtEmployeeName);
employeePhoneEdt = findViewById(R.id.idEdtEmployeePhoneNumber);
employeeAddressEdt = findViewById(R.id.idEdtEmployeeAddress);
firebaseDatabase = FirebaseDatabase.getInstance();
databaseReference = firebaseDatabase.getReference("EmployeeInfo");
// class variable.
sendDatabtn = findViewById(R.id.idBtnSendData);
sendDatabtn.setOnClickListener(new View.OnClickListener() {
@Override
} else {
});
employeeInfo.setEmployeeName(name);
employeeInfo.setEmployeeContactNumber(phone);
employeeInfo.setEmployeeAddress(address);
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
@Override
});
}
Output :
Result :
Thus the given program To Develop an android application to demonstrate Firebase Database
output is verified and executed successfully .