22617 (1)
22617 (1)
22617 (1)
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
WINTER – 2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Ans Explanation 2 M
Page No: 1 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
• Users buy devices and applications
b) Define Emulator. 2M
Ans An Android emulator is a tool that creates virtual Android devices on your computer. Correct
The emulator lets you prototype, develop and test Android applications without using Definition 2 M
a physical device
• The application layer runs within the Android run time using the classes and
services made available from the application framework.
Page No: 3 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
2. Application Framework:
• It basically provides the services through which we can create the particular
class and make that class helpful for the Applications creation.
Page No: 4 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
internal part and it contains a components like core libraries and the Dalvik
virtual machine.
• The Android run time is the engine that powers our applications along with the
libraries and it forms the basis for the application framework.
• It is specially designed and optimized for android to ensure that a device can
run multiple instances efficiently. It relies on the Linux kernel for threading
and low-level memory
• management.
• The core libraries in android runtime will enable us to implement an android
applications using standard JAVA programming language.
4. Platform Libraries:
• The Platform Libraries includes various C/C++ core libraries and Java based
libraries such as SSL,libc, Graphics, SQLite, Webkit, Media, Surface Manger,
OpenGL etc. to provide a support for android development.
5. Linux Kernel:
• Linux Kernel is a bottom layer and heart of the android architecture. It is heart
of Android architecture that exists at the root of android architecture and
contains all the low-level device drivers for the various hardware components
of an Android device.
• The Linux Kernel will provide an abstraction layer between the device
hardware and the remainder of the stack. It is responsible for memory
management, power management, device management, resource access, etc.
Ans A RelativeLayout is a type of ViewGroup that allows you to position its child views Explanation 2
relative to each other or to the parent container. This layout is powerful because it lets M,
you align views based on rules such as being above, below, to the left, to the right, or Example 2 M
(Consider any
centered relative to other views or the parent layout.
suitable
example)
Page No: 5 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Attributes Used in RelativeLayout:
• android:layout_alignParentLeft or android:layout_alignParentStart:
Aligns the view to the left or start of the parent.
• android:layout_alignParentRight or android:layout_alignParentEnd:
Aligns the view to the right or end of the parent.
Example of RelativeLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, RelativeLayout!"
android:textSize="20sp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
<Button
Page No: 6 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me"
android:layout_below="@id/textView1"
android:layout_centerHorizontal="true"/>
<ImageView
android:id="@+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/ic_launcher_foreground"
android:layout_below="@id/button1"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="@+id/formTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Page No: 7 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:text="Student Registration Form"
android:textSize="24sp"
android:textColor="#000000"
android:layout_gravity="center"
android:layout_marginBottom="20dp"/>
<TextView
android:id="@+id/labelName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Full Name:"
android:textSize="16sp"
android:layout_marginBottom="8dp"/>
<EditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:layout_marginBottom="16dp"/>
<TextView
android:id="@+id/labelEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email Address:"
Page No: 8 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:textSize="16sp"
android:layout_marginBottom="8dp"/>
<EditText
android:id="@+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Email"
android:inputType="textEmailAddress"
android:layout_marginBottom="16dp"/>
<TextView
android:id="@+id/labelGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender:"
android:textSize="16sp"
android:layout_marginBottom="8dp"/>
<RadioGroup
android:id="@+id/radioGroupGender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="16dp">
Page No: 9 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
<RadioButton
android:id="@+id/rbMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:layout_marginEnd="16dp"/>
<RadioButton
android:id="@+id/rbFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:layout_marginEnd="16dp"/>
<RadioButton
android:id="@+id/rbOther"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Other"/>
</RadioGroup>
<TextView
android:id="@+id/labelCourse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Course:"
Page No: 10 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:textSize="16sp"
android:layout_marginBottom="8dp"/>
<Spinner
android:id="@+id/spinnerCourse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp" />
<Button
android:id="@+id/btnSubmit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit"
android:textSize="18sp"
android:layout_marginTop="16dp" />
</LinearLayout>
• You’ll need to pay a one-time registration fee of $25 using your international
credit or debit card. It can take up to 48 hours for your registration to be fully
processed.
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
Page No: 11 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
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.
• 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. You not necessarily complete it at once , you can always save a
draft and revisit it later when you’re ready to publish.
• The information required for your store listing is divided into several
categories such as Product Details containing title, short and full description of
the app, Your app’s title and description should be written with a great user
experience in mind. Use the right keywords, but don’t overdo it. Make sure
your app doesn’t come across as spam-y or promotional, or it will risk getting
suspended on the Play Store.
• Graphic Assets where you can add screenshots, images, videos, promotional
graphics, and icons that showcase your app’s features and functionality.
• 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.
• This is a safer option because you can analyze the test results and optimize or
Page No: 12 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
fix your app accordingly if you need to before rolling it out to all users.
• Once you create a production release, your uploaded app version will become
accessible to everyone in the countries you choose to distribute it in and click
on ‘Create release.’
• 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.
• To rate your app, you need to fill out a content rating questionnaire An
appropriate content rating will also help you get to the right audience, which
will eventually improve your engagement rates.
• 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.
• You can always change your app from paid to free later, but you cannot change
a free app to paid. For that, you’ll need to create a new app and set its price.
• 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.
• Once you’re sure about the correctness of the details, select your app and
navigate to ‘Release management’ – ‘App releases.’
• You can always opt for reviews by clicking on ‘Review’ to be taken to the
‘Review and rollout release’ screen. Here, you can see if there are any issues or
warnings you might have missed out on.
• Finally, select ‘Confirm rollout.’ This will also publish your app to all users in
your target countries on Google Play.
Page No: 13 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans 4 correct points-
4M
DVM JVM
It is Register based which is designed to It is Stack based.
run on low memory.
DVM uses its own byte code and runs JVM uses java byte code and runs
the “.Dex” file. From Android 2.2 SDK “.class” file having JIT (Just In Time).
Dalvik has got a Just in Time compiler
DVM has been designed so that a device A single instance of JVM is shared with
can run multiple instances of the VM multiple applications.
efficiently. Applications are given their
own instance
DVM supports the Android operating JVM supports multiple operating
system only. systems.
There is a constant pool for every It has a constant pool for every class.
application.
Here the executable is APK. Here the executable is JAR
b) Describe sensors use in Android. 4M
Ans Most of the android devices have built-in sensors that measure motion, orientation, and 1 M for each
various environmental condition. The android platform supports three broad categories sensor’s use
of sensors.
1. Motion Sensors
These are used to measure acceleration forces and rotational forces along with three
axes.
2. Environmental sensors
These are used to measure the environmental changes such as temperature, humidity
etc.
3. Position sensors
These are used to measure the physical position of device.
Example:
TYPE_ACCELE_ROMETER
TYPE_GRAVITY
TYPE_LIGHT
TYPE_ORIENTATION
TYPE_PRESSURE
Some of the sensors are hardware based and some are software based sensors.
Whatever the sensor is, android allows us to get the raw data from these sensors and
use it in our application.
Page No: 14 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Android provides SensorManager and Sensor classes to use the sensors in our
application.
1) SensorManager class
The android.hardware.SensorManager class provides methods :
o to get sensor instance,
o to access and list sensors,
o to register and unregister sensor listeners etc.
You can get the instance of SensorManager by calling the method getSystemService()
and passing the SENSOR_SERVICE constant in it.
SensorManager sm = (SensorManager)getSystemService(SENSOR_SERVICE);
2) Sensor class
The android.hardware.Sensor class provides methods to get information of the sensor
such as sensor name, sensor type, sensor resolution, sensor type etc.
3) SensorEvent class
Its instance is created by the system. It provides information about the sensor.
4) SensorEventListener interface
It provides two call back methods to get information when sensor values (x,y and z)
change or sensor accuracy changes.
Page No: 15 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:layout_height="wrap_content" />
</LinearLayout>
2. Java Code (MainActivity.java)
package com.example.listviewdemo;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
String[] items = {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"};
ArrayAdapter<String> adapter = new ArrayAdapter<>(
this,
android.R.layout.simple_list_item_1,
items
);
listView.setAdapter(adapter);
}
}
Page No: 16 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
2. Real-Time Logs:
It displays real-time application logs, allowing developers to track events, actions, and
method calls while the app is running.
3. Performance Monitoring:
Helps measure memory usage, CPU activity, and network operations to optimize the
app’s performance.
4. Debugging UI Issues:
The console highlights UI-related errors like invalid layouts or missing resources,
helping ensure proper user interface design.
5. Testing and Feedback:
Supports testing by showing outputs of log messages (Log.d, Log.e, etc.), making it
easier to verify functionality and behavior during development.
Page No: 17 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
b) Double-click the downloaded file.
c) If you see a User Account Control dialog about allowing the installation to
make changes to your computer, click Yes to confirm the installation.
d) Click Next to start the installation.
e) Accept the default installation settings for all steps.
f) Click finish when installation is done.
• EditText 2 M for
Example code
• Button XML or Java
Code
• ImageView
• ListView
• CheckBox
• RadioButton
• ProgressBar
Example Code:
XML Layout (activity_main.xml):
<Button
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me" />
Page No: 18 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button myButton = findViewById(R.id.myButton);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Button Clicked!",
Toast.LENGTH_SHORT).show();
}
});
}
}
* Note: Consider any suitable example.
Page No: 19 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bluetooth"
android:id="@+id/text"
android:textSize="20dp"
android:gravity="center"/>
<Button
android:id="@+id/on"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:layout_marginTop="62dp"
android:text="ON" />
<Button
android:id="@+id/discoverable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/on"
android:layout_marginTop="74dp"
android:text="DISCOVERABLE" />
<Button
android:id="@+id/off"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/discoverable"
android:layout_marginTop="104dp"
android:text="OFF" />
</RelativeLayout>
Menifest File:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ifcdiv">
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
Java File
package com.example.ifcdiv;
import androidx.appcompat.app.AppCompatActivity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.os.Bundle;
Page No: 20 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
import android.view.View;
import android.widget.Button;
on=findViewById(R.id.on);
off=findViewById(R.id.off);
dis=findViewById(R.id.discoverable);
BluetoothAdapter bluetoothAdapter=BluetoothAdapter.getDefaultAdapter();
on.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!bluetoothAdapter.isEnabled())
{
Intent i=new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(i,REQUEST_ENABLE);
}
}
});
dis.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!bluetoothAdapter.isDiscovering())
{
Intent i=new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
startActivityForResult(i,REQUEST_DIS);
}
}
});
off.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bluetoothAdapter.disable();
}
});
}
}
Page No: 21 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
d) Explain Geocoding and reverse geocoding in android with example. 4M
Ans Geocoding: Converts an address (like "123 Main St, Mumbai") into geographical 3 M for Code,
coordinates (latitude and longitude). 1 M for
Permissions
Reverse Geocoding: Converts geographical coordinates into a readable address (like
"123 Main St, Mumbai").
Example: Geocoding and Reverse Geocoding
1. Add Permissions
Include location permissions in the AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
/>
2. Layout File (res/layout/activity_main.xml)
A layout with a button and two TextView elements to show results.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<Button
android:id="@+id/btnGeocode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Get Coordinates from Address" />
<TextView
android:id="@+id/tvGeocodeResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp" />
<Button
Page No: 22 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:id="@+id/btnReverseGeocode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Get Address from Coordinates"
android:layout_marginTop="20dp" />
<TextView
android:id="@+id/tvReverseGeocodeResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp" />
</LinearLayout>
3. Java Code (MainActivity.java)
Using Geocoder to perform geocoding and reverse geocoding.
package com.example.geocodingdemo;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Page No: 23 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
setContentView(R.layout.activity_main);
Button btnGeocode = findViewById(R.id.btnGeocode);
TextView tvGeocodeResult = findViewById(R.id.tvGeocodeResult);
Button btnReverseGeocode = findViewById(R.id.btnReverseGeocode);
TextView tvReverseGeocodeResult =
findViewById(R.id.tvReverseGeocodeResult);
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
// Geocoding: Address to Coordinates
btnGeocode.setOnClickListener(v -> {
String address = "123 Main St, Mumbai";
try {
List<Address> addresses = geocoder.getFromLocationName(address, 1);
if (addresses != null && !addresses.isEmpty()) {
Address location = addresses.get(0);
tvGeocodeResult.setText("Coordinates: " + location.getLatitude() + ", " +
location.getLongitude());
} else {
tvGeocodeResult.setText("Address not found");
}
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this, "Error: " + e.getMessage(),
Toast.LENGTH_SHORT).show();
}
});
// Reverse Geocoding: Coordinates to Address
btnReverseGeocode.setOnClickListener(v -> {
double latitude = 19.0760; // Example: Mumbai's latitude
double longitude = 72.8777; // Example: Mumbai's longitude
Page No: 24 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
try {
List<Address> addresses = geocoder.getFromLocation(latitude, longitude,
1);
if (addresses != null && !addresses.isEmpty()) {
Address address = addresses.get(0);
tvReverseGeocodeResult.setText("Address: " +
address.getAddressLine(0));
} else {
tvReverseGeocodeResult.setText("Address not found");
}
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this, "Error: " + e.getMessage(),
Toast.LENGTH_SHORT).show();
}
});
}
}
Ans A service is an application component which runs without direst interaction with the 1 M for diagram,
user in the background.
3 M for
● Services are used for repetitive and potentially long running operations, i.e., Internet Explanation
downloads, checking for new data, data processing, updating content providers and the
like.
● Service can either be started or bound we just need to call either startService() or
bindService() from any of our android components. Based on how our service was
started it will either be “started” or “bound”
Service Lifecycle
1. Started
a. A service is started when an application component, such as an activity, starts it by
calling startService().
b. Now the service can run in the background indefinitely, even if the component that
Page No: 25 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
started it is destroyed.
2. Bound
a. A service is bound when an application component binds to it by calling
bindService().
b. A bound service offers a client-server interface that allows components to interact
with the service, send requests, get results, and even do so across processes with
InterProcess Communication (IPC).
c. Like any other components service also has callback methods. These will be
invoked while the service is running to inform the application of its state.
Implementing these in our custom service would help you in performing the right
operation in the right state.
d. There is always only a single instance of service running in the app. If you are
calling startService() for a single service multiple times in our application it just
invokes the onStartCommand() on that service. Neither is the service restarted
Page No: 26 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
multiple times nor are its multiple instances created
1. onCreate():
This is the first callback which will be invoked when any component starts the
service. If the same service is called again while it is still running this method Won’t
be invoked. Ideally one time setup and intializing should be done in this callback.
2. onStartCommand() /startSetvice()
This callback is invoked when service is started by any component by calling
startService(). It basically indicates that the service has started and can now run
indefinetly.
3. onBind()
To provide binding for a service, you must implement the onBind() callback method.
This method returns an IBinder object that defines the programming interface that
clients can use to interact with the service.
4. onUnbind()
This is invoked when all the clients are disconnected from the service.
5. onRebind()
This is invoked when new clients are connected to the service. It is called after
onRebind
6. onDestroy()
This is a final clean up call from the system. This is invoked just before the service is
being destroyed.
a) Develop the android application for student marksheets using table layout atleast 6M
five subject marks with total and percentage. (Write both Java and xml code)
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
Page No: 27 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Student Marksheet"
android:textSize="24sp"
android:layout_gravity="center"
android:marginBottom="20dp" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:padding="8dp">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subject 1"
android:paddingEnd="8dp"/>
<EditText
android:id="@+id/subject1_marks"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="number"
Page No: 28 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:hint="Marks"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subject 2"
android:paddingEnd="8dp"/>
<EditText
android:id="@+id/subject2_marks"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="number"
android:hint="Marks"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subject 3"
android:paddingEnd="8dp"/>
<EditText
Page No: 29 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:id="@+id/subject3_marks"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="number"
android:hint="Marks"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subject 4"
android:paddingEnd="8dp"/>
<EditText
android:id="@+id/subject4_marks"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="number"
android:hint="Marks"/>
</TableRow>
<TableRow>
Page No: 30 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subject 5"
android:paddingEnd="8dp"/>
<EditText
android:id="@+id/subject5_marks"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="number"
android:hint="Marks"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Total Marks"
android:paddingEnd="8dp"/>
<TextView
android:id="@+id/total_marks"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
Page No: 31 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:text="0"
android:gravity="end"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Percentage"
android:paddingEnd="8dp"/>
<TextView
android:id="@+id/percentage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="0%"
android:gravity="end"/>
</TableRow>
</TableLayout>
<Button
android:id="@+id/submit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculate"
Page No: 32 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:layout_gravity="center"/>
</LinearLayout>
Java Code
package com.example.studentmarksheet;
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;
Button calculateButton;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Page No: 33 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
subject1 = findViewById(R.id.subject1_marks);
subject2 = findViewById(R.id.subject2_marks);
subject3 = findViewById(R.id.subject3_marks);
subject4 = findViewById(R.id.subject4_marks);
subject5 = findViewById(R.id.subject5_marks);
totalMarks = findViewById(R.id.total_marks);
percentage = findViewById(R.id.percentage);
calculateButton = findViewById(R.id.submit_button);
calculateButton.setOnClickListener(new View.OnClickListener() {
@Override
try {
Page No: 34 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
totalMarks.setText(String.valueOf(total));
percentage.setText(String.format("%.2f%%", percentageValue));
} catch (NumberFormatException e) {
});
b) Develop an application to store student details like roll no, name, marks and 6M
retrieve student information using roll no. in SQLite database. (Write java and
xml file).
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="@+id/editRollNo"
android:layout_width="match_parent"
Page No: 35 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:layout_height="wrap_content"
android:hint="Roll No"
android:inputType="number" />
<EditText
android:id="@+id/editName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:inputType="text" />
<EditText
android:id="@+id/editMarks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Marks"
android:inputType="number" />
<Button
android:id="@+id/saveButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
<EditText
android:id="@+id/searchRollNo"
Page No: 36 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
<Button
android:id="@+id/searchButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
<TextView
android:id="@+id/studentInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:gravity="center"
android:layout_marginTop="20dp" />
</LinearLayout>
Java Code
package com.example.studentinfo;
import android.content.ContentValues;
import android.database.Cursor;
Page No: 37 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
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;
// UI components
TextView studentInfo;
DBHelper dbHelper;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize UI components
editRollNo = findViewById(R.id.editRollNo);
Page No: 38 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
editName = findViewById(R.id.editName);
editMarks = findViewById(R.id.editMarks);
searchRollNo = findViewById(R.id.searchRollNo);
saveButton = findViewById(R.id.saveButton);
searchButton = findViewById(R.id.searchButton);
studentInfo = findViewById(R.id.studentInfo);
// Initialize DB helper
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
saveStudentInfo();
});
searchButton.setOnClickListener(new View.OnClickListener() {
@Override
searchStudentInfo();
});
Page No: 39 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
} else {
SQLiteDatabase db = dbHelper.getWritableDatabase();
values.put(DBHelper.COLUMN_ROLL_NO, rollNo);
values.put(DBHelper.COLUMN_NAME, name);
values.put(DBHelper.COLUMN_MARKS, marks);
if (result == -1) {
} else {
clearFields();
Page No: 40 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
}
if (rollNo.isEmpty()) {
} else {
SQLiteDatabase db = dbHelper.getReadableDatabase();
String[] projection = {
DBHelper.COLUMN_ROLL_NO,
DBHelper.COLUMN_NAME,
DBHelper.COLUMN_MARKS
};
String name =
cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.COLUMN_NAME));
Page No: 41 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
String marks =
cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.COLUMN_MARKS));
cursor.close();
} else {
editRollNo.setText("");
editName.setText("");
editMarks.setText("");
searchRollNo.setText("");
Ans GridView just works like ListView, The only difference is that GridView is used to Grid view
display grid of View objects. definition 1 M
The view objects can be a Text view, an Image view or a view group which has both Example of grid
an image and some text. view 2 M
Vertical and horizontal spacing between every single items of gridView can be set Image view
by verticalSpacing and horizontalSpacing. definition 1 M
Example of
GridView Example image view 2 M
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
Page No: 42 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFEB3B"
tools:context="com.example.android.studytonightandroid.MainActivity">
<GridView
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:numColumns="2"/>
</android.support.constraint.ConstraintLayout>
Now we will create a new XML file, with name grid_item.xml in the layout folder,
and add a TextView
Java File
public class MainActivity extends AppCompatActivity
{
GridView gridView;
TextView textView;
String[] carBrands = { "Ferrari", "McLaren", "Jaguar", "Skoda", "Suzuki",
Page No: 43 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
"Hyundai", "Toyota", "Renault", "Mercedes", "BMW", "Ford",
"Honda", "Chevrolet", "Volkswagon" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridView = (GridView)findViewById(R.id.gridView);
textView = (TextView)findViewById(R.id.textView);
listView.setAdapter(adapter);
} }
ImageView
<ImageView
android:id="@+id/simpleImageView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000"
android:src="@drawable/lion"
android:padding="30dp"/>
Ans DatePicker is used to display date selection widget in android application. It can be Date picker
used in either spinner mode or calendar mode ( date picker). explanation 2 M
Xml file 2 M
Java file 2 M
Page No: 44 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
DatePicker Properties:
DatePickerMode :
Value can be spinner or calendar. If set to calendar, it will display a calendar which let
you choose date. If set to spinner, it will display a spinner to let you choose date.
XML file:
<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: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">
<DatePicker
android:id="@+id/simpleDatePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#150"
android:datePickerMode="spinner" />
<Button
android:id="@+id/submitButton"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@+id/simpleDatePicker"
Page No: 45 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:background="#150"
android:text="SUBMIT"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
Java File:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.DatePicker;
import android.widget.Button;
import android.widget.Toast;
DatePicker simpleDatePicker;
Button submit;
@Override
super.onCreate(savedInstanceState);
Page No: 46 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
setContentView(R.layout.activity_main);
submit.setOnClickListener(new View.OnClickListener() {
@Override
});
b) Write a program to find the direction from ·user's current location to MSBTE, 6M
Bandra (Write only java and manifest file) )
Page No: 47 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
MainActivity.java
import android.Manifest;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.net.Uri;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
Page No: 48 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
import com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions;
import com.karumi.dexter.Dexter;
import com.karumi.dexter.MultiplePermissionsReport;
import com.karumi.dexter.PermissionToken;
import com.karumi.dexter.listener.DexterError;
import com.karumi.dexter.listener.PermissionRequest;
import com.karumi.dexter.listener.PermissionRequestErrorListener;
import com.karumi.dexter.listener.multi.MultiplePermissionsListener;
import java.util.List;
public class MainActivity extends AppCompatActivity implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
com.google.android.gms.location.LocationListener , OnMapReadyCallback,
TaskLoadedCallback{
//variables for map and route
private GoogleMap mMap;
private MarkerOptions place1, place2;
Button getDirection;
private Polyline currentPolyline;
private MapFragment mapFragment;
private boolean isFirstTime = true;
//variables for current location
private static final String TAG = "MainActivity";
private TextView tvLocation;
private GoogleApiClient mGoogleApiClient;
private Location mLocation;
private LocationRequest mLocationRequest;
private com.google.android.gms.location.LocationListener listener;
Page No: 49 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
private long UPDATE_INTERVAL = 2 * 1000; /* 10 secs */
private long FASTEST_INTERVAL = 2000; /* 2 sec */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//code for getting current location
requestMultiplePermissions();
tvLocation = (TextView) findViewById((R.id.tv));
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
} //code for drawing route
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.clear();
Log.d("mylog", "Added Markers");
mMap.addMarker(place1);
mMap.addMarker(place2);
CameraPosition googlePlex = CameraPosition.builder()
.target(new LatLng(22.7739,71.6673))
.zoom(7)
.bearing(0)
.tilt(45)
.build();
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(googlePlex),
Page No: 50 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
5000,
null);
}
private String getUrl(LatLng origin, LatLng dest, String directionMode) {
// Origin of route
String str_origin = "origin=" + origin.latitude + "," + origin.longitude;
// Destination of route
String str_dest = "destination=" + dest.latitude + "," + dest.longitude;
// Mode
String mode = "mode=" + directionMode;
// Building the parameters to the web service
String parameters = str_origin + "&" + str_dest + "&" + mode;
// Output format
String output = "json";
// Building the url to the web service
String url = "https://maps.googleapis.com/maps/api/directions/" + output + "?" +
parameters + "&key=" + getString(R.string.google_maps_key);
return url;
}
@Override
public void onTaskDone(Object... values) {
if (currentPolyline != null)
currentPolyline.remove();
currentPolyline = mMap.addPolyline((PolylineOptions) values[0]);
}
//runtime permission method
private void requestMultiplePermissions(){
Dexter.withActivity(this)
Page No: 51 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
withPermissions(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION )
.withListener(new MultiplePermissionsListener() {
@Override
public void onPermissionsChecked(MultiplePermissionsReport report) {
// check if all permissions are granted
if (report.areAllPermissionsGranted()) {
Toast.makeText(getApplicationContext(), "All permissions are granted by
user!", Toast.LENGTH_SHORT).show();
}
// check for permanent denial of any permission
if (report.isAnyPermissionPermanentlyDenied()) {
// show alert dialog navigating to Settings
openSettingsDialog();
}
}
@Override
public void onPermissionRationaleShouldBeShown(List<PermissionRequest>
permissions, PermissionToken token) {
token.continuePermissionRequest();
}
}).
withErrorListener(new PermissionRequestErrorListener() {
@Override
public void onError(DexterError error) {
Toast.makeText(getApplicationContext(), "Some Error! ",
Toast.LENGTH_SHORT).show();
Page No: 52 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
}
})
.onSameThread()
.check();
}
private void openSettingsDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Required Permissions");
builder.setMessage("This app require permission to use awesome feature. Grant them
in
app settings.");
builder.setPositiveButton("Take Me To SETTINGS", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
Intent intent = new
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivityForResult(intent, 101);
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
Page No: 53 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
builder.show();
}
//methods for getting current location
@Override
public void onConnected(Bundle bundle) {
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
return;
}
startLocationUpdates();
mLocation =
LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if(mLocation == null){
startLocationUpdates();
}
if (mLocation != null) {
// mLatitudeTextView.setText(String.valueOf(mLocation.getLatitude()));
//mLongitudeTextView.setText(String.valueOf(mLocation.getLongitude()));
} else {
Toast.makeText(this, "Location not Detected", Toast.LENGTH_SHORT).show();
}}
@Override
public void onConnectionSuspended(int i) {
Log.i(TAG, "Connection Suspended");
mGoogleApiClient.connect();
Page No: 54 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.i(TAG, "Connection failed. Error: " + connectionResult.getErrorCode());
}
@Override
protected void onStart() {
super.onStart();
if (mGoogleApiClient != null) { mGoogleApiClient.connect();
}}
@Override
protected void onStop() {
super.onStop();
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}}
protected void startLocationUpdates() {
// Create the location request
mLocationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(UPDATE_INTERVAL)
.setFastestInterval(FASTEST_INTERVAL);
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
return;
Page No: 55 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
}
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,
mLocationRequest, this);
}
@Override
public void onLocationChanged(Location location) {
String msg = "Updated Location: " +
Double.toString(location.getLatitude()) + "," +
Double.toString(location.getLongitude());
tvLocation.setText(String.valueOf(location.getLatitude() +"
"+String.valueOf(location.getLongitude())));
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
if(isFirstTime){
//code to draw path on map
getDirection = findViewById(R.id.btnGetDirection);
getDirection.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new FetchURL(MainActivity.this).execute(getUrl(place1.getPosition(),
place2.getPosition(), "driving"), "driving");
}
});
place1 = new MarkerOptions().position(new LatLng(location.getLatitude(),
location.getLongitude())).title("Location 1");
place2 = new MarkerOptions().position(new
LatLng(19.021824,72.8662016)).title("MSBTE");
mapFragment = (MapFragment)
getFragmentManager().findFragmentById(R.id.mapNearBy);
Page No: 56 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
mapFragment.getMapAsync(this);
isFirstTime = false;
} }}
Note: Imports are not required in coding.
c) Develop and application to send SMS (Design minimal UI as per your choice. 6M
Write XML ,Java and manifest file).
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
send = findViewById(R.id.send);
msg = findViewById(R.id.sms);
phone = findViewById(R.id.phone);
requestMessage();
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Page No: 57 | 58
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
if(checkPermission()) {
sendSMS();
} else {
requestMessage();
}
}
});
}
sm = SmsManager.getDefault();
sm.sendTextMessage(PhoneText , null, MsgTxt,null,null);
Toast.makeText(MainActivity.this, "Message sent",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(MainActivity.this, "Message not sent",
Toast.LENGTH_SHORT).show();
}
}
public boolean checkPermission(){
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.SEND_SMS) ==
PackageManager.PERMISSION_GRANTED) {
return true;
} else return false;
}
}
AndroidManifest.xml:
o <uses-feature android:name="android.hardware.telephony" />
o <uses-permission
android:name="android.permission.SEND_SMS"/>
Page No: 58 | 58