0% found this document useful (0 votes)
14 views42 pages

HX IAb 2 BM IU

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views42 pages

HX IAb 2 BM IU

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

Here are answers for the 2-mark questions from the document:

1. **List all tools and software required for developing an Android application**: Tools include Android Studio, JDK (Java Development Kit),
Android SDK, and an emulator or a physical device for testing.

2. **Define emulator**: An emulator is a software that replicates the hardware and software environment of an Android device on a computer,
allowing developers to test their applications without a physical device.

3. **List any four attributes of layout**: Four common attributes are `layout_width`, `layout_height`, `padding`, and `margin`.

4. **Define Geocoding and Reverse Geocoding**: Geocoding is the process of converting an address into geographic coordinates, while reverse
geocoding converts geographic coordinates into a readable address.

5. **State intent. List types of intent**: Intent is a messaging object used to request an action from another app component. Types include
implicit and explicit intents.

6. **Difference between toggle button and radio button**: A toggle button allows switching between two states (on/off), whereas a radio button
allows selection among multiple options, typically used in groups where only one option can be selected at a time.
7. **Define: i) Fragment ii) Broadcast receiver**: A Fragment is a reusable component of an activity's UI, while a Broadcast receiver listens for
system-wide broadcast announcements.

8. **State Android Ecosystem**: The Android ecosystem includes the Android OS, Google Play Store, developer tools, and a wide range of
hardware devices running Android.

9. **List various layouts used in Android UI design**: Layouts include LinearLayout, RelativeLayout, ConstraintLayout, FrameLayout, and
TableLayout.

10. **Name any four attributes of EditText control**: Common attributes are `text`, `hint`, `inputType`, and `maxLength`.

11. **State the use of fragments in Android App development**: Fragments allow modularizing UI components, facilitating flexible and dynamic
UI design within an activity.

12. **Define SMS service in Android application development**: SMS service enables sending and receiving text messages in Android
applications using APIs provided by the Android framework.

13. **List different types of sensors used in Android**: Types include accelerometer, gyroscope, proximity sensor, and light sensor.
14. **List any four features of Android operating system**: Features include multitasking, rich application framework, integrated web browser,
and media support.

15. **Define Dalvik Virtual Machine (DVM)**: DVM is a process virtual machine in Android OS that executes applications written for Android by
converting Java bytecode into a format optimized for mobile devices.

16. **List any four folders from the directory structure of Android project and elaborate in one line**:

- `src`: Contains the Java source code files.

- `res`: Stores resources like layouts, strings, and images.

- `manifest`: Holds the AndroidManifest.xml file with app metadata.

- `gradle`: Contains configuration files for project build settings.

17. **List any four attributes of checkbox**: Attributes include `text`, `checked`, `gravity`, and `textColor`.

18. **Draw diagram of activity life cycle**: (Requires a visual) Key stages include `onCreate()`, `onStart()`, `onResume()`, `onPause()`, `onStop()`,
`onRestart()`, and `onDestroy()`.

19. **State syntax to display built-in zoom control**: `webView.getSettings().setBuiltInZoomControls(true);`


20. **Name two classes used to play audio and video in Android**: `MediaPlayer` for audio and `VideoView` for video.

Here are answers for the 4-mark questions from the document:

1. **Explain relative layout with all its attributes**: RelativeLayout arranges UI elements relative to each other or to the parent container. Key
attributes include:

- `layout_alignParentTop`/`layout_alignParentBottom`: Aligns the view to the top/bottom of the parent.

- `layout_toLeftOf`/`layout_toRightOf`: Positions a view to the left or right of another view.

- `layout_centerHorizontal`/`layout_centerVertical`: Centers the view horizontally or vertically.

- `layout_alignBaseline`: Aligns the baseline of the view with another view's baseline.

2. **Explore all steps to install Android Studio and SDK**:

- **Download Android Studio** from the official website.

- **Install the software**, following the installation wizard.

- **Configure SDK location** and select the required SDK packages.

