Mobile App Development Question Bank
Mobile App Development Question Bank
Mobile App Development Question Bank
Q1 2 MARKS QUESTIONS.
.
2. List all tools and softwares required for developing an android application.
Tools :
1. Android Studio
2. Eclipse IDE
Software Required :
1. Java JDK5 or Latest version.
2. Android Studio.
8. Define emulator
Android emulator simulates android devices on your computer so that you can test your
applications on a variety of devices and android api levels without needing to have each
physical device. The emulator provides almost all the capabilities of a real android device.
9. List any four attributes of layout.
1. android:id
2. android:layout_x
3. android:layout_y
4. android:gravity
5. android:divider
6. android:orientation
13. Define :
i) Fragment
ii) Broadcast receiver
Fragments are the modular section of an activity design. Fragments are used to represent
the behaviour of user interface in an activity. We can build multiple fragments in an single
activity. And also use same fragments in the multiple activity. Fragments has its own life
cycle.
The Open Handset Alliance (OHA) is an association whose goal is to develop open
standards for mobile devices, promote innovation in mobile phones and provide a better
experience for consumers at a lower cost.
OR
Components of UI
Menu Bar
Toolbar
Navigation Bar
Editor Tabs
Editor
Project Explorer
Status Bar
Tool Buttons
23. List any four folders from directory structure of Android project and elaborate in one line.
26. Name two classes used to play audio and video in Android.
1.android.media.MediaPlayer class
2.android.widget.MediaController
Q2 4 MARKS QUESTION Q2
Importance of OHA is to develop open mobile device standards with the help of more than
80 companies including google , dell , Intel ,etc.
Audio and video playback features include integration with OpenMAX codecs, session
management, time- synchronized rendering, transport control, and DRM.
Stagefright also supports integration with custom hardware codecs provided by you. To set
a hardware path to encode and decode media, you must implement a hardware-based
codec as an OpenMax IL (Integration Layer) component.
7. Explain the need of Android Operating System. Also describe any four features of android.
Need of android operating system is :
1. Android market : Android market is the techno based and fastest growing market in the
world. You can effortlessly get almost any software you wish for in the android market.
2. Customization : Android offers the best in terms of end user experience mainly because
of the extent that one can customize his phone. Android is open source software.This
means anybody with programming skills can create applications for android device.
3. Rooting : Expansion of the scope of functionality of your phone and boosts its
performance multiple times over. By rooting devices makes it possible for you to change
system files in your devices and customize your device.
4. The android community : This is one of the major reason which define need of android is
the best decision you will ever make. The larger android comunnity provides you with the
necessary help and support for your device.
Features :
1) Beautiful UI : Android os basic screen provides a beautiful and intutive user interface.
2) Connectivity : WIFI , LTE , Bluetooth , CMDA , IDEN
3) Storage : SQLite a light weight relational database is used for data storage purpose.
4) Custom Roms : As android is open source developers can tweak the current os and
build their own versions.
5) Multi Language : Supports single direction and bi directional text.
8. Develop a program to add “Hello World” marker at (10,10) co-ordinates. Write only . java
file
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@Override
public void onMapReady(GoogleMap googleMap) {
LatLng location = new LatLng(10, 10);
googleMap.addMarker(new MarkerOptions().position(location).title("Hello World"));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(location));
}
}
1. The purpose of a permission is to protect the privacy of an Android user. Android apps
must request permission to access sensitive user data (such as contacts and SMS), as well
as certain system features (such as camera and internet).
2. Depending on the feature, the system might grant the permission automatically or might
prompt the user to approve the request.
11. Elaborate the need of permissions in Android. Explain the permissions to set system
functionalitics like SEND-SMS, bluetooth.
The purpose of a permission is to protect the privacy of an Android user. Android apps
must request permission to access sensitive user data (such as contacts and SMS), as well
as certain system features (such as camera and internet). Depending on the feature, the
system might grant the permission automatically or might prompt the user to approve the
request.
Step 1: Make a Developer Account : Before you can publish any app on Google Play, you
need to create a Developer Account. You can easily sign up for one using your existing
Google Account. You’ll need to pay a one-time registration fee of $25 using your
international credit or debit card.
Step 2: Plan to Sell? Link Your Merchant Account : If you want to publish a paid app or plan
to sell in-app purchases, you need to create a payments center profile, i.e. a merchant
account. A merchant account will let you manage your app sales and monthly payouts, as
well as analyze your sales reports right in your Play Console
Step 3: Create an App : Now you have create an application by clicking on 'Create
Application'.
Step 4: Prepare Store Listing : Before you can publish your app, you need to prepare its
store listing. These are all the details that will show up to customers on your app’s listing
on Google Play.
Step 5: Upload APK to an App Release : Finally upload your app, by uploading APK file.
Before you upload APK, you need to create an app release. You need to select the type of
release you want to upload your first app version to. You can choose between an internal
test, a closed test, an open test, and a production release. The first three releases allow
you to test out your app among a select group of users before you make it go live for
everyone to access.
Step 6: Provide an Appropriate Content Rating : If you don’t assign a rating to your app, it
will be listed as ‘Unrated’. Apps that are ‘Unrated’ may get removed from Google Play.
Step 7: Set Up Pricing & Distribution : Before you can fill out the details required in this
step, you need to determine your app’s monetization strategy. Once you know how your
app is going to make money, you can go ahead and set up your app as free or paid.
Step 8: Rollout Release to Publish Your App : The final step involves reviewing and rolling
out your release after making sure you’ve taken care of everything else. Before you review
and rollout your release, make sure the store listing, content rating, and pricing and
distribution sections of your app each have a green check mark next to them.
15. Describe with example, how to create a simple database in SQLite (Assume suitable data).
This procedure is by openOrCreateDatabase()
1. The package imported into the application is android.database.sqlite.SQLiteDatabase.
2. Here the class used is SQLiteDatabase.
3. The method used to create the database or connect to the database is
openOrCreateDatabse() method.
Program:
activity_main.xml
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:text="Create SQLite Database"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp"
android:id="@+id/button" />
</RelativeLayout>
MainActivity.java
package in.edu.vpt.insertusingasync;
import android.app.ProgressDialog;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;;
public class MainActivity extends AppCompatActivity {
SQLiteDatabase sqLiteDatabaseObj;
Button EnterData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
createData = (Button)findViewById(R.id.button);
createData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sqLiteDatabaseObj = openOrCreateDatabase("AndroidJSonDataBase",
Context.MODE_PRIVATE, null);
} });
}
16. State syntax to create Text View and Image button with any two attributes of each.
Text View:
Syntax :
<TextView
android:id="@+id/textView1"
android:layout_width="<width value>”
android:layout_height="<height_value>"
android:text="<text to be displayed>"/>
Attributes/Properties of TextView:
1. text: text attribute is used to set the text in a text view. We can set the text in xml as
well as in the java class.
2. textColor: textColor attribute is used to set the text color of a text view.
3. textSize: textSize attribute is used to set the size of text of a text view.
4. background: background attribute is used to set the background of a text view.
5. id: Supply an identifier name of this view, to later retrieve it with View.findViewByID()
or Activity.findViewById()
6. auto link: Controls whether links such as urls and email addresses are automatically
found and converted to clickable links.[flag]
ImageButton:
Syntax :
<ImageButton
android:id="@+id/imageButton"
android:layout_width="<width value>"
android:layout_height="<height value>"
app:srcCompat="<image source from drawable folder "/>
Attributes/Properties of ImageButton:
1. id: id is an attribute used to uniquely identify a image button.
2. src: src is an attribute used to set a source file of image
3. background: background attribute is used to set the background of an image button.
4. padding: padding attribute is used to set the padding from left, right, top or bottom of
the
ImageButton.
18. State and elaborate the syntax of required class and methods for Geocoding.
Geocoder: A class for handling geocoding and reverse geocoding.
Finding the geographical cooridinates of a given address or location is called geocoding
And where a pair of longitude and latitude is converted into an address or location is called
as reverse geocoding.
The Geocoder class requires a backend service that is not included in the core android
framework
Syntax :
Geocoder (Context context)
Constructs a Geocoder localized for the default locale.
Geocoder(Context context, Locale locale)
Constructs a Geocoder localized for the given locale.
1. getFromLocation :
Syntax
public List<Address> getFromLocation (double latitude, double longitude, int
maxResults)
This method returns an array of Addresses that attempt to describe the area
immediately surrounding the given latitude and longitude.
2. getFromLocationName :
Syntax :
public void getFromLocationName (String locationName, int maxResults,
Geocoder.GeocodeListener listener)
Returns an array of Addresses that attempt to describe the named location, which may
be a place name such as "Dalvik, Iceland", an address such as "1600 Amphitheatre
Parkway, Mountain View, CA", an airport code such as "SFO", The returned addresses
should be localized for the locale provided to this class's constructor.
3. isPresent
Syntax :
Returns true if there is a geocoder implementation present that may return results. If
true,
there is still no guarantee that any individual geocoding attempt will succeed.
3. getYear(): This method is used to get the selected year from a date picker. This method
returns an integer value.
DatePicker simpleDatePicker = (DatePicker)findViewById(R.id.simpleDatePicker); int year =
simpleDatePicker.getYear();
4. getFirstDayOfWeek(): This method is used to get the first day of the week. This method
returns an integer value.
DatePicker simpleDatePicker = (DatePicker)findViewBy
TimePicker: In Android, TimePicker is a widget used for selecting the time of the day in
either AM/PM mode or 24 hours mode. The displayed time consist of hours, minutes and
clock format. If we need to show this view as a Dialog then we have to use a
TimePickerDialog class.
setHour(Integer hour): setCurrentHour() method was deprecated in API level 23. From api
level 23 we have to use setHour(Integer hour). In this method there is only one parameter
of
integer type which is used to set the value for hours.
TimePicker simpleTimePicker=(TimePicker)findViewById(R.id.simpleTimePicker);
simpleTimePicker.setCurrentHour(5);
simpleTimePicker.setHour(5);
getCurrentMinute(): This method is used to get the current minutes from a time picker.
getMinute(): getCurrentMinute() method was deprecated in API level 23. From api level 23
we have to use getMinute(). This method returns an integer value.
TimePicker simpleTimePicker = (TimePicker)findViewById(R.id.simpleTimePicker);
int minutes = simpleTimePicker.getCurrentMinute();
int minutes = simpleTimePicker.getMinute();
is24HourView(): This method is used to check the current mode of the time picker. This
method returns true if its 24 hour mode or false if AM/PM mode is set.
TimePicker simpleTimePicker = (TimePicker)findViewById(R.id.simpleTimePicker);
Boolean mode=simpleTimePicker.is24HourView();
21. Write an xml file to create login page using Table Layout
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<TableRow>
<EditText
android:id="@+id/usernameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username" />
</TableRow>
<TableRow>
<EditText
android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword" />
</TableRow>
<TableRow>
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login" />
</TableRow>
</TableLayout>
22. Develop an application to display analog Time Picker. Also display the selected time. (Write
only . java file)
import android.app.Activity;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
import java.util.Calendar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
timeTextView = findViewById(R.id.timeTextView);
Button pickTimeButton = findViewById(R.id.pickTimeButton);
pickTimeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Get current time
final Calendar currentTime = Calendar.getInstance();
int hour = currentTime.get(Calendar.HOUR_OF_DAY);
int minute = currentTime.get(Calendar.MINUTE);
// Create a TimePickerDialog
TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity.this,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int selectedHour, int
selectedMinute) {
// Display selected time
timeTextView.setText("Selected Time: " + selectedHour + ":" +
selectedMinute);
}
}, hour, minute, true);
Attributes :
<GridView
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3"
android:columnWidth="100dp"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth" />
@Override
if (status == TextToSpeech.SUCCESS) {
}
}
.....
}
<Button
android:id="@+id/btnPickDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pick Date" />
<Button
android:id="@+id/btnPickTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pick Time" />
<TextView
android:id="@+id/tvDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Selected Date: " />
<TextView
android:id="@+id/tvTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Selected Time: " />
</LinearLayout>
JAVA :
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Calendar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvDate = findViewById(R.id.tvDate);
tvTime = findViewById(R.id.tvTime);
btnPickDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pickDate();
}
});
btnPickTime.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pickTime();
}
});
}
Components :
1. /src : This is the most common folder in any android project. It contains our java source
code for android application.
2. /gen : This folder is created by IDE for configuration purpose. Under this folder we can
find 2 java files both files are auto generated.
3. /libs : This folder contains private libraries.
4. /res : This folder contains lots of required sub folder for the project.
5. /menu : For xml files that defines application menus.
6. /drawable : Under this folder we can store images for our project
7. /bin : this is the most imp folder in our directory structure as it contains
androidManifest.xml file.
28. Explain property animation method to animate the properties of view object with example.
Special Permissions: Special permissions, like drawing over other apps or installing
unknown apps, require additional user action through system settings. They are typically
used for specific system-level operations and are not granted automatically.
Best Practices: Developers should request permissions judiciously, explaining clearly why
each permission is necessary. They should also handle permission requests gracefully,
respecting user decisions and providing alternative functionality if permissions are denied.
<TextView
android:id="@+id/tvLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Current Location"
android:textSize="18sp"
android:layout_centerInParent="true"/>
</RelativeLayout>
JAVA :
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvLocation = findViewById(R.id.tvLocation);
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
requestLocationPermission();
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[]
permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == LOCATION_PERMISSION_REQUEST_CODE) {
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
fetchLastLocation();
} else {
tvLocation.setText("Location permission denied");
}
}
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/radioButtonOption1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 1" />
<RadioButton
android:id="@+id/radioButtonOption2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 2" />
<RadioButton
android:id="@+id/radioButtonOption3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 3" />
</RadioGroup>
<Button
android:id="@+id/buttonShowSelection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Selection" />
<TextView
android:id="@+id/textViewSelection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp"
android:layout_marginTop="16dp"/>
</LinearLayout>
Java :
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonShowSelection.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int selectedRadioButtonId = radioGroup.getCheckedRadioButtonId();
if (selectedRadioButtonId != -1) {
RadioButton selectedRadioButton = findViewById(selectedRadioButtonId);
textViewSelection.setText("Selected Option: " + selectedRadioButton.getText());
} else {
textViewSelection.setText("Please select an option");
}
}
});
}
}
32. Develop an application to send and receive SMS. (Write only . java and permission tag in
manifest file)
Mainfest :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.smsdemo">
<application
... <!-- other app configurations -->
>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
Java File :
import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextPhoneNumber = findViewById(R.id.editTextPhoneNumber);
editTextMessage = findViewById(R.id.editTextMessage);
buttonSend = findViewById(R.id.buttonSend);
buttonSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String phoneNumber = editTextPhoneNumber.getText().toString();
String message = editTextMessage.getText().toString();
sendSMS(phoneNumber, message);
}
});
}
@Override
protected void onResume() {
super.onResume();
IntentFilter filter = new IntentFilter();
filter.addAction("android.provider.Telephony.SMS_RECEIVED");
registerReceiver(smsReceiver, filter);
}
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(smsReceiver);
}
View Groups:
The ViewGroup is a subclass of View and provides invisible container that hold other Views
or other ViewGroups and define their layout properties.
A ViewGroup provides the layout in which we can order the appearance and sequence of
views.
Examples of ViewGroup are FrmaeLayout, LineourLayout etc.
Fragments:
Fragments represents a portion of user interface in an Activity.
Each Fragment includes its own user interface (UI) layout and receives the related input
events but is tightly bound to the activity into which each must be embedded. Fragments
are similar to UI view controller in iPhone development.
Activities:
Activities dictate the UI and handle the user interaction to the smart phone screen.
Activities represent a single screen that user interact.
Activities are the Android equivalent of Forms in traditional windows desktop
development.
34. Write a program to display a rectangular progress bar.
XML LAYOUT :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context=".MainActivity">
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_centerVertical="true"
android:indeterminate="false"
android:max="100"
android:progress="50"
android:progressDrawable="@drawable/rectangular_progress_bar" />
</RelativeLayout>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
</layer-list>
Colors :
<resources>
<color name="light_gray">#CCCCCC</color>
<color name="teal">#009688</color>
</resources>
Reverse-geocoding:
where a pair of longitude and latitude is converted into an address or location is called as
reverse geocoding.
The following code shows how we can find the exact location of the Empire State Building
by using the getFromLocationName() method:
Geocoder geoCoder = new Geocoder(this, Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocationName(
"empire state building", 5);
String add = "";
if (addresses.size() > 0) {
p = new GeoPoint(
(int) (addresses.get(0).getLatitude() * 1E6),
(int) (addresses.get(0).getLongitude() * 1E6));
mc.animateTo(p);
mapView.invalidate();
}
} catch (IOException e) {
e.printStackTrace();
}
36. Explain with example, code to create GUI using absolute layout (Assume suitable data)
AbsoluteLayout is based on the simple idea of placing each control at an absolute position.
We specify the exact x and y coordinates on the screen for each control. This is not
recommended for most UI development since absolutely positioning every element on the
screen makes an inflexible UI that is much more difficult to maintain.
An Absolute Layout lets you specify exact locations (x/y coordinates) of its children.
Absolute layouts are less flexible and harder to maintain than other types of layouts
without absolute positioning. AbsoluteLayout is based on the simple idea of placing each
control at an absolute position.
We specify for the exact x and y corodinates on the screen for every control.
<Button
android:id="@+id/button1"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="Button 1"
android:layout_x="50dp"
android:layout_y="100dp" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView 1"
android:layout_x="200dp"
android:layout_y="200dp" />
<EditText
android:id="@+id/editText1"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:hint="Enter text"
android:layout_x="100dp"
android:layout_y="300dp" />
</AbsoluteLayout>
40. Write a program to demonstrate declaring and using permissions with any relevant
example.
Q3 6 MARKS QUESTIONS :
<EditText
android:id="@+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:inputType="text" />
<EditText
android:id="@+id/editTextEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editTextName"
android:layout_marginTop="16dp"
android:hint="Email"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/editTextPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editTextEmail"
android:layout_marginTop="16dp"
android:hint="Phone"
android:inputType="phone" />
<Button
android:id="@+id/buttonRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editTextPhone"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:text="Register" />
</RelativeLayout>
JAVA FILE :
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextName = findViewById(R.id.editTextName);
editTextEmail = findViewById(R.id.editTextEmail);
editTextPhone = findViewById(R.id.editTextPhone);
buttonRegister = findViewById(R.id.buttonRegister);
buttonRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
registerEmployee();
}
});
}
2. Develop an android application for taking student feedback with database connectivity
XML Layout for Feedback Form :
<TextView
android:id="@+id/textViewFeedback"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Your Feedback:"
android:textSize="18sp"
android:layout_marginTop="16dp"/>
<EditText
android:id="@+id/editTextFeedback"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textViewFeedback"
android:layout_marginTop="8dp"
android:inputType="textMultiLine"
android:minLines="5"
android:hint="Write your feedback here..." />
<Button
android:id="@+id/buttonSubmitFeedback"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit Feedback"
android:layout_below="@id/editTextFeedback"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"/>
</RelativeLayout>
<TextView
android:id="@+id/textViewFeedbackTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Feedback List"
android:textSize="20sp"
android:layout_marginBottom="16dp"/>
<ListView
android:id="@+id/listViewFeedback"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<Button
android:id="@+id/buttonRefresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Refresh"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE_FEEDBACK);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_FEEDBACK);
onCreate(db);
}
}
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_feedback);
dbHelper = new DBHelper(this);
editTextFeedback = findViewById(R.id.editTextFeedback);
buttonSubmitFeedback = findViewById(R.id.buttonSubmitFeedback);
buttonSubmitFeedback.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saveFeedback();
}
});
}
if (feedbackText.isEmpty()) {
Toast.makeText(this, "Please enter your feedback", Toast.LENGTH_SHORT).show();
return;
}
SQLiteDatabase db = dbHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(DBHelper.COLUMN_FEEDBACK_TEXT, feedbackText);
if (newRowId != -1) {
Toast.makeText(this, "Feedback submitted successfully",
Toast.LENGTH_SHORT).show();
editTextFeedback.setText("");
} else {
Toast.makeText(this, "Failed to submit feedback", Toast.LENGTH_SHORT).show();
}
db.close();
}
}
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_feedback);
listViewFeedback = findViewById(R.id.listViewFeedback);
buttonRefresh = findViewById(R.id.buttonRefresh);
buttonRefresh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
refreshFeedbackList();
}
});
refreshFeedbackList();
}
listViewFeedback.setAdapter(adapter);
}
}
<ListView
android:id="@+id/listViewPairedDevices"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="16dp"
android:visibility="gone" />
</LinearLayout>
JAVA :
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
import java.util.Set;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null) {
Toast.makeText(this, "Bluetooth not supported", Toast.LENGTH_SHORT).show();
finish();
}
<EditText
android:id="@+id/editTextPhoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Phone Number"
android:inputType="phone" />
<EditText
android:id="@+id/editTextMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:hint="Message"
android:inputType="textMultiLine"
android:minLines="5" />
<Button
android:id="@+id/buttonSendSMS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send SMS"
android:layout_marginTop="16dp" />
</LinearLayout>
JAVA :
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextPhoneNumber = findViewById(R.id.editTextPhoneNumber);
editTextMessage = findViewById(R.id.editTextMessage);
buttonSendSMS = findViewById(R.id.buttonSendSMS);
buttonSendSMS.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sendSMS();
}
});
}
if (phoneNumber.isEmpty() || message.isEmpty()) {
Toast.makeText(this, "Please enter phone number and message",
Toast.LENGTH_SHORT).show();
return;
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[]
grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == PERMISSION_SEND_SMS) {
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
// Permission granted, send SMS
sendSMS();
} else {
// Permission denied
Toast.makeText(this, "Permission denied to send SMS",
Toast.LENGTH_SHORT).show();
}
}
}
}
6. Explain how linear and frame layout is used to design an android application with suitable
example
Linear and Frame layouts are two fundamental layout types in Android used to arrange UI
components.
Linear Layout:
Linear layout arranges its children elements in a single direction, either horizontally or
vertically. Each child is placed next to or below the previous one in the layout. It's
particularly useful for creating simple user interfaces with a linear arrangement.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name:" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your name" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />
</LinearLayout>
Frame Layout:
Frame layout is designed to block out an area on the screen to display a single item. It's
typically used for fragments or displaying a single view at a time.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/image" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Overlay text"
android:textSize="24sp"
android:layout_gravity="center" />
</FrameLayout>
<EditText
android:id="@+id/editTextNumber1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter number 1"
android:inputType="numberDecimal" />
<EditText
android:id="@+id/editTextNumber2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editTextNumber1"
android:layout_marginTop="16dp"
android:hint="Enter number 2"
android:inputType="numberDecimal" />
<Button
android:id="@+id/buttonAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editTextNumber2"
android:layout_marginTop="16dp"
android:text="Add" />
<Button
android:id="@+id/buttonSubtract"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonAdd"
android:layout_marginTop="8dp"
android:text="Subtract" />
<Button
android:id="@+id/buttonMultiply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonSubtract"
android:layout_marginTop="8dp"
android:text="Multiply" />
<Button
android:id="@+id/buttonDivide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonMultiply"
android:layout_marginTop="8dp"
android:text="Divide" />
<TextView
android:id="@+id/textViewResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonDivide"
android:layout_marginTop="16dp"
android:text="Result:"
android:textSize="18sp" />
</RelativeLayout>
Java Code :
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextNumber1 = findViewById(R.id.editTextNumber1);
editTextNumber2 = findViewById(R.id.editTextNumber2);
buttonAdd = findViewById(R.id.buttonAdd);
buttonSubtract = findViewById(R.id.buttonSubtract);
buttonMultiply = findViewById(R.id.buttonMultiply);
buttonDivide = findViewById(R.id.buttonDivide);
textViewResult = findViewById(R.id.textViewResult);
buttonAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
performOperation('+');
}
});
buttonSubtract.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
performOperation('-');
}
});
buttonMultiply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
performOperation('*');
}
});
buttonDivide.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
performOperation('/');
}
});
}
if (num1Str.isEmpty() || num2Str.isEmpty()) {
textViewResult.setText("Please enter both numbers");
return;
}
switch (operation) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
if (num2 != 0) {
result = num1 / num2;
} else {
textViewResult.setText("Cannot divide by zero");
return;
}
break;
}
8. Develop an application to display a Google Map. (Write JAVA and Manifest file)
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Obtain the MapFragment and get notified when the map is ready to be used.
MapFragment mapFragment = (MapFragment)
getFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
// Add markers, polylines, polygons, etc., as needed.
// For now, let's just display the map.
}
}
MANIFEST FILE :
<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/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</application>
</manifest>
9. Develop an application to convert “thanks” text to speech as given in the following GUI.
XML LAYOUT :
<Button
android:id="@+id/buttonSpeak"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Speak"
android:layout_centerInParent="true"/>
</RelativeLayout>
JAVA :
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Locale;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@Override
protected void onDestroy() {
// Shutdown TextToSpeech when the activity is destroyed
if (textToSpeech != null) {
textToSpeech.stop();
textToSpeech.shutdown();
}
super.onDestroy();
}
}
10. Develop an application to update a record of an employee whose emp.id is ‘E101’ in SQlite
database. Change employee name from “PQR” to “XYZ”. Also display the updated record.
(Write .java and .xml files)
JAVA :
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonUpdate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateRecord();
}
});
}
// Update record
String updateQuery = "UPDATE " + DBHelper.TABLE_EMPLOYEE +
" SET " + DBHelper.COLUMN_NAME + " = 'XYZ' " +
" WHERE " + DBHelper.COLUMN_ID + " = 'E101'";
db.execSQL(updateQuery);
db.close();
}
}
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE_EMPLOYEE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_EMPLOYEE);
onCreate(db);
}
}
12. Develop a program to TURN ON and OFF bluetooth. Write .java file and permission tags
JAVA :
import android.bluetooth.BluetoothAdapter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Button buttonTurnOn = findViewById(R.id.buttonTurnOn);
Button buttonTurnOff = findViewById(R.id.buttonTurnOff);
buttonTurnOn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
turnOnBluetooth();
}
});
buttonTurnOff.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
turnOffBluetooth();
}
});
}
MANIFEST :
<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/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
import androidx.appcompat.app.AppCompatActivity;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextTo = findViewById(R.id.editTextTo);
editTextSubject = findViewById(R.id.editTextSubject);
editTextMessage = findViewById(R.id.editTextMessage);
buttonSend = findViewById(R.id.buttonSend);
buttonSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sendEmail();
}
});
}
// Set up authenticator
Session session = Session.getInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("your_email@gmail.com",
"your_password");
}
});
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
Toast.makeText(MainActivity.this, "Email sent", Toast.LENGTH_SHORT).show();
}
}.execute();
} catch (MessagingException e) {
Log.e(TAG, "Error creating email", e);
}
}
}
XML :
<EditText
android:id="@+id/editTextTo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="To" />
<EditText
android:id="@+id/editTextSubject"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editTextTo"
android:layout_marginTop="16dp"
android:hint="Subject" />
<EditText
android:id="@+id/editTextMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editTextSubject"
android:layout_marginTop="16dp"
android:hint="Message"
android:inputType="textMultiLine"
android:minLines="5" />
<Button
android:id="@+id/buttonSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editTextMessage"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="Send" />
</RelativeLayout>
USER PERMISION :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bluetooth">
<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/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
JAVA :
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
import java.util.Set;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
ListView listViewPairedDevices = findViewById(R.id.listViewPairedDevices);
Button buttonEnableBluetooth = findViewById(R.id.buttonEnableBluetooth);
buttonEnableBluetooth.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
enableBluetooth();
}
});
if (bluetoothAdapter == null) {
Toast.makeText(this, "Bluetooth is not supported on this device",
Toast.LENGTH_SHORT).show();
buttonEnableBluetooth.setEnabled(false);
} else {
if (!bluetoothAdapter.isEnabled()) {
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, 1);
}
listPairedDevices();
}
}
XML :
<Button
android:id="@+id/buttonEnableBluetooth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enable Bluetooth"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"/>
<ListView
android:id="@+id/listViewPairedDevices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/buttonEnableBluetooth"
android:layout_marginTop="16dp"/>
</RelativeLayout>
15. Develop a program to implement i) List view of 5 items ii) Grid view of 4 x 4 items iii) Image
view.
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE_CUSTOMER);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CUSTOMER);
onCreate(db);
}
}
JAVVA :
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextID = findViewById(R.id.editTextID);
editTextName = findViewById(R.id.editTextName);
editTextMobile = findViewById(R.id.editTextMobile);
editTextAddress = findViewById(R.id.editTextAddress);
editTextPinCode = findViewById(R.id.editTextPinCode);
textViewResult = findViewById(R.id.textViewResult);
dbHelper = new DBHelper(this);
if (newRowId != -1) {
Toast.makeText(this, "Customer added with ID: " + newRowId,
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Error adding customer", Toast.LENGTH_SHORT).show();
}
db.close();
}
String id = editTextID.getText().toString();
String[] projection = {
DBHelper.COLUMN_NAME,
DBHelper.COLUMN_MOBILE,
DBHelper.COLUMN_ADDRESS,
DBHelper.COLUMN_PIN_CODE
};
if (cursor.moveToFirst()) {
String name =
cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.COLUMN_NAME));
String mobile =
cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.COLUMN_MOBILE));
String address =
cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.COLUMN_ADDRESS));
String pinCode =
cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.COLUMN_PIN_CODE));
textViewResult.setText(result);
} else {
textViewResult.setText("No customer found with ID: " + id);
}
cursor.close();
db.close();
}
}
LAYOUT :
<EditText
android:id="@+id/editTextID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Customer ID"
android:inputType="number" />
<EditText
android:id="@+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editTextID"
android:layout_marginTop="16dp"
android:hint="Name" />
<EditText
android:id="@+id/editTextMobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editTextName"
android:layout_marginTop="16dp"
android:hint="Mobile Number"
android:inputType="phone" />
<EditText
android:id="@+id/editTextAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editTextMobile"
android:layout_marginTop="16dp"
android:hint="Address" />
<EditText
android:id="@+id/editTextPinCode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editTextAddress"
android:layout_marginTop="16dp"
android:hint="Pin Code"
android:inputType="number" />
<Button
android:id="@+id/buttonAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editTextPinCode"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="Add Customer" />
<Button
android:id="@+id/buttonRetrieve"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonAdd"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="Retrieve Customer" />
<TextView
android:id="@+id/textViewResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonRetrieve"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text=""
android:textSize="18sp" />
</RelativeLayout>
17. Write a program to find the direction from user's current location to MSBTE, Bandra.
(Write only Java and manitest file).
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textViewDirection = findViewById(R.id.textViewDirection);
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[]
permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == LOCATION_PERMISSION_REQUEST_CODE) {
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
// Permission granted, start getting direction
getDirection();
} else {
// Permission denied, show a message
Toast.makeText(this, "Location permission denied",
Toast.LENGTH_SHORT).show();
}
}
}
}
MANIFEST :
<TextView
android:id="@+id/textViewDirection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="18sp" />
</RelativeLayout>
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textViewResult = findViewById(R.id.textViewResult);
Button buttonClear = findViewById(R.id.buttonClear);
Button buttonEqual = findViewById(R.id.buttonEqual);
buttonClear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clearInput();
}
});
buttonEqual.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
calculate();
}
});
}
LAYOUT :
<TextView
android:id="@+id/textViewResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginBottom="16dp"
android:background="@android:color/darker_gray"
android:gravity="end"
android:padding="8dp"
android:textSize="24sp" />
<Button
android:id="@+id/buttonClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textViewResult"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="C"
android:onClick="onClickClear"
android:layout_alignParentEnd="true"/>
<Button
android:id="@+id/buttonDivide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textViewResult"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="/"
android:onClick="onClickOperator"
android:layout_toStartOf="@id/buttonClear"
android:layout_alignParentEnd="true"/>
<Button
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textViewResult"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="7"
android:onClick="onClickNumber"
android:layout_toStartOf="@id/buttonDivide"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
19. Write a program to convert temperature from celcius to farenhite and vice versa using
Toggle button. (Design UI as per your choice. Write XML and java file)
JAVA :
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextTemperature = findViewById(R.id.editTextTemperature);
textViewResult = findViewById(R.id.textViewResult);
toggleButtonUnit = findViewById(R.id.toggleButtonUnit);
toggleButtonUnit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
convertTemperature();
}
});
}
if (isCelsius) {
// Convert Celsius to Fahrenheit
result = (temperature * 9 / 5) + 32;
textViewResult.setText(temperature + " °C = " + result + " °F");
} else {
// Convert Fahrenheit to Celsius
result = (temperature - 32) * 5 / 9;
textViewResult.setText(temperature + " °F = " + result + " °C");
}
}
}
XML :
<EditText
android:id="@+id/editTextTemperature"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter temperature"
android:inputType="numberDecimal"
android:layout_marginBottom="16dp" />
<ToggleButton
android:id="@+id/toggleButtonUnit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="°C"
android:textOn="°F"
android:checked="true"
android:layout_below="@id/editTextTemperature"
android:layout_marginBottom="16dp" />
<TextView
android:id="@+id/textViewResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp"
android:layout_below="@id/toggleButtonUnit" />
</RelativeLayout>
20. Write a program to capture an image using camera and display it.
MANIFEST :
LAYOUT :
<Button
android:id="@+id/buttonCapture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Capture Image"
android:layout_centerHorizontal="true"
android:layout_marginBottom="16dp" />
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/buttonCapture"
android:layout_marginTop="16dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:visibility="gone" />
</RelativeLayout>
JAVA :
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.imageView);
buttonCapture = findViewById(R.id.buttonCapture);
buttonCapture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dispatchTakePictureIntent();
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
imageView.setImageBitmap(imageBitmap);
imageView.setVisibility(View.VISIBLE);
}
}
}
21. Develop and application to send and receive SMS (Design minimal UI as per your choice.
Write XML, java and manifest file)
MANIFEST :
LAYOUT :
<EditText
android:id="@+id/editTextPhoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Phone Number"
android:inputType="phone" />
<EditText
android:id="@+id/editTextMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editTextPhoneNumber"
android:layout_marginTop="16dp"
android:hint="Message" />
<Button
android:id="@+id/buttonSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editTextMessage"
android:layout_marginTop="16dp"
android:text="Send" />
<Button
android:id="@+id/buttonReceive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonSend"
android:layout_marginTop="16dp"
android:text="Receive" />
</RelativeLayout>
JAVA :
import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextPhoneNumber = findViewById(R.id.editTextPhoneNumber);
editTextMessage = findViewById(R.id.editTextMessage);
buttonSend = findViewById(R.id.buttonSend);
buttonReceive = findViewById(R.id.buttonReceive);
buttonSend.setOnClickListener(v -> {
String phoneNumber = editTextPhoneNumber.getText().toString();
String message = editTextMessage.getText().toString();
sendSMS(phoneNumber, message);
});
buttonReceive.setOnClickListener(v -> {
// Request permissions if not granted
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.RECEIVE_SMS)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new
String[]{Manifest.permission.RECEIVE_SMS}, 1);
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
// Unregister receiver
unregisterReceiver(smsReceiver);
}
22. Write a program to implement Android Activity Life Cycle. Use toast messages to display
message through life cycle
JAVA :
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showToast("onCreate()");
}
@Override
protected void onStart() {
super.onStart();
showToast("onStart()");
}
@Override
protected void onResume() {
super.onResume();
showToast("onResume()");
}
@Override
protected void onPause() {
super.onPause();
showToast("onPause()");
}
@Override
protected void onStop() {
super.onStop();
showToast("onStop()");
}
@Override
protected void onDestroy() {
super.onDestroy();
showToast("onDestroy()");
}
@Override
protected void onRestart() {
super.onRestart();
showToast("onRestart()");
}
XML :
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Activity Lifecycle Demo"
android:textSize="24sp"
android:textStyle="bold"
android:layout_centerInParent="true" />
</RelativeLayout>
24. Develop an application to display Google map with user's current location.
PERMISSION :
API key :
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY" />
LAYOUT :
JAVA :
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
mMap.setMyLocationEnabled(true);
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
LOCATION_PERMISSION_REQUEST_CODE);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[]
permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == LOCATION_PERMISSION_REQUEST_CODE) {
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
mMap.setMyLocationEnabled(true);
}
}
}
}
}
25. Design UI using table layout to display buttons with 0 9 numbers on it. Even display submit
and clear button. When user clicks on particular buttons and later when clicks on submit
button, it should display the numbers clicked.
XML :
<Button
android:id="@+id/button0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />
</TableRow>
<!-- Row 2 -->
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp">
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5" />
</TableRow>
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6" />
<Button
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7" />
<Button
android:id="@+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8" />
</TableRow>
<Button
android:id="@+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9" />
<Button
android:id="@+id/buttonSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />
<Button
android:id="@+id/buttonClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear" />
</TableRow>
</TableLayout>
JAVA :
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
import java.util.List;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);