Mad 22617 Winter 2023 Model Answer
Mad 22617 Winter 2023 Model Answer
Page No: 1 | 48
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
Attribute Description
Page No: 3 | 48
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
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
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
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
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
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
Page No: 11 | 48
Page No: 12 | 48
Page No: 13 | 48
Page No: 14 | 48
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
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
<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
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
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
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
});
}
@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
Page No: 22 | 48
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
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
Page No: 25 | 48
Page No: 26 | 48
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
<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
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
android:paddingTop="@dimen/activity_vertical_margin"
Page No: 31 | 48
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
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
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
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
Page No: 36 | 48
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
Page No: 38 | 48
Page No: 39 | 48
// 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
Page No: 41 | 48
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_update_emp);
Page No: 42 | 48
// 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
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
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
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
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
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