- **Create a new project** to verify that Android Studio and SDK are correctly set up.
3. **Explain the need of Android Operating System and describe any four features**:

- **Need**: Android OS provides an open-source, customizable platform for mobile applications, encouraging rapid innovation and diverse app
development.

- **Features**:

- **Multitasking**: Allows multiple apps to run simultaneously.

- **Rich Application Framework**: Supports complex and interactive apps.

- **Media Support**: Compatible with a wide range of media formats.

- **Integrated Web Browser**: Offers built-in browser functionality with web technologies support.

4. **Program to add "Hello World" marker at (10,10) coordinates**:

```java

MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(10, 10)).title("Hello World");

googleMap.addMarker(markerOptions);

```

5. **Describe service life cycle with its diagram**:

- **Life Cycle Stages**:


- `onCreate()`: Called when the service is first created.

- `onStartCommand()`: Called every time a client starts the service.

- `onBind()`: Binds the service to a component.

- `onUnbind()`: Unbinds the service.

- `onDestroy()`: Called when the service is destroyed.

- **Diagram**: Requires drawing the flow of these methods.

6. **Elaborate Android Security Model**: Android's security model is based on sandboxing, permissions, and user authentication:

- **Sandboxing**: Each app runs in its own user space, isolating it from others.

- **Permissions**: Apps must declare permissions in the manifest file for certain operations.

- **User Authentication**: Protects data with lock screens, fingerprint scanning, and facial recognition.

- **App Signing**: Ensures app integrity and helps manage updates.

7. **XML file to create login page using Table Layout**:

```xml

<TableLayout android:layout_width="match_parent" android:layout_height="wrap_content">

<TableRow>
<TextView android:text="Username:"/>

<EditText android:id="@+id/username" android:layout_width="wrap_content" />

</TableRow>

<TableRow>

<TextView android:text="Password:"/>

<EditText android:id="@+id/password" android:layout_width="wrap_content" android:inputType="textPassword"/>

</TableRow>

<TableRow>

<Button android:text="Login" android:layout_span="2"/>

</TableRow>

</TableLayout>

```

8. **Application to display analog Time Picker and selected time**:

```java

TimePicker timePicker = findViewById(R.id.timePicker);


timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {

@Override

public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {

String time = "Selected Time: " + hourOfDay + ":" + minute;

Toast.makeText(getApplicationContext(), time, Toast.LENGTH_SHORT).show();

});

```

9. **Differentiate between JVM and DVM**:

- **Architecture**: JVM runs Java bytecode, whereas DVM runs optimized bytecode (DEX format).

- **Purpose**: JVM is designed for desktops; DVM is optimized for Android mobile devices.

- **Memory Efficiency**: DVM is more memory efficient, suitable for resource-constrained devices.

- **Execution**: JVM uses a stack-based architecture; DVM uses a register-based architecture.

10. **Components of Android directory structure**:

- **Manifest**: Holds essential information like app permissions and activities.


- **Java**: Contains all Java source files.

- **res**: Contains resources like layout files, drawable images, and strings.

- **Gradle**: Contains build configuration files, managing project dependencies.

Let me know if you'd like more answers.

Continuing with answers for the next 4-mark questions:

11. **Develop an Android application using radio button**:

```xml

<!-- XML Layout -->

<RadioGroup android:id="@+id/radioGroup" android:layout_width="wrap_content" android:layout_height="wrap_content">

<RadioButton android:id="@+id/radio1" android:text="Option 1" />

<RadioButton android:id="@+id/radio2" android:text="Option 2" />

</RadioGroup>

<Button android:id="@+id/submitButton" android:text="Submit" />


<!-- Java Code -->

RadioGroup radioGroup = findViewById(R.id.radioGroup);

Button submitButton = findViewById(R.id.submitButton);

submitButton.setOnClickListener(v -> {

int selectedId = radioGroup.getCheckedRadioButtonId();

RadioButton selectedRadio = findViewById(selectedId);

Toast.makeText(getApplicationContext(), "Selected: " + selectedRadio.getText(), Toast.LENGTH_SHORT).show();

});

```

