XXXXX: The Emulator Lets You Prototype, Develop and Test Android Applications Without Using A Physical Device
XXXXX: The Emulator Lets You Prototype, Develop and Test Android Applications Without Using A Physical Device
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
WINTER – 2023 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Page No: 1 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
c) List any four attributes of layout. 2M
Ans android:id Any 4 attributes
android:layout_width
One attribute for ½
android:layout_height
Mark
android:layout_margin
android:layout_marginTop 2M
android:layout_marginBottom
android:layout_marginLeft
android:layout_marginRight
android:background
d) Define Geocoding and Reverse Geocoding. 2M
Reverse Geocoding :
Reverse geocoding is the process of transforming a (latitude, longitude) coordinate
into a (partial) address.
Ans Intent is the message that is passed between components such as activities. Definition 1 M
Android uses Intent for communicating between the components of an Application Types Listing 1 M
and also from one application to another application.
Types:
Explicit Intent
Implicit Intent
f) Write difference between toggle button and radio button. 2M
Page No: 2 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
g) Define: 2M
i)Fragment
ii) Broadcast receiver
Ans Fragment: Fragment :1 M
Fragment is the part of activity, it is also known as sub-activity.
Broadcast receiver :
1M
Broadcast receiver:
Attribute Description
Page No: 3 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
1. Click Download Android Studio. The Terms and Conditions page with
the Android Studio License Agreement opens.
2. Read the License Agreement.
3. At the bottom of the page, if you agree with the terms and conditions,
select the I have read and agree with the above terms and
Page No: 4 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
conditions checkbox.
4. Click Download Android Studio to start the download.
5. When prompted, save the file to a location where you can easily locate it,
such as the Downloads folder.
6. Wait for the download to complete.
Within Android Studio, you can install the Android SDK as follows:
c) Explain the need of Android Operating System. Also describe any four 4M
features of android.
Open Source:
Multi-Platform Support
Multi-Carrier Support
World wide a large number of telecom carriers like Airtel, Vodafone, Idea
Cellular, AT&T Mobility, BSNL etc. are supporting Android powered
phones.
Android Market place (Google Play store) has very few restrictions on the
content or functionality of an android app. So the developer can distribute
theirs app through Google Play store and as well other distribution channels
like Amazon’s app store.
Four features of android
1) Near Field Communication (NFC)
Most Android devices support NFC, which allows electronic devices to easily
interact across short distances.
2) Alternate Keyboards
Android supports multiple keyboards and makes them easy to install; the SwiftKey,
Skype, and 8pen apps all offer ways to quickly change up your keyboard style.
3) Infrared Transmission
The Android operating system supports a built-in infrared transmitter, allowing you
to use your phone or tablet as a remote control.
4) No-Touch Control
Using Android apps such as Wave Control, users can control their phones touch-free,
using only gestures.
5) Automation
The Tasker app controls the app permissions but also automate them
Using the Android Market or third-party options like AppBrain, we can download
apps on PC and then automatically sync them with Android, no plugging required.
Page No: 6 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
7) Storage and Battery Swap
While it’s possible to hack certain phones to customize the home screen, Android
comes with this capability from the get-go
9) Widgets
Apps are versatile, but sometimes you want information at a glance instead of having
to open an app and wait for it to load. Android widgets let you display just about any
feature you choose, right on the home screen—including weather apps, music
widgets, or productivity tools that helpfully remind you of upcoming meetings or
approaching deadlines.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to
be used.
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
Page No: 7 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
mMap = googleMap;
Ans A service is an application component which runs without direst interaction with Explanation 2 M,
Diagram 2 M
the user in the background.
● Services are used for repetitive and potentially long running operations, i.e.,
Internet 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
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
Page No: 8 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
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
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.
Page No: 9 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
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.
Therefore, one application has not granted access to other applications’ files.
Android application has been signed with a certificate with a private key
Know the owner of the application is unique.
This allows the author of the application will be identified if needed. When
an application is installed in the phone is assigned a user ID, thus avoiding it
from affecting it other applications by creating a sandbox for it.
This user ID is permanent on which devices and applications with the same
user ID are allowed to run in a single process.
It is mandatory for an application to list all the resources it will Access during
installation. Terms are required of an application, in the installation process
should be user-based or interactive Check with the signature of the
application
Page No: 10 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
affects whether runtime permission requests are required. There are three
protection levels that affect third party apps: normal, signature, and
dangerous permissions.
Normal permissions: Normal permissions cover areas where your app needs
to access data or resources outside the app’s sandbox, but where there’s very
little risk to the user’s privacy or the operation of other apps. For example,
permission to set the time zone is a normal permission. If an app declares in
its manifest that it needs a normal permission, the system automatically
grants the app that permission at install time. The system doesn’t prompt the
user to grant normal permissions, and users cannot revoke these permissions.
Signature permissions: The system grants these app permissions at install
time, but only when the app that attempts to use permission is signed by the
same certificate as the app that defines the permission.
Dangerous permissions: Dangerous permissions cover areas where the app
wants data or resources that involve the user’s private information, or could
potentially affect the user’s stored data or the operation of other apps. For
example, the ability to read the user’s contacts is a dangerous permission. If
an app declares that it needs a dangerous permission, the user must explicitly
grant the permission to the app. Until the user approves the permission, your
app cannot provide functionality that depends on that permission. To use a
dangerous permission, your app must prompt the user to grant permission at
runtime. For more details about how the user is prompted, see Request
prompt for dangerous permission.
Page No: 11 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:text="@string/loginForm"
android:textColor="#0ff"
android:textSize="25sp"
android:textStyle="bold" />
</TableRow>
<TableRow>
<TextView
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="10dp"
android:text="@string/userName"
android:textColor="#fff"
android:textSize="16sp" />
<EditText
android:id="@+id/userName"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_marginLeft="10dp"
android:background="#fff"
android:hint="@string/userName"
android:padding="5dp"
android:textColor="#000" />
</TableRow>
<TableRow>
<TextView
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="10dp"
Page No: 12 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:layout_marginTop="20dp"
android:text="@string/password"
android:textColor="#fff"
android:textSize="16sp" />
<EditText
android:id="@+id/password"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:background="#fff"
android:hint="@string/password"
android:padding="5dp"
android:textColor="#000" />
</TableRow>
<TableRow android:layout_marginTop="20dp">
<Button
android:id="@+id/loginBtn"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_span="2"
android:background="#0ff"
android:text="@string/login"
android:textColor="#000"
android:textSize="20sp"
android:textStyle="bold" />
</TableRow>
</TableLayout>
Page No: 13 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
d) Develop an application to display analog Time Picker. Also display the 4M
selected time. (Write only . java file)
Ans MainActivity.java Code for display
time picker 2 M and
import android.os.Bundle;
display time 2 M
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
public class MainActivity extends AppCompatActivity {
TextView textview1;
TimePicker timepicker;
Button changetime;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textview1=(TextView)findViewById(R.id.textView1);
timepicker=(TimePicker)findViewById(R.id.timePicker);
//Uncomment the below line of code for 24 hour view
timepicker.setIs24HourView(true);
changetime=(Button)findViewById(R.id.button1);
textview1.setText(getCurrentTime());
changetime.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
textview1.setText(getCurrentTime());
}
});
Page No: 14 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
}
public String getCurrentTime(){
String currentTime="Current Time:
"+timepicker.getCurrentHour()+":"+timepicker.getCurrentMinute();
return currentTime;
}
}
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 A single instance of JVM is shared with
device can run multiple instances of the multiple applications.
VM efficiently. Applications are given
their own instance
There is a constant pool for every It has a constant pool for every class.
application.
An The android project contains different types of app modules, source code files, and 1 M for each
s resource files. directory
Following are the components/ modules of android directory:
1) Manifests Folder
Manifests folder contains AndroidManifest.xml for creating our android
application. This file contains information about our application such as the
Page No: 15 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Android version, metadata, states package for Kotlin file, and other
application components. It acts as an intermediator between android OS and
our application.
2) Java folder
The Java folder contains all the java source code (.java) files that we create
during the app development, including other Test files.
res/drawable folder
It contains the different types of images used for the development of
the application. We need to add all the images in a drawable folder for
the application development.
res/layout folder
The layout folder contains all XML layout files which we used to
define the user interface of our application. It contains the
activity_main.xml file.
res/mipmap folder
This folder contains launcher.xml files to define icons that are used to
show on the home screen. It contains different density types of icons
depending upon the size of the device such as hdpi, mdpi, xhdpi.
res/values folder
Values folder contains a number of XML files like strings,
dimensions, colors, and style definitions. One of the most important
files is the strings.xml file which contains the resources.
Ans [Consider any relevant example of Radio Button and in XML file, consider XML Code 2 M,
minimum attributes] Java Code 2 M
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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
Page No: 16 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="30dp"
tools:context=".frame">
<TextView android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Radio Button"
android:textSize="20dp"
android:gravity="center"
android:textColor="#f00"/>
<RadioGroup android:id="@+id/group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/text1">
<RadioButton android:id="@+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"/>
<RadioButton
android:id="@+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/male"
android:text="Female"/>
</RadioGroup>
<Button android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/group"
android:layout_marginTop="99dp"
android:layout_centerHorizontal="true"
android:text="Submit" />
</RelativeLayout>
Java File:
package com.example.ifcdiv;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
Page No: 17 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
import android.widget.RadioButton;
import android.widget.Toast;
RadioButton male,female;
Button b1;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_frame);
male=findViewById(R.id.male);
female=findViewById(R.id.female);
b1=findViewById(R.id.submit);
b1.setOnClickListener(new View.OnClickListener()
@Override
Page No: 18 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
d) Develop an application to send and receive SMS. (Write only Java and 4M
permission tag in manifest file)
MainActivity.java
(Cosidering appropriate layout file with 2 edit text boxes namely for phone
number,
message and a button for sending sms)
package com.example.testreceivesms;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.Manifest;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
Page No: 19 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
SmsReceiver sms= new SmsReceiver();
EditText et1,et2;
Button b1;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1=findViewById(R.id.etPhno);
et2=findViewById(R.id.etmsg);
b1=findViewById(R.id.btnSms);
if(ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.SEND_SMS)!=
PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(MainActivity.this,new
String[]{Manifest.permission.SEND_SMS},100);
}
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
String phno= et1.getText().toString();
String msg=et2.getText().toString();
SmsManager smsManager= SmsManager.getDefault();
smsManager.sendTextMessage(phno,null,msg,null,null);
Page No: 20 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Toast.makeText(MainActivity.this,"Sms sent successfully",
Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
Toast.makeText(MainActivity.this,"Sms failed to send... try again",
Toast.LENGTH_LONG).show();
}
}
});
}
@Override
protected void onStart() {
super.onStart();
IntentFilter filter=new
IntentFilter("android.provider.Telephony.SMS_RECEIVED");
registerReceiver(sms,filter);
}
@Override
protected void onStop() {
super.onStop();
unregisterReceiver(sms);
}
}
SmsReceiver.java
package com.example.testreceivesms;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
Page No: 21 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;
public class SmsReceiver extends BroadcastReceiver {
SmsReceiver(){}
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
// Retrieve the SMS Messages received
Object[] sms = (Object[]) bundle.get("pdus");
// For every SMS message received
for (int i=0; i < sms.length; i++) {
// Convert Object array
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]);
String phone = smsMessage.getOriginatingAddress();
String message = smsMessage.getMessageBody().toString();
Toast.makeText(context, “Received from “+ phone + ": " + message,
Toast.LENGTH_SHORT).show();
}
}
}
}
Page No: 22 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
onCreate (): Called then the activity is created. Used to initialize the activity, for
example create the user interface.
onStart ():called when activity is becoming visible to the user.
onResume (): Called if the activity get visible again and the user starts interacting
with the activity again. Used to initialize fields, register listeners, bind
to services, etc.
onPause (): Called once another activity gets into the foreground. Always called
before the activity is not visible anymore. Used to release resources or save
application data. For example you unregister listeners, intent receivers, unbind from
services or remove system service listeners.
onStop (): Called once the activity is no longer visible. Time or CPU intensive
shutdown operations, such as writing information to a database should be down in
the onStop() method. This method is guaranteed to be called as of API 11.
onDestroy (): called before the activity is destroyed.
Page No: 23 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and Any appropriate UI
fill all required details to create a new project. controls and layout
with correct
Step 2 − Add the following code to res/layout/activity_main.xml. activity_main.xml
file-3 M
<?xml version="1.0" encoding="utf-8"?>
MainActivity.java
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
file-3 M
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp">
<TextView
android:id="@+id/textResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:background="#008080"
android:padding="5dp"
android:text="Code4Example"
android:textColor="#fff"
android:textSize="24sp"
android:textStyle="bold" />
<EditText
android:id="@+id/editNum1"
android:inputType="number"
android:layout_width="match_parent"
Page No: 24 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<EditText
android:id="@+id/editNum2"
android:inputType="number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editNum1"
android:layout_centerInParent="true" />
<GridLayout
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_below="@+id/editNum2"
android:columnCount="2"
android:rowCount="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="1dp"
android:onClick="btnAdd"
android:text="+" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
Page No: 25 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:layout_margin="1dp"
android:onClick="btnSub"
android:text="-" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="1dp"
android:onClick="btnMul"
android:text="*" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="1dp"
android:onClick="btnDiv"
android:text="/" />
</GridLayout>
</RelativeLayout>
Page No: 26 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editNum1= findViewById(R.id.editNum1);
editNum2= findViewById(R.id.editNum2);
textResult= findViewById(R.id.textResult);
}
public void btnAdd(View view){
double num1 = Double.parseDouble(editNum1.getText().toString());
double num2 = Double.parseDouble(editNum2.getText().toString());
double result = num1 + num2;
textResult.setText(Double.toString(result));
}
public void btnSub(View view){
double num1 = Double.parseDouble(editNum1.getText().toString());
double num2 = Double.parseDouble(editNum2.getText().toString());
double result = num1 - num2;
textResult.setText(Double.toString(result));
}
public void btnMul(View view){
double num1 = Double.parseDouble(editNum1.getText().toString());
double num2 = Double.parseDouble(editNum2.getText().toString());
double result = num1 * num2;
textResult.setText(Double.toString(result));
}
public void btnDiv(View view){
Page No: 27 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
double num1 = Double.parseDouble(editNum1.getText().toString());
double num2 = Double.parseDouble(editNum2.getText().toString());
double result = num1 / num2;
textResult.setText(Double.toString(result));
}
}
Output:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Page No: 29 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
</intent-filter>
</activity>
</application>
</manifest>
code of MapsActivity.java :
package example.com.mapexample;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
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;
public class MapsActivity extends FragmentActivity implements OnMapReadyC
allback{
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used
.
Page No: 30 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sy
dney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
android:paddingTop="@dimen/activity_vertical_margin"
Page No: 31 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:transitionGroup="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:layout_below="@+id/textview"
android:layout_centerHorizontal="true"
android:textColor="#ff7aff24"
android:textSize="35dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_below="@+id/textView"
android:layout_marginTop="46dp"
android:text="thanks"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#ff7aff10"
android:textColorHint="#ffff23d1" />
<Button
android:layout_width="wrap_content"
Page No: 32 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:layout_height="wrap_content"
android:id="@+id/button"
android:layout_below="@+id/editText"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp"
android:textSize="15dp" />
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
<TextView
android:padding="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextToSpeechDemo"
android:gravity="center"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="@android:color/white"/>
</LinearLayout>
Page No: 33 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Code of MainActivity.java.
package com.example.texttospeech.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.util.Locale;
import android.widget.Toast;
TextToSpeech t1;
EditText ed1;
Button b1;
@Override
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CU
STOM);
getSupportActionBar().setCustomView(R.layout.toolbar_title_layout);
setContentView(R.layout.activity_main);
ed1=(EditText)findViewById(R.id.editText);
b1=(Button)findViewById(R.id.button);
@Override
Page No: 34 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
if(status != TextToSpeech.ERROR) {
t1.setLanguage(Locale.UK);
});
b1.setOnClickListener(new View.OnClickListener() {
@Override
Toast.makeText(getApplicationContext(),
toSpeak,Toast.LENGTH_SHORT).show();
});
if(t1 !=null){
t1.stop();
t1.shutdown();
super.onPause();
Page No: 35 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans activity_update_emp.xml file activity_update
_emp.xmlfile-1 M
<?xml version="1.0" encoding="utf-8"?>
DBHandler.java
<LinearLayout file-2 M
xmlns:android="http://schemas.android.com/apk/res/android" empRVAdapter.java
file-1 M
xmlns:tools="http://schemas.android.com/tools"
Update java file- 2
android:layout_width="match_parent"
M
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<!--Edit text to enter employee name-->
<EditText
android:id="@+id/idEdtEmpName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Enter Employee Name" />
<!--edit text for employee salary-->
<EditText
android:id="@+id/idEdtEmpSalary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Enter Employee Salary" />
Page No: 36 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Add Employee"
android:textAllCaps="false" />
</LinearLayout>
DBHandler.java file
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DBHandler extends SQLiteOpenHelper {
// creating a constant variables for our database.
// below variable is for our database name.
private static final String DB_NAME = "empdb";
Page No: 37 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
// below variable is for our employee salary column.
private static final String TRACKS_COL = "emp_salary";
Page No: 38 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
// our sqlite database and calling writable method
// as we are writing data in our database.
SQLiteDatabase db = this.getWritableDatabase();
// on below line we are creating a
// variable for content values.
ContentValues values = new ContentValues();
Page No: 39 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
empRVAdapter.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;
public class MainActivity extends AppCompatActivity {
// creating variables for our edittext, button and dbhandler
private EditText empNameEdt, empSalaryEdt;
private Button addempBtn;
private DBHandler dbHandler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// initializing all our variables.
empNameEdt = findViewById(R.id.idEdtempName);
empSalaryEdt = findViewById(R.id.idEdtempSalary);
addempBtn = findViewById(R.id.idBtnAddemp);
// creating a new dbhandler class
// and passing our context to it.
dbHandler = new DBHandler(MainActivity.this);
// below line is to add on click listener for our add emp button.
addCourseBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Page No: 40 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
// below line is to get data from all edit text fields.
String empName = empNameEdt.getText().toString();
String empSalary = empSalaryEdt.getText().toString();
// validating if the text fields are empty or not.
if (empName.isEmpty() && empSalary.isEmpty() &&) {
Toast.makeText(MainActivity.this, "Please enter all the data..",
Toast.LENGTH_SHORT).show();
return;
}
// on below line we are calling a method to add new
// employee to sqlite data and pass all our values to it.
dbHandler.addNewemp(empName, empSalary);
Page No: 41 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
import androidx.appcompat.app.AppCompatActivity;
public class UpdateCourseActivity extends AppCompatActivity {
// variables for our edit text, button, strings and dbhandler class.
private EditText empNameEdt, empSalaryEdt;
private Button updateempBtn;
private DBHandler dbHandler;
String empName, empSalary;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_update_emp);
Page No: 42 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
empSalaryEdt.setText(empSalary);
// displaying a toast message that our employee database has been updated.
Toast.makeText(UpdateempActivity.this, "Employee Record Updated..",
Toast.LENGTH_SHORT).show();
Page No: 43 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
During the preparation step, you build a release version of your app.
Release the app to users.
During the release step, you publicize, sell, and distribute the release version
of your app, which users can download and install on their Android-powered
devices.
1)Preparing your app for release is a multistep process involving the following tasks:
2) Signing of Application
Application signing allows developers to identify the author of the
application and to update their application without creating complicated
interfaces and permissions.
Every application that is run on the Android platform must be signed by the
developer.
Page No: 44 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
1)App signing
All APKs must be signed with a certificate whose private key is held by their
developer. The certificate does not need to be signed by a certificate authority. It's
allowable, and typical, for Android apps to use self-signed certificates. The purpose
of certificates in Android is to distinguish app authors. This lets the system grant or
deny apps access to signature-level permissions and grant or deny an app's request to
be given the same Linux identity as another app.
Starting in Android 12 (API level 31), the knownCerts attribute for signature-level
permissions lets you refer to the digests of known signing certificates at declaration
time.
You can declare the knownCerts attribute and use the knownSigner flag in your
app's protectionLevel attribute for a particular signature-level permission. Then, the
system grants that permission to a requesting app if any signer in the requesting app's
signing lineage, including the current signer, matches one of the digests that's
declared with the permission in the knownCerts attribute.
The knownSigner flag lets devices and apps grant signature permissions to other
apps without having to sign the apps at the time of device manufacturing and
shipment.
At install time, Android gives each package a distinct Linux user ID. The identity
remains constant for the duration of the package's life on that device. On a different
device, the same package might have a different UID—what matters is that each
package has a distinct UID on a given device.
Because security enforcement happens at the process level, the code of any two
Page No: 45 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
packages can't normally run in the same process, since they need to run as different
Linux users.
Any data stored by an app is assigned that app's user ID and isn't normally accessible
to other packages.
For example, an app that needs to control which other apps can start one of its
activities can declare a permission for this operation as follows:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp" >
<permission
android:name="com.example.myapp.permission.DEADLY_ACTIVITY"
android:label="@string/permlab_deadlyActivity"
android:description="@string/permdesc_deadlyActivity"
android:permissionGroup="android.permission-group.COST_MONEY"
android:protectionLevel="dangerous" />
...
</manifest>
c) Develop a program to TURN ON and OFF bluetooth. 6M
Write .java file and permission tags.
Ans Code of MainActivity.java AndroidManifest.x
ml file-3 M
package com.example.bluetooth.myapplication;
MainActivity.java
import android.app.Activity; file-3 M
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 java.util.ArrayList;
import java.util.Set;
Page No: 46 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.button);
b2=(Button)findViewById(R.id.button2);
b3=(Button)findViewById(R.id.button3);
b4=(Button)findViewById(R.id.button4);
BA = BluetoothAdapter.getDefaultAdapter();
lv = (ListView)findViewById(R.id.listView);
}
Page No: 47 | 48
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
final ArrayAdapter adapter = new
ArrayAdapter(this,android.R.layout.simple_list_item_1, list);
lv.setAdapter(adapter);
}
}
Permission Tags
AndroidManifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bluetooth.myapplication" >
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Page No: 48 | 48