Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
17 views25 pages

Q1 Draw and Explain Activity and Service Life Cycle

The document explains the Android Activity and Service lifecycle, detailing the various lifecycle methods for activities and the differences between Started and Bound Services. It also outlines steps to deploy an app on the Google Play Store, the concept of Intents and their types, and provides code examples for sending emails and SMS, animations, and sensor usage. Additionally, it covers the Android security model, types of permissions, the significance of the Android Developer Console, and code for managing Wi-Fi and Bluetooth functionalities.

Uploaded by

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

Q1 Draw and Explain Activity and Service Life Cycle

The document explains the Android Activity and Service lifecycle, detailing the various lifecycle methods for activities and the differences between Started and Bound Services. It also outlines steps to deploy an app on the Google Play Store, the concept of Intents and their types, and provides code examples for sending emails and SMS, animations, and sensor usage. Additionally, it covers the Android security model, types of permissions, the significance of the Android Developer Console, and code for managing Wi-Fi and Bluetooth functionalities.

Uploaded by

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

Q1 Draw and Explain Activity and Service Life Cycle

The Activity Lifecycle defines how an Android activity behaves at different stages — from
when it's created, becomes visible, comes to the foreground, and finally when it's destroyed.

The Android system automatically calls lifecycle methods to manage how the app interacts
with the user and system resources.
 Android maintains a stack of activities, called the Back Stack.
 When a new activity starts, it is pushed onto the stack.
 When you press the back button, the current activity is popped off the stack, and the
previous one resumes.

Lifecycle Methods

1. onCreate()
o Called once when the activity is created.
o Setup UI, variables, and components.
2. onStart()
o Called when the activity becomes visible, but not yet in the foreground.
o Good place to refresh data.
3. onResume()
o Called when the activity moves to the foreground and is ready to interact with
the user.
o The app is now active and visible.
4. onPause()
o Called when the activity is partially hidden (e.g., a dialog appears or another
activity is in front).
o Used to pause animations, save light data.
5. onStop()
o Called when the activity is completely hidden.
o It enters the stopped state and is no longer visible.
o Good for releasing resources like sensors or GPS.
6. onDestroy()
o Final call before the activity is completely removed.
o Used for cleanup.
7. onRestart()
o Called after onStop() when the activity is coming back to the foreground.

Service Life cycle


A Service in Android runs in the background without any user interface. It's used to do long
tasks like downloading, playing music, etc.

There are two types of services: Started Service and Bound Service.
A Started Service is started using startService(). The system calls onCreate() once and
then onStartCommand() every time the service starts. It keeps running in the background even if
the user leaves the app. When it’s done, onDestroy() is called to stop it.

A Bound Service is started using bindService(). It allows other components (like an activity)
to connect and talk to it. The system calls onCreate() and then onBind(). It stops automatically
when no one is connected. Then onUnbind() and onDestroy() are called.

So, Started Service = background work, and Bound Service = background + interaction.
Q2 Write Down Steps to deploy app on Google Play
Store :
1. Create a Developer Account
o Sign up at play.google.com/console and pay $25.
2. Link Your Merchant Account
o Needed if your app has paid features or in-app purchases.
3. Create an App
o Enter app name, type, language, and accept policies.
4. Prepare Store Listing
o Add app title, description, screenshots, icon, and contact info.
5. Upload APK or AAB
o Go to “App release” and upload your signed APK/AAB file.
6. Provide Content Rating
o Fill in the rating questionnaire to set the proper age group.
7. Set Pricing & Distribution
o Choose Free/Paid and select available countries.
8. Rollout Release & Publish
o Review all info and click “Publish” to submit the app.
Q3. Explain Intent And Its Type :
An Intent in Android is a messaging object used to request an action from another app
component. It is used to start activities, services, or send data between components.

For example, you can use an intent to open a new screen, send an email, open a webpage, or
share data between activities.

Types of Intents

There are two main types of intents:

1. Explicit Intent
o Used to start a specific component within the same app.
o Example: Starting a new activity in your own app.
2. Implicit Intent
o Used to request an action without naming a specific component.
o The system finds a suitable app to handle it.
o Example: Open browser, dial number, or send an email.

Code : Phone dial and Google Page :

<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="20dp">

<Button
android:id="@+id/btnDial"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open Dialer" />

<Button
android:id="@+id/btnGoogle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open Google" />

</LinearLayout>
package com.example.jod;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


Button btnDial, btnGoogle;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

btnDial = findViewById(R.id.btnDial);
btnGoogle = findViewById(R.id.btnGoogle);

btnDial.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_DIAL);
startActivity(intent);
}
});

btnGoogle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.google.com"));
startActivity(intent);
}
});
}
}
Q4.Write A program to send Email and SMS

AndroidManifest.xml

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

Xml

<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="20dp">

<EditText
android:id="@+id/etNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Phone Number" />

<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>

Java

package com.example.jod;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

public class MainActivity extends AppCompatActivity {

EditText etNumber, etMessage;


Button btnSend;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

etNumber = findViewById(R.id.etNumber);
etMessage = findViewById(R.id.etMessage);
btnSend = findViewById(R.id.btnSend);

btnSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String number = etNumber.getText().toString();
String message = etMessage.getText().toString();

try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(number, null, message,
null, null);
Toast.makeText(MainActivity.this, "SMS Sent",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(MainActivity.this, "Failed to send
SMS", Toast.LENGTH_SHORT).show();
}
}
});
}
}
Email :

Xml
<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"
android:gravity="center">

<Button
android:id="@+id/btnEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Email" />
</LinearLayout>

Java
package com.example.jod;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

Button btnEmail;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

btnEmail = findViewById(R.id.btnEmail);

btnEmail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]
{"[email protected]"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Test Subject");
intent.putExtra(Intent.EXTRA_TEXT, "This is the email
body.");
startActivity(Intent.createChooser(intent, "Choose Email
App"));
}
});
}
}

Q5. Write a code for animation Zoom IN and Out & Fade IN and Out

RES /ANIM folder :

Zoom in/out .xml


<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">

<scale
android:fromXScale="0.5"
android:toXScale="1.0"
android:fromYScale="0.5"
android:toYScale="1.0"
android:duration="300" />

<scale
android:fromXScale="1.0"
android:toXScale="0.5"
android:fromYScale="1.0"
android:toYScale="0.5"
android:duration="300" />

</set>

Fade in/out .xml


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="300" />
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:startOffset="300"
android:duration="300" />

</set>

Main.xml
<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="20dp">

<ImageView
android:id="@+id/imageView"
android:layout_width="150dp"
android:layout_height="150dp"
android:src="@mipmap/ic_launcher" />

<Button
android:id="@+id/btnZoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Zoom In/Out" />

<Button
android:id="@+id/btnFade"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fade In/Out" />
</LinearLayout>

Java
package com.example.jod;

import android.os.Bundle;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {

ImageView imageView;
Button btnZoom, btnFade;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

imageView = findViewById(R.id.imageView);
btnZoom = findViewById(R.id.btnZoom);
btnFade = findViewById(R.id.btnFade);

btnZoom.setOnClickListener(v ->
imageView.startAnimation(AnimationUtils.loadAnimation(this,
R.anim.zoom_in_out)));

btnFade.setOnClickListener(v ->
imageView.startAnimation(AnimationUtils.loadAnimation(this,
R.anim.fade_in_out)));
}
}

Q6 .Explain Andriod Security model and types of permission

Android Security Model


Android uses a multi-layered security model to protect user data and device integrity. Every
app runs in its own sandbox, meaning it cannot access other apps' data or system resources
directly. Apps must request permissions to access sensitive features like camera, storage, or
contacts. The Android system enforces this using a permission-based access control.

Types of Permissions in Android