12. **Develop an application to send and receive SMS (Java and manifest)**:

```xml

<!-- Manifest permissions -->

<uses-permission android:name="android.permission.SEND_SMS"/>

<uses-permission android:name="android.permission.RECEIVE_SMS"/>

```
```java

// Java code for sending SMS

SmsManager smsManager = SmsManager.getDefault();

smsManager.sendTextMessage(phoneNumber, null, message, null, null);

// Java code for receiving SMS (BroadcastReceiver)

public class SmsReceiver extends BroadcastReceiver {

@Override

public void onReceive(Context context, Intent intent) {

Bundle bundle = intent.getExtras();

SmsMessage[] msgs = null;

if (bundle != null) {

Object[] pdus = (Object[]) bundle.get("pdus");

msgs = new SmsMessage[pdus.length];

for (int i = 0; i < msgs.length; i++) {

msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);


String msgBody = msgs[i].getMessageBody();

Toast.makeText(context, "Received: " + msgBody, Toast.LENGTH_SHORT).show();

```

13. **Draw and explain activity life cycle**:

- **Stages**:

- `onCreate()`: Initializes the activity.

- `onStart()`: Prepares the activity to become visible.

- `onResume()`: Makes the activity interactive.

- `onPause()`: Pauses user interactions.

- `onStop()`: Hides the activity from the user.

- `onDestroy()`: Cleans up resources when the activity is terminated.

- **Diagram**: (Typically shows transitions between each method in the life cycle.)
14. **Describe Android and the importance of OHA**:

- **Android** is an open-source mobile operating system for devices like smartphones and tablets, providing a platform for application
development.

- **Open Handset Alliance (OHA)**: A collaboration of tech companies aiming to develop open standards for mobile devices. OHA promotes
Android’s growth by fostering open-source contributions and enabling widespread adoption.

15. **Explain Dalvik Virtual Machine and its importance**:

- **DVM**: A specialized virtual machine for Android that optimizes memory and performance for mobile devices by executing Dalvik
bytecode.

- **Importance**: DVM ensures efficient app performance on resource-constrained devices and enables multiple apps to run smoothly by
allocating separate processes.

16. **Process of getting the map API Key**:

- **Step 1**: Go to the [Google Cloud Console](https://console.cloud.google.com/).

- **Step 2**: Create or select an existing project.

- **Step 3**: Enable the "Maps SDK for Android" API.

- **Step 4**: Navigate to "Credentials" and generate a new API key.


- **Step 5**: Restrict the key to avoid misuse and integrate it into the application.

17. **Explain multimedia framework in Android**:

- The multimedia framework supports audio, video, and image processing. Key components include:

- **MediaPlayer**: Plays audio and video files.

- **MediaRecorder**: Captures audio and video.

- **AudioManager**: Manages audio settings.

- **Camera**: Captures photos and video.

- Together, these components provide a comprehensive solution for multimedia handling in Android apps.

18. **Explain GridView with its attributes with a suitable example**:

- **GridView**: A layout that arranges items in a two-dimensional scrollable grid.

- **Attributes**:

- `numColumns`: Specifies the number of columns.

- `horizontalSpacing` & `verticalSpacing`: Defines spacing between items.

- `stretchMode`: Specifies how columns are stretched to fill space.

- **Example**:
```xml

<GridView android:id="@+id/gridView" android:layout_width="match_parent" android:layout_height="match_parent"


android:numColumns="3"/>

```

19. **Explain text-to-speech conversion technique in Android**:

- **TextToSpeech API** allows Android apps to convert text into spoken words.

- Steps:

- Initialize `TextToSpeech` object.

- Set the language and pitch.

- Use `speak()` method to convert text to speech.

- Example:

```java

TextToSpeech tts = new TextToSpeech(context, status -> {

if (status == TextToSpeech.SUCCESS) {

tts.setLanguage(Locale.US);

tts.speak("Hello World", TextToSpeech.QUEUE_FLUSH, null, null);


}

});

```

20. **Steps for deploying an Android application on Google Play Store**:

- **Step 1**: Create a Google Play Console account and pay the one-time registration fee.

- **Step 2**: Prepare your app by testing and signing it with a release key.

- **Step 3**: Create a store listing, including app details, screenshots, and promotional content.

- **Step 4**: Upload the APK or app bundle.

- **Step 5**: Set pricing and distribution details.

- **Step 6**: Submit the app for review and release it once approved.

Let me know if you'd like more detailed answers or additional questions.

Continuing with the next set of 4-mark question answers:

21. **Describe directory structure and its components**:


- **`src` Folder**: Contains all Java source code files.

- **`res` Folder**: Stores non-code resources like layouts (`layout`), images (`drawable`), and strings (`values`).

- **`AndroidManifest.xml`**: Specifies essential app information such as permissions, components, and app metadata.

- **`Gradle` Files**: Contains configuration files like `build.gradle` that manage dependencies and build settings.

22. **Develop an Android application for Date and Time Picker**:

```xml

<!-- XML Layout -->

<DatePicker android:id="@+id/datePicker" android:layout_width="wrap_content" android:layout_height="wrap_content" />

<TimePicker android:id="@+id/timePicker" android:layout_width="wrap_content" android:layout_height="wrap_content" />

```

```java

// Java Code

DatePicker datePicker = findViewById(R.id.datePicker);

TimePicker timePicker = findViewById(R.id.timePicker);


datePicker.init(2023, 10, 15, (view, year, monthOfYear, dayOfMonth) -> {

String date = "Selected Date: " + dayOfMonth + "/" + (monthOfYear + 1) + "/" + year;

Toast.makeText(getApplicationContext(), date, Toast.LENGTH_SHORT).show();

});

timePicker.setOnTimeChangedListener((view, hourOfDay, minute) -> {

String time = "Selected Time: " + hourOfDay + ":" + minute;

Toast.makeText(getApplicationContext(), time, Toast.LENGTH_SHORT).show();

});

```

23. **Explain property animation method to animate view object properties with example**:

- **Property Animation** in Android allows you to animate any property of a view.

- **Key Classes**: `ObjectAnimator`, `AnimatorSet`, and `ValueAnimator`.

- **Example**: Fading a view in and out.

```java
ObjectAnimator fadeOut = ObjectAnimator.ofFloat(view, "alpha", 1f, 0f);

fadeOut.setDuration(1000);

ObjectAnimator fadeIn = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f);

fadeIn.setDuration(1000);

AnimatorSet animatorSet = new AnimatorSet();

animatorSet.play(fadeIn).after(fadeOut);

animatorSet.start();

```

24. **Describe permissions required for Android application development**:

- Permissions ensure app security by restricting access to sensitive data.

- **Examples of Permissions**:

- **`INTERNET`**: Required for network operations.

- **`ACCESS_FINE_LOCATION`**: Needed for accessing precise location data.

- **`READ_CONTACTS`**: Allows reading contacts from the user’s device.

- **`CAMERA`**: Grants access to the device camera.


25. **Develop an Android application to show the current location of a user’s car**:

```xml

<!-- Manifest Permission -->

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

```

```java

// Java Code

FusedLocationProviderClient locationClient = LocationServices.getFusedLocationProviderClient(this);

locationClient.getLastLocation().addOnSuccessListener(location -> {

if (location != null) {

double latitude = location.getLatitude();

double longitude = location.getLongitude();

Toast.makeText(getApplicationContext(), "Car Location: " + latitude + ", " + longitude, Toast.LENGTH_SHORT).show();

}
});

```

26. **Describe Android architecture with a diagram**:

- **Layers**:

- **Applications**: User-facing apps like Contacts, Phone, and Browser.

- **Application Framework**: Provides APIs for apps to interact with hardware and system components.

- **Libraries and Android Runtime**: Includes core libraries and Dalvik VM, responsible for running apps.

- **Linux Kernel**: The foundation layer, handling device drivers and core system services.

- **Diagram**: Typically shows a layered architecture from the Linux Kernel up to Applications.

27. **Describe with example how to create a simple database in SQLite**:

```java

SQLiteDatabase db = openOrCreateDatabase("StudentDB", MODE_PRIVATE, null);

db.execSQL("CREATE TABLE IF NOT EXISTS students(id INTEGER PRIMARY KEY, name TEXT);");

db.execSQL("INSERT INTO students (name) VALUES ('John Doe');");

Cursor cursor = db.rawQuery("SELECT * FROM students", null);


while (cursor.moveToNext()) {

int id = cursor.getInt(0);

String name = cursor.getString(1);

Toast.makeText(getApplicationContext(), "ID: " + id + ", Name: " + name, Toast.LENGTH_SHORT).show();

```

28. **Syntax to create TextView and ImageButton with two attributes of each**:

- **TextView**:

```xml

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello" android:textSize="18sp" />

```

- **ImageButton**:

```xml

<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/image"


android:contentDescription="ImageButton" />

```
29. **Syntax for required class and methods for Geocoding**:

- **Geocoding Example**:

```java

Geocoder geocoder = new Geocoder(context, Locale.getDefault());

List<Address> addresses = geocoder.getFromLocationName("1600 Amphitheatre Parkway, CA", 1);

String city = addresses.get(0).getLocality();

```

- **Reverse Geocoding Example**:

```java

List<Address> addresses = geocoder.getFromLocation(37.4219983, -122.084, 1);

String addressLine = addresses.get(0).getAddressLine(0);

```

30. **Discuss developer console with at least four features**:

- **Dashboard**: Displays app performance, install statistics, and crash data.


- **App Releases**: Manages and tracks different app versions and updates.

- **User Feedback**: Displays ratings and user reviews for insights.

- **Monetization Reports**: Provides revenue details if the app is monetized through ads or in-app purchases.

31. **Program to declare and use permissions with example**:

```xml

<!-- Manifest Permission -->

<uses-permission android:name="android.permission.CALL_PHONE" />

```

```java

// Java Code to Make a Call

Intent callIntent = new Intent(Intent.ACTION_CALL);

callIntent.setData(Uri.parse("tel:123456789"));

if (ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {

startActivity(callIntent);

} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CALL_PHONE}, 1);

```

32. **Code to create GUI using AbsoluteLayout (assuming suitable data)**:

```xml

<AbsoluteLayout android:layout_width="match_parent" android:layout_height="match_parent">

<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 1" android:layout_x="50dp"


android:layout_y="50dp" />

<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 2" android:layout_x="150dp"


android:layout_y="150dp" />

</AbsoluteLayout>

Here are the answers to the 6-mark questions from the document:

1. **Program for addition, subtraction, division, and multiplication of two numbers**:

```xml
<!-- XML Layout -->

<EditText android:id="@+id/num1" android:hint="Enter Number 1" android:inputType="numberDecimal"/>

<EditText android:id="@+id/num2" android:hint="Enter Number 2" android:inputType="numberDecimal"/>

<Button android:id="@+id/calculateButton" android:text="Calculate"/>

<TextView android:id="@+id/result" android:text="Result"/>

```

```java

// Java Code

EditText num1 = findViewById(R.id.num1);

EditText num2 = findViewById(R.id.num2);

TextView result = findViewById(R.id.result);

findViewById(R.id.calculateButton).setOnClickListener(v -> {

double n1 = Double.parseDouble(num1.getText().toString());

double n2 = Double.parseDouble(num2.getText().toString());

double sum = n1 + n2;

double diff = n1 - n2;


double prod = n1 * n2;

double quot = n1 / n2;

result.setText("Sum: " + sum + ", Diff: " + diff + ", Prod: " + prod + ", Quot: " + quot);

});

```

2. **Develop an application to display a Google Map (Java and Manifest)**:

```xml

<!-- Manifest Permissions -->

<uses-permission android:name="android.permission.INTERNET"/>

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR_API_KEY"/>

```

```java

// Java Code
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

mapFragment.getMapAsync(googleMap -> {

LatLng location = new LatLng(37.7749, -122.4194);

googleMap.addMarker(new MarkerOptions().position(location).title("Marker in San Francisco"));

googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 10));

});

