0% found this document useful (0 votes)
10 views23 pages

Madpt2qbv1 (Codeincluded)

The document outlines various tasks related to Android development, including creating a custom toast notification, implementing a scroll view, and understanding key concepts such as services, intents, and sensors. It also covers the activity lifecycle, database handling with SQLite, and multimedia features like audio and video playback. Additionally, it provides code examples for building a camera app and listing all sensors available on a device.

Uploaded by

Ruchi
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)
10 views23 pages

Madpt2qbv1 (Codeincluded)

The document outlines various tasks related to Android development, including creating a custom toast notification, implementing a scroll view, and understanding key concepts such as services, intents, and sensors. It also covers the activity lifecycle, database handling with SQLite, and multimedia features like audio and video playback. Additionally, it provides code examples for building a camera app and listing all sensors available on a device.

Uploaded by

Ruchi
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/ 23

Unit 4: Design User Interface with View (12 Marks)

4 Marks

1. Develop a program to implement Custom Toast


Alert. Create custom_toast.xml inside the
res/layout/ folder:

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


<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp"
android:background="#FF0000"> <!-- Red Background -->

<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@android:drawable/ic_dialog_info"
android:layout_marginEnd="10dp"/>

<TextView
android:id="@+id/toast_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Custom Toast!"
android:textColor="#FFFFFF"
android:textSize="16sp"/>
</LinearLayout>
MainActivity.java
package com.example.customtoast;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends
AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Show Custom Toast


showCustomToast("Hello! This is a Custom Toast.");
}
private void showCustomToast(String message) {
LayoutInflater inflater = getLayoutInflater(); View layout =
inflater.inflate(R.layout.custom_toast, null); TextView text =
layout.findViewById(R.id.toast_text);
text.setText(message);
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
}
2. Develop a program to implement Scroll View.
activity_main.xml

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


<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">

<!-- Item 1 -->


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:text="Item 1: Welcome to ScrollView Example"
android:textSize="20sp"
android:textStyle="bold"/>

<!-- Item 2 -->


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:text="Item 2: This is a sample text."
android:textSize="18sp"/>

<!-- Item 3 -->


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:text="Item 3: More content here."
android:textSize="18sp"/>
<!-- Item 4 -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:text="Item 4: Enjoy scrolling."
android:textSize="18sp"/>

<!-- Item 5 -->


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:text="Item 5: Keep on going."
android:textSize="18sp"/>

<!-- Item 6 -->


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:text="Item 6: Almost halfway through."
android:textSize="18sp"/>

<!-- Item 7 -->


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:text="Item 7: Seven items now."
android:textSize="18sp"/>

<!-- Item 8 -->


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:text="Item 8: More scrolling fun."
android:textSize="18sp"/>
<!-- Item 9 -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:text="Item 9: Keep scrolling."
android:textSize="18sp"/>

<!-- Item 10 -->


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:text="Item 10: Almost there."
android:textSize="18sp"/>

<!-- Item 11 -->


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:text="Item 11: More items to see."
android:textSize="18sp"/>

<!-- Item 12 -->


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:text="Item 12: Keep enjoying the scroll."
android:textSize="18sp"/>

<!-- Item 13 -->


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:text="Item 13: Almost done."
android:textSize="18sp"/>
<!-- Item 14 -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:text="Item 14: Just one more."
android:textSize="18sp"/>

<!-- Item 15 -->


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:text="Item 15: You reached the end!"
android:textSize="18sp"/>

</LinearLayout>
</ScrollView>

MainActivity.java
package com.example.index;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
(IN ActivityMain.xml YOU CAN LEARN ANYONE TEXTVIEW AND CAN
CREATE SAME TEXT VIEW MULTIPLE TIMES TO MAKE SCROLLABLE OR
YOU CAN INCREASE PADDING FOR REMOVING MULTIPLE TEXTVIEW’S)
Unit 5: Activity & Multimedia with Database

2 Marks

1. Write the syntax for Intent-Filter tag.


<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

2. What is Service in Android? Enlist its Types.


A Service in Android runs in the background without a user interface. It is
used for long-running operations like playing music or fetching data. Types of
services are

• Foreground Service
• Background Service
• Bound Service

3. Enlist different ways to handle databases in android? Elaborate


anyone. Android provides multiple ways to handle databases, such as
SQLite, Room Database, and Firebase.

SQLite is the most common local database that stores structured data in
tables. It allows CRUD (Create, Read, Update, Delete) operations using SQL
queries.

4. What is Intent? Enlist its Types.


An Intent is used in Android to navigate between activities, pass data, and
trigger system events. It is of two types:

• Explicit Intent: which starts a specific activity