1. Normal Permissions
These allow access to basic features (like internet or vibrate).
⚙️Automatically granted at install time.
2. Dangerous Permissions
These involve user data (like contacts, SMS, location).
⚠️User must grant them at runtime (Android 6.0+).
3. Signature Permissions
Granted only if the requesting app is signed with the same certificate as the app
declaring the permission.
4. Special Permissions
High-level permissions like "Draw over other apps" or "Change system settings".
⚠️Must be granted manually in system settings.

Q7 Write significance of Andriod Developer console

Google Play Developer Console is an online platform provided by Google to publish, manage,
and monitor Android apps on the Play Store.

Significance:

 App Publishing: Allows uploading and releasing APKs or App Bundles to users
globally.
 App Updates: Easily manage app versions and push updates.
 Store Listing: Customize app title, description, screenshots, and more.
 User Feedback: View and respond to user ratings and reviews.
 Statistics & Reports: Monitor app performance, installs, crashes, and ANRs.
 Monetization: Manage in-app purchases and set up pricing.
 Testing & Tracks: Use internal, alpha, or beta testing tracks before full release.
 Security & Policy Management: Ensure apps meet Google’s content and security
policies.

Q8 Write program to all types of sensors :

Xml :
<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">

<TextView
android:id="@+id/tvSensors"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sensors List:"
android:textSize="18sp" />
</LinearLayout>

Java Code :

package com.example.sensordemo;

import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;
import java.util.List;

public class MainActivity extends Activity {

TextView tvSensors;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tvSensors = findViewById(R.id.tvSensors);
SensorManager sensorManager = (SensorManager)
getSystemService(SENSOR_SERVICE);
List<Sensor> sensorList =
sensorManager.getSensorList(Sensor.TYPE_ALL);

StringBuilder sensorData = new StringBuilder();


for (Sensor sensor : sensorList) {
sensorData.append(sensor.getName()).append("\n");
}

tvSensors.setText(sensorData.toString());
}
}
Q9 wap to wifi and Bluetooth !

Bluetooth :

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

Xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
android:id="@+id/btnTurnOn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Turn ON Bluetooth"
android:onClick="turnOnBluetooth" />

<Button
android:id="@+id/btnTurnOff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Turn OFF Bluetooth"
android:onClick="turnOffBluetooth" />

<Button
android:id="@+id/btnShowDevices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show Paired Devices"
android:onClick="showPairedDevices" />

<ListView
android:id="@+id/listViewDevices"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Java
package com.example.bluetoothapp;

import androidx.appcompat.app.AppCompatActivity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import java.util.ArrayList;
import java.util.Set;

public class MainActivity extends AppCompatActivity {

BluetoothAdapter bluetoothAdapter;
ListView listViewDevices;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

listViewDevices = findViewById(R.id.listViewDevices);
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
}

public void turnOnBluetooth(View view) {


if (!bluetoothAdapter.isEnabled()) {
Intent intent = new
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivity(intent);
Toast.makeText(this, "Bluetooth Turned ON",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Bluetooth is already ON",
Toast.LENGTH_SHORT).show();
}
}

public void turnOffBluetooth(View view) {


if (bluetoothAdapter.isEnabled()) {
bluetoothAdapter.disable();
Toast.makeText(this, "Bluetooth Turned OFF",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Bluetooth is already OFF",
Toast.LENGTH_SHORT).show();
}
}

public void showPairedDevices(View view) {


Set<BluetoothDevice> pairedDevices =
bluetoothAdapter.getBondedDevices();
ArrayList<String> deviceList = new ArrayList<>();

for (BluetoothDevice device : pairedDevices) {


deviceList.add(device.getName() + " - " +
device.getAddress());
}

if (deviceList.isEmpty()) {
Toast.makeText(this, "No Paired Devices Found",
Toast.LENGTH_SHORT).show();
} else {
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, deviceList);
listViewDevices.setAdapter(adapter);
}
}
}

Wifi :

Manifest :

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

Xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btnWifiOn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Turn ON WiFi"
android:onClick="turnOnWifi" />

<Button
android:id="@+id/btnWifiOff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Turn OFF WiFi"
android:onClick="turnOffWifi" />
</LinearLayout>

Java:

package com.example.wifitest;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