```

3. **Update a record in SQLite database (Java and XML)**:

```java

// Java Code

SQLiteDatabase db = openOrCreateDatabase("EmployeeDB", MODE_PRIVATE, null);

db.execSQL("UPDATE employee SET name = 'XYZ' WHERE emp_id = 'E101';");

Cursor cursor = db.rawQuery("SELECT * FROM employee WHERE emp_id = 'E101'", null);

if (cursor.moveToFirst()) {

String name = cursor.getString(cursor.getColumnIndex("name"));

Toast.makeText(getApplicationContext(), "Updated Name: " + name, Toast.LENGTH_SHORT).show();


}

```

4. **Steps for app deployment on Google Play Store & customized permissions**:

- **Deployment**:

- Create a Google Play Console account.

- Prepare the app (sign APK, test thoroughly).

- Create a store listing (app description, screenshots).

- Upload the app and set distribution preferences.

- Submit the app for review.

- **Customized Permissions**:

- Define permissions in the manifest.

- Use runtime permissions for sensitive data.

- Handle permission results in `onRequestPermissionsResult()`.

5. **Program to TURN ON and OFF Bluetooth (Java and permissions)**:


```xml

<!-- Manifest Permission -->

<uses-permission android:name="android.permission.BLUETOOTH"/>

```

```java