• Implicit Intent: which lets the system decide which app can handle the
request.

5. What is Sensor in Android? Enlist its Types.


Sensors in Android help detect physical properties like movement, light,
and temperature. The three main types of sensors are
• Motion Sensors
• Environmental Sensors
• Position Sensors
These sensors help in fitness tracking, gaming, and automation.
6. What is Animation? Enlist its Types.
Animation in Android enhances user interaction by creating visual effects. It
has three main types:

• Tween Animation (scaling, rotation)


• Frame Animation (sequence of images)
• Property Animation (modifying object properties over time).

7. What is TTS Feature of Android?


Text-to-Speech (TTS) in Android allows the device to convert written text into
spoken output. It is useful for visually impaired users and voice assistant
applications. TTS can be customized for different languages and speech
speeds.
4 Marks

1. Define content provider and explain fragments.


Content Provider: A Content Provider is a component in Android that helps
applications share data with other apps in a secure and structured way. It
allows access to data such as contacts, images, music, and databases using
a URI (Uniform Resource Identifier).

Fragments: Fragments are reusable parts of an activity that provide a flexible


UI across different screen sizes. They help manage multiple views in one
activity, reducing code repetition. For example, a messaging app can use
fragments for the chat list and message details.
OR
A Fragment in Android is a small part of an app’s screen that works inside an
Activity. It helps create flexible and reusable layouts, especially for larger
screens like tablets. Fragments cannot work alone; they always need an
activity to host them. They allow apps to update only part of the screen
without restarting the whole activity. This makes the app more organized and
user-friendly. Fragments are commonly used in tabs, navigation menus,
and split screens, making apps more flexible and easy to manage.

2. Explain the activity life cycle.


The Activity Life Cycle in Android consists of different states: onCreate(),
onStart(), onResume(), onPause(), onStop(), and onDestroy(). When an
activity is launched, it goes through these states in sequence. If an activity is
paused or stopped, it can resume without restarting. Understanding these
states helps manage app behavior and memory efficiently.

• onCreate() – Called when the activity is first created; used for


initialization. • onStart() – Called when the activity becomes visible to
the user.
• onResume() – Called when the activity is ready for user interaction. •
onPause() – Called when the activity is partially visible (another activity
comes in front).
• onStop() – Called when the activity is no longer visible.
• onDestroy() – Called before the activity is completely removed from memory.
3. Explain with Diagram Service Life Cycle?
The Service Life Cycle includes three main states: onCreate(),
onStartCommand(), and onDestroy(). A service starts when the
onCreate() method is called, runs in the background, and stops with
onDestroy(). Services can be bound (communicating with other
components) or unbound (running independently). A music player running
in the background is an example of a service.
4. How to Play Audio & Video in Android?
Android provides the MediaPlayer class for playing audio and the VideoView
class for video playback. Audio files can be played from local storage or a
URL using MediaPlayer.start(), and supported formats include MP3, WAV,
and AAC. Similarly, VideoView.setVideoURI() is used to load and play
videos, supporting formats like MP4, 3GP, and AVI. Developers can control
playback using methods like pause(), resume(), and stop(), making it easy to
manage media in apps. Additionally, seek functions allow users to move to
specific parts of the audio or video, enhancing the user experience.
5. Explain how to Create & Connect SQLite?
SQLite is an in-built database in Android for storing structured data. It is
created using the SQLiteOpenHelper class, and onCreate() is overridden to
define tables. Developers can insert, update, and delete data using SQL
queries. getWritableDatabase() is used to perform write operations, while
getReadableDatabase() is used for reading data. To connect SQLite, create
a subclass of SQLiteOpenHelper and provide a database name. Use
getWritableDatabase() or getReadableDatabase() to interact with the
database and close() to free resources.

6. What is Transaction? Explain with Example.


A transaction in a database ensures that a set of operations is executed
completely or not at all. For example, transferring money between two
accounts should either complete successfully or not happen at all. SQLite
supports transactions using beginTransaction(), setTransactionSuccessful(),
and endTransaction(). Transactions help in maintaining data integrity.

7. Develop a program to build Camera.

Permission in AndroidManifest.xml

<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="true"/>

MainActivity.java

package com.example.camerademo;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


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

imageView = findViewById(R.id.imageView);
btnCapture = findViewById(R.id.btnCapture);
btnCapture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, 100);
}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable
Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == 100 && resultCode == RESULT_OK && data !=


null) { Bitmap imageBitmap = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(imageBitmap);
}
}
}

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

<ImageView
android:id="@+id/imageView"
android:layout_width="250dp"
android:layout_height="250dp"
android:scaleType="centerCrop"
android:background="@android:color/darker_gray"/>