WifiManager wifiManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

wifiManager = (WifiManager)
getApplicationContext().getSystemService(Context.WIFI_SERVICE);
}

public void turnOnWifi(View view) {


if (!wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(true);
Toast.makeText(this, "WiFi Turned ON",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "WiFi is already ON",
Toast.LENGTH_SHORT).show();
}
}

public void turnOffWifi(View view) {


if (wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(false);
Toast.makeText(this, "WiFi Turned OFF",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "WiFi is already OFF",
Toast.LENGTH_SHORT).show();
}
}
}

Extra Questions from A division

Q1 Define Geocoding and reverse Geo coding

Geocoding is the process of converting a place name or address into geographical


coordinates (latitude and longitude).
Reverse Geocoding is the opposite — it converts latitude and longitude into a readable
address or location name.

Example:

 Geocoding → "Taj Mahal" → 27.1751° N, 78.0421° E


 Reverse Geocoding → 27.1751° N, 78.0421° E → "Taj Mahal, Agra, India"

Q2 Write permission required for ( SMS , BLUETOOH , WIFI , INTERNET/DATA )


<!-- SMS Permissions -->
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />

<!-- Bluetooth Permissions -->


<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"
/>
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />

<!-- WiFi Permissions -->


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

<!-- Internet/Data Permissions -->


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

Q3Write A program to capture an image and insert it in a imageview


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

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:orientation="vertical"
android:padding="20dp"
android:gravity="center">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Capture Image"
android:onClick="captureImage" />

<ImageView
android:id="@+id/imageView"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_marginTop="20dp"
android:scaleType="centerCrop" />
</LinearLayout>

Java:
package com.example.captureimage;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


ImageView imageView;
static final int CAMERA_REQUEST = 100;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.imageView);
}

public void captureImage(android.view.View view) {


Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA_REQUEST);
}

@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
}

Q4 Write steps to generate API key for Google Maps !


Step 1: Go to Google Cloud Console
🔗 https://console.cloud.google.com/

Step 2: Click on “Select a project” or “Create Project”


➡️Give your project a name and click “Create”

Step 3: Enable Maps SDK for Android


🔍 In the search bar, type: Maps SDK for Android
✅ Click on it and then press Enable

Step 4: Go to APIs & Services > Credentials


📍 Click on “Create Credentials” > API Key

Step 5: Copy the API Key


🔑 The key will be generated – copy it

Step 6: Add it to AndroidManifest.xml


Paste the key inside your app like this:

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

Q5 Explain android Multimedia framework

The Android Multimedia Framework is a system that helps Android applications to play,
record, and manage audio, video, and images. It supports many common media formats like
MP3, MP4, AAC, 3GP, etc. It gives developers built-in classes and tools to handle media easily.
Architecture Overview:

1. Java API Layer:


Apps use Java classes like:
o MediaPlayer – for playing audio/video
o MediaRecorder – for recording
o IMediaPlayer and IMediaRecorder – internal interfaces for media control
2. JNI (Java Native Interface):
This connects Java code to the native C/C++ libraries for better performance.
3. Native C/C++ Layer:
o Contains core libraries that handle media processing
o Communicates with the hardware and low-level services
4. Media Server:
o A background system service that manages all media-related tasks.
5. PVPlayer and Author:
o Used internally for media playback and file authoring (encoding).

Q6 Text to Speech :

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:orientation="vertical"
android:padding="20dp">

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter text" />

<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Speak" />
</LinearLayout>

Java :
package com.example.tts;

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;

public class MainActivity extends Activity {


TextToSpeech tts;
EditText inputText;
Button speakBtn;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

inputText = findViewById(R.id.editText);
speakBtn = findViewById(R.id.button);

tts = new TextToSpeech(getApplicationContext(), status -> {


if (status != TextToSpeech.ERROR) {
tts.setLanguage(Locale.UK);
}
});

speakBtn.setOnClickListener(v -> {
String text = inputText.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null, null);
});
}

@Override
protected void onPause() {
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onPause();
}
}

You might also like