// Java Code

BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

if (bluetoothAdapter != null) {

bluetoothAdapter.enable(); // To turn ON Bluetooth

bluetoothAdapter.disable(); // To turn OFF Bluetooth

```

6. **Design an employee registration form using UI components**:

```xml

<!-- XML Layout -->


<EditText android:id="@+id/name" android:hint="Enter Name" />

<EditText android:id="@+id/email" android:hint="Enter Email" android:inputType="textEmailAddress" />

<EditText android:id="@+id/phone" android:hint="Enter Phone" android:inputType="phone" />

<EditText android:id="@+id/department" android:hint="Enter Department" />

<Button android:id="@+id/registerButton" android:text="Register" />

```

7. **Develop Android application for student feedback with database connectivity**:

```java

// Java Code

SQLiteDatabase db = openOrCreateDatabase("FeedbackDB", MODE_PRIVATE, null);

db.execSQL("CREATE TABLE IF NOT EXISTS feedback(id INTEGER PRIMARY KEY, studentName TEXT, feedbackText TEXT);");

EditText studentName = findViewById(R.id.studentName);

EditText feedbackText = findViewById(R.id.feedbackText);

Button submitButton = findViewById(R.id.submitButton);


submitButton.setOnClickListener(v -> {

String name = studentName.getText().toString();

String feedback = feedbackText.getText().toString();

db.execSQL("INSERT INTO feedback (studentName, feedbackText) VALUES('" + name + "', '" + feedback + "');");

Toast.makeText(getApplicationContext(), "Feedback Submitted", Toast.LENGTH_SHORT).show();

});

```

8. **Explain Geocoding and Reverse Geocoding with examples**:

- **Geocoding**: Converts addresses into geographic coordinates.

```java

Geocoder geocoder = new Geocoder(this, Locale.getDefault());

List<Address> addresses = geocoder.getFromLocationName("Eiffel Tower, Paris", 1);

double latitude = addresses.get(0).getLatitude();

double longitude = addresses.get(0).getLongitude();

```
- **Reverse Geocoding**: Converts coordinates into readable addresses.

```java

List<Address> addresses = geocoder.getFromLocation(48.8584, 2.2945, 1);

String addressLine = addresses.get(0).getAddressLine(0);

```

9. **Design an Android application to show the list of paired Bluetooth devices**:

```java

BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();

ListView listView = findViewById(R.id.listView);

ArrayList<String> deviceNames = new ArrayList<>();

for (BluetoothDevice device : pairedDevices) {

deviceNames.add(device.getName() + "\n" + device.getAddress());

ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, deviceNames);


listView.setAdapter(adapter);

```

10. **Develop an Android application for sending SMS (Java, XML, and Manifest)**:

```xml

<!-- Manifest Permission -->

<uses-permission android:name="android.permission.SEND_SMS" />

```

```java

// Java Code

SmsManager smsManager = SmsManager.getDefault();

smsManager.sendTextMessage("1234567890", null, "Hello from Android!", null, null);

```

11. **Explain usage of linear and frame layouts with example**:

- **LinearLayout**: Arranges elements in a single row or column.


```xml

<LinearLayout android:orientation="vertical">

<Button android:text="Button 1" />

<Button android:text="Button 2" />

</LinearLayout>

```

- **FrameLayout**: Stacks elements on top of each other.

```xml

<FrameLayout>

<ImageView android:src="@drawable/image" />

<TextView android:text="Overlay Text" />

</FrameLayout>

```

12. **Program to convert temperature using ToggleButton (Java and XML)**:

```xml
<!-- XML Layout -->

<EditText android:id="@+id/tempInput" android:hint="Enter Temperature"/>

<ToggleButton android:id="@+id/toggleButton" android:textOn="To Celsius" android:textOff="To Fahrenheit"/>

<TextView android:id="@+id/result" />

```

```java

// Java Code

EditText tempInput = findViewById(R.id.tempInput);

ToggleButton toggleButton = findViewById(R.id.toggleButton);

TextView result = findViewById(R.id.result);

toggleButton.setOnCheckedChangeListener((buttonView, isChecked) -> {

double temp = Double.parseDouble(tempInput.getText().toString());

if (isChecked) {

result.setText("Celsius: " + ((temp - 32) * 5/9));

} else {

result.setText("Fahrenheit: " + ((temp * 9/5) + 32));


}

});

```

13. **Program to capture an image using camera and display it**:

```java

// Java Code

Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

startActivityForResult(cameraIntent, 100);

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (requestCode == 100 && resultCode == RESULT_OK) {

Bitmap photo = (Bitmap) data.getExtras().get("data");

ImageView imageView = findViewById(R.id


.imageView);

imageView.setImageBitmap(photo);

```

14. **Send and receive SMS with XML, Java, and Manifest**:

- **Permissions**:

```xml

<uses-permission android:name="android.permission.SEND_SMS"/>

<uses-permission android:name="android.permission.RECEIVE_SMS"/>

```

- **Send SMS**:

```java

SmsManager smsManager = SmsManager.getDefault();

smsManager.sendTextMessage(phoneNumber, null, message, null, null);

```
- **Receive SMS**:

```java

public class SmsReceiver extends BroadcastReceiver {

@Override

public void onReceive(Context context, Intent intent) {

// Logic to read the incoming SMS message

```

15. **Program to implement Android Activity Life Cycle with Toasts**:

```java

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

Toast.makeText(this, "onCreate Called", Toast.LENGTH_SHORT).show();


}

@Override

protected void onStart() {

super.onStart();

Toast.makeText(this, "onStart Called", Toast.LENGTH_SHORT).show();

// Implement other lifecycle methods similarly

```

16. **Display Google map with user’s current location**:

```java

FusedLocationProviderClient locationClient = LocationServices.getFusedLocationProviderClient(this);

locationClient.getLastLocation().addOnSuccessListener(location -> {

if (location != null) {

double lat = location.getLatitude();


double lng = location.getLongitude();

LatLng userLocation = new LatLng(lat, lng);

googleMap.addMarker(new MarkerOptions().position(userLocation).title("You are here"));

googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(userLocation, 15));

});

```

17. **UI for Table Layout with buttons 0–9, submit, and clear**:

```xml

<TableLayout>

<TableRow>

<Button android:text="1" />

<Button android:text="2" />

<Button android:text="3" />

</TableRow>
<!-- Add rows similarly for buttons up to 9 -->

<TableRow>

<Button android:text="Submit" />

<Button android:text="Clear" />

</TableRow>

</TableLayout>

```

Let me know if you need further details!

You might also like