Summer 2023 Finall11 - Removed
Summer 2023 Finall11 - Removed
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_______
SUMMER – 2023 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Ans Android Fragment is the part of activity, it is also known as sub-activity. There can be more Explanation
2M
than one fragment in an activity.
Fragments were added in Honeycomb version of Android i.e API version 11. We can add,
replace or remove Fragment’s in an Activity while the activity is running.
Fragment can be used in multiple activities.
We can also combine multiple Fragments in a single activity to build a multi-plane UI.
We can only show a single Activity on the screen at one given point of time so we were not
able to divide the screen and control different parts separately. With the help of Fragment’s
we can divide the screens in different parts and controls different parts separately
In Android, you can use SmsManager API or devices Built-in SMS application to 4 points
send SMS's
2M
Android SMS is stored in PDU (protocol description unit) format
SmsManager class takes care of sending the SMS message.
We just need to get an instance of it and send the SMS message.
We need to add permission to SEND_SMS in the Android manifest file.
Ans The android platform supports three broad categories of sensors. 2 M for List
Motion Sensors
These are used to measure acceleration forces and rotational forces along with three
axes.
Environmental sensors
These are used to measure the environmental changes such as temperature, humidity etc.
Position sensors
Android was developed by the Open Handset Alliance, led by Google, and other companies.
OHA
The Open Handset Alliance (OHA) is a business alliance that was created for the
purpose of developing open mobile device standards.
The OHA has approximately 80 member companies, including HTC, Dell, Intel,
Motorola, Qualcomm and Google.
Importance of OHA
Lower overall handset costs: Opens up resources, which facilitates the focus on
creating innovative applications, solutions and services.
Developer-friendly environment: In the open-source community, developers share
notes to expedite application development.
Post-development: Provides an ideal channel for application marketing and
distribution.
b) Explain Dalvik Virtual Machine and state its importance. (Pt 1 ka ans hai) 4M
Ans Explain 2
M
Importance
2M
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_______
1. Optimization for Mobile Devices: Dalvik is optimized to run multiple instances efficiently,
which is ideal for mobile environments.
2. Efficient Memory Management: Dalvik uses a register-based architecture which makes it
more memory-efficient compared to traditional stack-based virtual machines like the JVM.
3. Battery Efficiency: It consumes less power, which helps in improving battery performance.
4. Performance: Dalvik provides good performance in terms of speed and execution of Android
applications.
5. Multi-tasking Support: Supports running multiple applications simultaneously without
significant performance loss.
6. Conversion of Java Bytecode: Java .class files are converted into .dex (Dalvik
Executable) files, which are smaller and optimized for Android.
The Java source code is compiled by the javac compiler into .class files.
The dx tool then converts all .class files into a single .dex file.
The Android Asset Packaging Tool (aapt) packages these .dex files with other resources
into an .apk file.
This .apk file runs on the Dalvik Virtual Machine.
Click on the API key option to generate your API key. After clicking on this option your API
key will be generated
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_______
d) Explain multimedia framework in android. 4M
Ans Proper
Explanation
4 marks
Multimedia Framework
Java Class of Media
This is the top layer where media-related classes like MediaPlayer and MediaRecorder are
defined for Android apps to use.
Native C Library
This includes core libraries like libmedia, libaudioclient, libmediaservice, etc., written
in C/C++. These handle the real processing of media tasks like playing or recording
audio/video.
Media Server
The Media Server is a system service that handles all media-related requests like playing or
recording media. It communicates with the native library through Android’s Binder IPC.
PV Player / PV Author
These are part of the OpenCore engine used internally for handling playback (PVPlayer) and
content creation (PVAuthor).
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_______
3.a. Describe various installation steps of android studio and its environment. steps 4
marks
Step 3: After the downloading has finished, open the file from downloads and will prompt the
following dialog box. Click on next. In the next prompt, it’ll ask for a path for installation.
Choose a path and hit next.
Step 4: It will start the installation, and once it is completed, it will be like the image shown
below.
Step 5: Once “Finish” is clicked, it will ask whether the previous settings need to be imported
[if the android studio had been installed earlier], or not. It is better to choose the ‘Don’t import
Settings option’. Click the OK button.
Step 6: This will start the Android Studio. Meanwhile, it will be finding the available SDK
components.
Step 7: After it has found the SDK components, it will redirect to the Welcome dialog box
Choose Standard and click on Next.
Step 8: Now it is time to download the SDK components. Click on Finish. Components begin
to download let it complete. The Android Studio has been successfully configured. Now
it’s time to launch and build apps. Click on the Finish button to launch it.
Step 9: Click on Start a new Android Studio project to build a new app.
3 android:gravity
Specifies the gravity within each cell. Possible values are top, bottom,
left, right, center, center_vertical, center_horizontal etc.
4 android:horizontalSpacing
Defines the default horizontal spacing between columns. This could be
in px, dp, sp, in, or mm.
5 android:numColumns
Defines how many columns to show. May be an integer value, such as
"100" or auto_fit which means display as many columns as possible to
fill the available space.
6 android:stretchMode
Defines how columns should stretch to fill the available empty space, if
any. This must be either of the values −
none − Stretching is disabled.
spacingWidth − The spacing between each column is stretched.
columnWidth − Each column is stretched equally.
spacingWidthUniform − The spacing between each column is
uniformly stretched..
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_______
7 android:verticalSpacing
Defines the default vertical spacing between rows. This could be in px,
dp, sp, in, or mm.
activity_main.xml (2 Marks)
xml
CopyEdit
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp" />
MainActivity.java (3 Marks)
java
CopyEdit
package com.example.gridviewdemo;
import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
Ans Text to Speech converts the text written on the screen to speech like you have written “Hello Proper
World” on the screen and when you press the button it will speak “Hello World”. Text-to- explanation
speech is commonly used as an accessibility feature to help people who have trouble reading
on-screen text, but it’s also convenient for those who want to be read too. This feature has 4 marks
come out to be a very common and useful feature for the users.
In android, by using TextToSpeech class we can easily convert our text into voice and it
supports different types of speaking languages. We can choose the speaking language based
on our requirements in the android application.
The android TextToSpeech instance can only be used to synthesize text once it has completed
its initialization so implement TextToSpeech.
OnInitListener to notify the completion of initialization. During the initialization, we can set
the audio pitch rate, audio speed, type of language to speak, etc. based on our requirements.
java
package com.example.ttsdemo;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Locale;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
speakBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tts.speak("thanks", TextToSpeech.QUEUE_FLUSH, null, null);
}
});
}
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_______
@Override
protected void onDestroy() {
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
}
Xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<Button
android:id="@+id/speakBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CLICK TO SPEAK 'thanks'" />
</LinearLayout>
Java Folder
Drawable Folder
Layout Folder
Mipmap Folder
Values Folder
4. Gradle Scripts
📁 Manifests Folder
The Manifests folder contains the AndroidManifest.xml file which defines essential
information about the application. This includes the Android version, app name, permissions,
and components like activities, services, and broadcast receivers. It acts as a bridge between
the Android OS and the application, helping the system understand how to run and manage the
app.
📁 Java Folder
The Java folder holds all the Java source code files used in the app, including the main activity
file like MainActivity.java and other supporting or test files. When a project is created, this
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_______
folder is automatically generated. It is where the app’s logic and functionality are implemented
using Java.
🔹 res/drawable folder
This folder stores all image files used in the application, such as .png, .jpg, or vector files.
These images are used in layouts, buttons, icons, and other design elements.
🔹 res/layout folder
The layout folder contains XML files that define the structure and design of the app’s user
interface. Files like activity_main.xml are used to arrange widgets like buttons, text fields,
and images on the screen.
🔹 res/mipmap folder
This folder is used to store launcher icons for the app. It includes different versions of the app
icon for different screen densities like mdpi, hdpi, xhdpi, etc., ensuring that the app icon
looks good on all devices.
🔹 res/values folder
The values folder includes XML files that store strings, colors, dimensions, and style
definitions used in the app. One important file here is strings.xml, which contains all the
text used in the app. This helps in organizing content and supporting multiple languages.
⚙️ Gradle Scripts
Gradle is a build automation tool that manages how the app is compiled and built. The Gradle
Scripts section contains two important files: build.gradle (Project level) and
build.gradle (App level). These files define dependencies, plugins, and other settings
required to build, test, and run the app successfully.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_______
b) Develop an android application for Date and Time Picker.
✅ activity_main.xml (2 Marks)
xml
CopyEdit
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="16dp">
<Button
android:id="@+id/btnDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Date" />
<Button
android:id="@+id/btnTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Time"
android:layout_marginTop="10dp" />
</LinearLayout>
✅ MainActivity.java
java
CopyEdit
package com.example.datetimepicker;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import java.util.Calendar;
btnDate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Calendar c = Calendar.getInstance();
DatePickerDialog dp = new
DatePickerDialog(MainActivity.this,
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_______
null, c.get(Calendar.YEAR), c.get(Calendar.MONTH),
c.get(Calendar.DAY_OF_MONTH));
dp.show();
}
});
btnTime.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Calendar c = Calendar.getInstance();
TimePickerDialog tp = new
TimePickerDialog(MainActivity.this,
null, c.get(Calendar.HOUR_OF_DAY),
c.get(Calendar.MINUTE), false);
tp.show();
}
});
}
}
c) Explain property animation method to animate the properties of view object with example. 4M
A property animation changes a property's (a field in an object) value over a specified length
of time. To animate something, you specify the object property that you want to animate, such
as an object's position on the screen, how long you want to animate it for, and what values you
want to animate between.The property animation system lets you define the following
characteristics of an animation:
Duration: You can specify the duration of an animation. The default length is 300 ms.
A property animation changes a property's (a field in an object) value over a specified length
of time. To animate something, you specify the object property that you want to animate, such
as an object's position on the screen, how long you want to animate it for, and what values
you want to animate between.The property animation system lets you define the following
characteristics of an animation:
Time interpolation: You can specify how the values for the property are calculated as a
unction of the animation's current elapsed time.
Repeat count and behavior: You can specify whether or not to have an animation repeat when it
reaches the end of a duration and how many times to repeat the animation. You can also specify
whether you want the animation to play back in reverse. Setting it to reverse plays the animation
forwards then backwards repeatedly, until the number of repeats is reached.
Animator sets: You can group animations into logical sets that play together or sequentially or after
specified delays.
Frame refresh delay: You can specify how often to refresh frames of your animation. The default is
set to refresh every 10 ms, but the speed in which your application can refresh frames is ultimately
dependent on how busy the system is overall and how fast the system can service the underlying
timer.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_______
🔹 activity_main.xml (2 Marks)
xml
CopyEdit
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btnAnimate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Move"
android:layout_centerInParent="true"/>
</RelativeLayout>
🔹 MainActivity.java (3 Marks)
CopyEdit
package com.example.animationdemo;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
Button btnAnimate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnAnimate = findViewById(R.id.btnAnimate);
ObjectAnimator anim = ObjectAnimator.ofFloat(btnAnimate,
"translationX", 0f, 300f);
anim.setDuration(1000);
anim.start();
}
}
✅ activity_main.xml
xml
CopyEdit
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_______
android:src="@drawable/my_image" <!-- Put any image named
my_image.png in drawable -->
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerInParent="true"
android:scaleType="centerCrop" />
</RelativeLayout>
✅ MainActivity.java
java
CopyEdit
import android.os.Bundle;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
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.
package com.example.maplocation;
import android.os.Bundle;
import androidx.fragment.app.FragmentActivity;
import com.google.android.gms.maps.*;
import com.google.android.gms.maps.model.*;
import com.google.android.gms.location.*;
import android.Manifest;
import android.content.pm.PackageManager;
import androidx.core.app.ActivityCompat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment mf = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map);
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_______
mf.getMapAsync(this);
}
manifest
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
activity_main.xml
xml
CopyEdit
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/etName"
android:hint="Employee Name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/etEmail"
android:hint="Email"
android:inputType="textEmailAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/etPhone"
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_______
android:hint="Phone Number"
android:inputType="phone"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/etDept"
android:hint="Department"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btnSubmit"
android:text="Register"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
✅ Minimal activity_main.xml
xml
CopyEdit
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:orientation="vertical">
<EditText android:id="@+id/editname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"/>
<EditText android:id="@+id/editclass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Class"/>
<EditText android:id="@+id/editfeedback"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Feedback"/>
<Button android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit"/>
</LinearLayout>
✅ Minimal DBHandler.java
java
CopyEdit
package com.example.feedback;
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_______
import android.content.Context;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;
✅ Minimal MainActivity.java
java
CopyEdit
package com.example.feedback;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import android.database.sqlite.*;
name = findViewById(R.id.editname);
stdClass = findViewById(R.id.editclass);
feedback = findViewById(R.id.editfeedback);
Button btn = findViewById(R.id.button);
db = new DBHandler(this).getWritableDatabase();
btn.setOnClickListener(v -> {
db.execSQL("INSERT INTO Feedback VALUES('" +
name.getText() + "','" +
stdClass.getText() + "','" +
feedback.getText() + "')");
Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show();
name.setText(""); stdClass.setText(""); feedback.setText("");
});
}
}
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.database.sqlite.SQLiteDatabase;
name = findViewById(R.id.editname);
stdClass = findViewById(R.id.editclass);
feedback = findViewById(R.id.editfeedback);
btn = findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String n = name.getText().toString();
String c = stdClass.getText().toString();
String f = feedback.getText().toString();
Ans Geocoding is the process of transforming a street address or other description of a (Geocoding ,
location into a (latitude, longitude) coordinate. Reverse
Geocoding
Reverse geocoding is the process of transforming a (latitude, longitude) coordinate into a Explanation :
(partial) address. 3 M,
Example :
The amount of detail in a reverse geocoded location description may vary, for example 3M)
one might contain the full street address of the closest building, while another might
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_______
contain only a city name and postal code.
The Geocoder class is used for handling geocoding and reverse geocoding.
✅ activity_main.xml (2 Marks)
<EditText
android:id="@+id/editAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Address" />
<Button
android:id="@+id/btnGeocode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Get LatLng" />
<EditText
android:id="@+id/editLat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Latitude" />
<EditText
android:id="@+id/editLng"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Longitude" />
<Button
android:id="@+id/btnReverse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Get Address" />
<TextView
android:id="@+id/textResult"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_______
✅ MainActivity.java (3 Marks)
java
CopyEdit
package com.example.geocodetest;
import android.app.Activity;
import android.os.Bundle;
import android.location.Geocoder;
import android.location.Address;
import android.view.View;
import android.widget.*;
import java.util.*;
editAddress = findViewById(R.id.editAddress);
editLat = findViewById(R.id.editLat);
editLng = findViewById(R.id.editLng);
textResult = findViewById(R.id.textResult);
btnGeocode = findViewById(R.id.btnGeocode);
btnReverse = findViewById(R.id.btnReverse);
btnGeocode.setOnClickListener(v -> {
String addr = editAddress.getText().toString();
Geocoder geocoder = new Geocoder(MainActivity.this);
List<Address> list = geocoder.getFromLocationName(addr, 1);
if (!list.isEmpty()) {
double lat = list.get(0).getLatitude();
double lng = list.get(0).getLongitude();
textResult.setText("Lat: " + lat + ", Lng: " + lng);
}
});
btnReverse.setOnClickListener(v -> {
double lat = Double.parseDouble(editLat.getText().toString());
double lng = Double.parseDouble(editLng.getText().toString());
Geocoder geocoder = new Geocoder(MainActivity.this);
List<Address> list = geocoder.getFromLocation(lat, lng, 1);
if (!list.isEmpty()) {
String address = list.get(0).getAddressLine(0);
textResult.setText("Address: " + address);
}
});
✅ activity_main.xml (2 Marks)
xml
CopyEdit
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
✅ MainActivity.java (3 Marks)
java
CopyEdit
package com.example.bluetoothlist;
import android.app.Activity;
import android.os.Bundle;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.widget.ListView;
import android.widget.ArrayAdapter;
import java.util.ArrayList;
import java.util.Set;
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = findViewById(R.id.listView);
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
🔹 activity_main.xml (2 Marks)
xml
CopyEdit
<?xml version="1.0" encoding="utf-8"?>
<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="20dp">
<EditText
android:id="@+id/etNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Number"
android:inputType="phone" />
<EditText
android:id="@+id/etMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Message" />
<Button
android:id="@+id/btnSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send SMS" />
</LinearLayout>
🔹 MainActivity.java (3 Marks)
java
CopyEdit
package com.example.sendsms;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
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);
etPhone = findViewById(R.id.etPhone);
etMessage = findViewById(R.id.etMessage);
btnSend = findViewById(R.id.btnSend);
ActivityCompat.requestPermissions(this, new
String[]{Manifest.permission.SEND_SMS}, 1);
btnSend.setOnClickListener(v -> {
String phone = etPhone.getText().toString();
String msg = etMessage.getText().toString();
SmsManager.getDefault().sendTextMessage(phone, null, msg, null,
null);
Toast.makeText(this, "SMS Sent", Toast.LENGTH_SHORT).show();
});
}
}
🔹 SMSReceiver.java
java
package com.example.smsapp;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;
🔹 Minimal AndroidManifest.xml
xml
CopyEdit
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<receiver
android:name=".SMSReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
c) Explain how linear and frame layout is used to design an android application with 6M
suitable example.
Ans LinearLayout (2 M : For
each layout
• Android LinearLayout is a view group that aligns all children in either vertically explanation,
or horizontally. 1 M for
each layout
Linear layout in Android allow us to arrange components horizontally in a single
example)
column or
vertically in a single row.
• Vertically or horizontally direction depends on attribute android: orientation.
• Linear layout is simple and easy to use, it creates a scroll bar if the length of the
window exceeds the length of the screen.
• Linear Layout are one of the simplest and common type of layouts used by
Android developers to keep controls within their interfaces. The linear layout
works as much as its name implies, it organizes the controls either a vertical or
horizontal pattern.
• When the layout’s orientation is set to vertical, all child controls within
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_______
organized in a single column, and when the layout’s orientation is set to
horizontal, all child controls within in single row.
Example
Frame Layout
• Frame Layout is designed to block out an area on the screen to display a single item.
Generally, FrameLayout should be used to hold a single child view, because it can be
difficult to organize child views in a way that's scalable to different screen sizes without
the children overlapping each other.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_______
• Frame layouts are one of the simplest layout types used to organize controls within the
user interface of an Android application. The purpose of FrameLayout is to allocate an
area of screen.
• Frame layouts are one of the most efficient types of layouts used by Android developers
to organize view controls. They are used less often than some other layouts, simply
because they are generally used to display only one view, or views which overlap.
• The frame layout is often used as a container layout, as it generally only has a single child
view (often another layout, used to organize more than one view).
Example