<Button
android:id="@+id/btnCapture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open Camera"
android:layout_marginTop="20dp"/>

</LinearLayout>

8. Develop a program to list all sensors.


MainActivity.java
package com.example.index;

import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {


ListView sensorListView;
SensorManager sensorManager;

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

sensorListView = findViewById(R.id.sensorListView);
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

List<Sensor> sensorList =
sensorManager.getSensorList(Sensor.TYPE_ALL); ArrayList<String>
sensorNames = new ArrayList<>();

for (Sensor sensor : sensorList) {


sensorNames.add(sensor.getName());
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, sensorNames);
sensorListView.setAdapter(adapter);
}
}
activity_main.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">

<ListView
android:id="@+id/sensorListView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</LinearLayout>

9. Develop a program for animation to zoom in only.


MainActivity.java
package com.example.zoomanimation;

import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


ImageView imageView;

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

imageView = findViewById(R.id.imageView);

// Zoom-In Animation (Scale from 1x to 2x size)


ScaleAnimation zoomIn = new ScaleAnimation(
1.0f, 2.0f, // Start and end X scale
1.0f, 2.0f, // Start and end Y scale
Animation.RELATIVE_TO_SELF, 0.5f, // Pivot X at center
Animation.RELATIVE_TO_SELF, 0.5f // Pivot Y at center );
zoomIn.setDuration(1000); // Duration in milliseconds (1 second)
zoomIn.setFillAfter(true); // Keep the final scale

// Start animation
imageView.startAnimation(zoomIn);
}
}

activity_main.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">

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

10.Develop a program to implement broadcast


receiver. MainActivity.java

package com.example.index;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


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

// Register BroadcastReceiver dynamically


airplaneModeReceiver = new AirplaneModeReceiver();
IntentFilter filter = new
IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
registerReceiver(airplaneModeReceiver, filter);
}

@Override
protected void onDestroy() {
super.onDestroy();
// Unregister the receiver to prevent memory leaks
unregisterReceiver(airplaneModeReceiver);
}
}

AirplaneModeReceiver.java
package com.example.index;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

public class AirplaneModeReceiver extends BroadcastReceiver {


private static final String TAG = "AirplaneModeReceiver";

@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(intent.getAction())) {
boolean isAirplaneModeOn = intent.getBooleanExtra("state", false); String
message = isAirplaneModeOn ? "Airplane Mode is ON" : "Airplane Mode is OFF";

// Show Toast message


Toast.makeText(context, message, Toast.LENGTH_SHORT).show();

// Log the event for debugging


Log.d(TAG, "Broadcast received: " + message);
}
}
}
activity_main.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">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toggle Airplane Mode to Test"
android:textSize="18sp"/>
</LinearLayout>

AndroidManifest.xml
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.qb">
<!-- Camera Permission -->
<uses-permission android:name="android.permission.CAMERA"/> <uses-feature
android:name="android.hardware.camera" android:required="true"/> <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="Camera App"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Unit 6: Security & Application Deployment

2 Marks Answers

1. Name any 4 methods to get location data in android.


Android provides four methods to get location data:

• GPS Provider (high accuracy)


• Network Provider (uses Wi-Fi/cellular)
• Passive Provider (uses other apps’ data)
• Fused Location Provider (combines GPS and network for best accuracy)

2. Explain Geocoding & Reverse Geocoding.


Geocoding converts an address into latitude and longitude, helping apps
find places on a map.

Reverse Geocoding does the opposite—it converts latitude and longitude


into a human-readable address. This is useful for location-based
applications.

3. Steps to Publish an Android Application


1> Sign up at Google Play Console, Pay a one-time fee of $25.
2> Test your app and remove any errors or bugs, Make sure your package
name is unique.
3> In Android Studio, go to Build > Generate Signed Bundle/APK.
4> Click Create App and enter app details (name, category), Upload Your App
File. 5> Add App Title, Description, Screenshots, and App Icon.
5> Set Pricing & Distribution
6> Submit for Review
7> Google reviews the app (may take a few hours or days). Once approved,
your app is live on the Play Store!

4. Steps to Deploy an Android Application

1. Test your app to ensure it runs without errors.


2. Open Android Studio and generate a signed APK or AAB.
3. Create a keystore and sign the app for release.
4. Install the APK on a real device and test it.
5. Create a Google Play Developer Account and pay the fee.
6. Upload the AAB to the Play Store and fill in app details.
7. Submit the app for review and wait for approval.
8. If not using Play Store, share the APK manually.
5. Google Maps & Its Types
Google Maps is a mapping service by Google that provides real-time
navigation, location search, and route planning. It helps users find places,
get directions, and explore areas with satellite imagery, street views, and
real-time traffic updates. It has different types of maps:

• Normal Map – Shows roads, buildings, and places (default


map). • Satellite Map – Displays real satellite images.
• Terrain Map – Shows mountains, rivers, and land heights.
• Hybrid Map – Mixes satellite view with road names.

6. List Various Classes of SMS Telephony.


Android provides SmsManager (to send SMS), TelephonyManager (to get
SIM info), BroadcastReceiver (to receive SMS), and
Intent.ACTION_VIEW (to open the messaging app). These classes help in
managing SMS services.
4 Marks Answers

1) Describe types of permissions used while developing


android applications.
Android permissions control access to sensitive user data and
device features.

1. Normal Permissions are automatically granted (e.g., internet


access). 2. Dangerous Permissions (e.g., camera, location) require
user approval. 3. Signature Permissions are granted only if apps are
signed by the same developer.
4. Special Permissions (e.g., SYSTEM_ALERT_WINDOW) require
additional user actions.Managing permissions correctly is important for
security and privacy.

2) Develop an application to send and receiveSMS.(Write ONLY .java


and permission tag in manifest file).
AndroidManifest.xml
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission
android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>

Send SMS: MainActivity.java


package com.example.smsapp;

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 phoneNumber, messageText;
Button sendSms;

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

phoneNumber = findViewById(R.id.phoneNumber);
messageText = findViewById(R.id.messageText);
sendSms = findViewById(R.id.sendSms);

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

sendSms.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String number = phoneNumber.getText().toString();
String message = messageText.getText().toString();

if (!number.isEmpty() && !message.isEmpty()) {


SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(number, null, message, null, null);
Toast.makeText(MainActivity.this, "SMS Sent!",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Enter number and message",
Toast.LENGTH_SHORT).show();
}
}
});
}
}

Receive SMS: MainActivity.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;

public class SmsReceiver extends BroadcastReceiver {


@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
if (pdus != null) {
for (Object pdu : pdus) {
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) pdu);
String sender = smsMessage.getDisplayOriginatingAddress(); String
message = smsMessage.getMessageBody();
Toast.makeText(context, "SMS from: " + sender + "\nMessage: " + message,
Toast.LENGTH_LONG).show();
}
}
}
}
}
3) Discuss Developer console with its purpose.
The Google Play Developer Console is a powerful tool used by developers
to publish, manage, and monitor their Android applications. It allows
developers to upload APKs or AABs, track app performance and
analytics, manage user feedback and reviews, and monetize apps
through in-app purchases and ads. Additionally, it provides crash reports,
security warnings, and testing tools to help improve app quality and
ensure a smooth user experience. The console also enables developers
to manage beta testing, app updates, and localization for a global
audience.

4) Develop a program to send and receive e-mail.

AndroidManifest.xml Permission
<uses-permission android:name="android.permission.INTERNET"/>
MainActivity.java
package com.example.emailapp;

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

public class MainActivity extends AppCompatActivity {


EditText toEmail, subject, message;
Button sendEmail;
@Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

toEmail = findViewById(R.id.toEmail);
subject = findViewById(R.id.subject);
message = findViewById(R.id.message);
sendEmail = findViewById(R.id.sendEmail);

sendEmail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String recipient = toEmail.getText().toString();
String emailSubject = subject.getText().toString();
String emailMessage = message.getText().toString();

Intent intent = new Intent(Intent.ACTION_SENDTO);


intent.setData(Uri.parse("mailto:" + recipient));
intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
intent.putExtra(Intent.EXTRA_TEXT, emailMessage);

startActivity(Intent.createChooser(intent, "Send Email")); }


});
}
}

Activity_main.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/toEmail"
android:layout_width="match_parent"
android:layout_height="56dp"
android:hint="Enter recipient email"
android:inputType="textEmailAddress"
android:padding="12dp" />
<EditText
android:id="@+id/subject"
android:layout_width="match_parent"
android:layout_height="56dp"
android:hint="Enter subject"
android:inputType="text"
android:padding="12dp" />

<EditText
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="120dp"
android:hint="Enter message"
android:inputType="textMultiLine"
android:padding="12dp"
android:minLines="4" />

<Button
android:id="@+id/sendEmail"
android:layout_width="match_parent"
android:layout_height="56dp"
android:text="Send Email"
android:layout_marginTop="10dp"/>

</LinearLayout>
© 2025 Naitik Donda. All Rights Reserved.

This document is created by Naitik Donda. It may not be copied, distributed, or


shared without giving proper credit. Please provide five credits before sharing or
using any part of this document. Unauthorized use is prohibited.

For any queries; gmail> [email protected]

You might also like