0% found this document useful (0 votes)
3 views

android codesssss (2)

The document contains a final list of 33 unique Android coding questions, including programs for displaying a progress bar, sending and receiving SMS, sending emails, providing Bluetooth connectivity, implementing ListView and GridView, and storing customer details using SQLite. Each coding question includes XML layout files and Java code necessary for implementation. The document serves as a comprehensive guide for Android development exercises.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

android codesssss (2)

The document contains a final list of 33 unique Android coding questions, including programs for displaying a progress bar, sending and receiving SMS, sending emails, providing Bluetooth connectivity, implementing ListView and GridView, and storing customer details using SQLite. Each coding question includes XML layout files and Java code necessary for implementation. The document serves as a comprehensive guide for Android development exercises.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 35

Final List of 33 Unique Android Coding Questions

1. Develop a program to display a rectangular progress bar.

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

<ProgressBar
android:id="@+id/progressBar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:progress="60"
android:max="100" />
</LinearLayout>

🔹 MainActivity.java
java
CopyEdit
package com.example.progressbarapp;

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

public class MainActivity extends AppCompatActivity {


ProgressBar progressBar;

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

progressBar = findViewById(R.id.progressBar);
progressBar.setProgress(60); // Set 60% progress
}
}

2. Develop an application to send and receive SMS (Write Java and manifest permissions only).

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

public class MainActivity extends AppCompatActivity {


EditText etPhone, etMessage;
Button btnSend;

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

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 (int i = 0; i < pdus.length; i++) {
byte[] pdu = (byte[]) pdus[i];
SmsMessage message = SmsMessage.createFromPdu(pdu);
String sender = message.getOriginatingAddress();
String body = message.getMessageBody();
Toast.makeText(context, "From: " + sender + "\n" + body,
Toast.LENGTH_LONG).show();
}
}
}
}
}

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

3. Develop a program to send and receive an Email.

MainActivity.java (Sending Email)


java
CopyEdit
package com.example.sendemail;

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

public class MainActivity extends AppCompatActivity {

EditText etEmail, etSubject, etMessage;


Button btnSendEmail;

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

etEmail = findViewById(R.id.etEmail);
etSubject = findViewById(R.id.etSubject);
etMessage = findViewById(R.id.etMessage);
btnSendEmail = findViewById(R.id.btnSendEmail);

btnSendEmail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String email = etEmail.getText().toString();
String subject = etSubject.getText().toString();
String message = etMessage.getText().toString();

Intent emailIntent = new Intent(Intent.ACTION_SEND);


emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{email});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, message);
emailIntent.setType("message/rfc822");

try {
startActivity(Intent.createChooser(emailIntent, "Choose an Email
client"));
Toast.makeText(MainActivity.this, "Email Sent",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(MainActivity.this, "No email client found",
Toast.LENGTH_SHORT).show();
}
}
});
}
}

activity_main.xml (UI Layout)


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

<EditText
android:id="@+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Recipient Email"
android:inputType="textEmailAddress" />

<EditText
android:id="@+id/etSubject"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Subject"
android:inputType="text" />

<EditText
android:id="@+id/etMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Message"
android:inputType="textMultiLine" />

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

4. Develop a program for providing Bluetooth connectivity.

1. activity_main.xml
xml
CopyEdit
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/out"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bluetooth Status"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:layout_centerHorizontal="true"/>

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TURN ON"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="30dp"
android:layout_marginTop="80dp"/>

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DISCOVERABLE"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginTop="30dp"/>

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TURN OFF"
android:layout_alignLeft="@+id/button2"
android:layout_below="@+id/button2"
android:layout_marginTop="30dp"/>
</RelativeLayout>

2. MainActivity.java

java
CopyEdit
package com.example.bluetooth;

import android.os.Bundle;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {


private static final int REQUEST_ENABLE_BT = 1;
private static final int REQUEST_DISCOVERABLE_BT = 2;
BluetoothAdapter bluetoothAdapter;
Button buttonTurnOn, buttonDiscoverable, buttonTurnOff;

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

bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
buttonTurnOn = findViewById(R.id.button1);
buttonDiscoverable = findViewById(R.id.button2);
buttonTurnOff = findViewById(R.id.button3);

if (bluetoothAdapter == null) {
Toast.makeText(this, "Bluetooth not supported on this device",
Toast.LENGTH_SHORT).show();
}

buttonTurnOn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!bluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
}
});

buttonDiscoverable.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!bluetoothAdapter.isDiscovering()) {
Intent discoverableBtIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
startActivityForResult(discoverableBtIntent,
REQUEST_DISCOVERABLE_BT);
}
}
});

buttonTurnOff.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bluetoothAdapter.disable();
Toast.makeText(getApplicationContext(), "Bluetooth Turned Off",
Toast.LENGTH_LONG).show();
}
});
}
}

5. Develop a program to implement:

i) ListView of 5 items
ii) GridView of 4x4 items

iii)ImageView

1. Layout: 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:orientation="vertical"
android:padding="16dp">

<!-- ListView -->


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

<!-- GridView -->


<GridView
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="4"
android:columnWidth="60dp"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"/>

<!-- ImageView -->


<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/sample_image" />

</LinearLayout>

2. Java Code: MainActivity.java


java
CopyEdit
package com.example.listviewgridviewimageview;

import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.GridView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

ListView listView;
GridView gridView;
ImageView imageView;

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

listView = findViewById(R.id.listView);
gridView = findViewById(R.id.gridView);
imageView = findViewById(R.id.imageView);

// ListView setup
String[] listItems = {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5"};
ArrayAdapter<String> listAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, listItems);
listView.setAdapter(listAdapter);

// GridView setup
String[] gridItems = new String[16]; // 4x4 grid
for (int i = 0; i < gridItems.length; i++) {
gridItems[i] = "Item " + (i + 1);
}
ArrayAdapter<String> gridAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, gridItems);
gridView.setAdapter(gridAdapter);

// ImageView setup
// You can replace "sample_image" with your image resource
imageView.setImageResource(R.drawable.sample_image);
}
}

6. Develop an application to store customer's details (ID, Name, Mobile No., Address, Pin-code) and

retrieve data using SQLite.

1. SQLite Helper: DatabaseHelper.java


java
CopyEdit
package com.example.customerdb;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {

private static final String DATABASE_NAME = "customer_db";


private static final int DATABASE_VERSION = 1;
private static final String TABLE_NAME = "customer";
private static final String COLUMN_ID = "id";
private static final String COLUMN_NAME = "name";
private static final String COLUMN_MOBILE = "mobile";
private static final String COLUMN_ADDRESS = "address";
private static final String COLUMN_PINCODE = "pincode";

public DatabaseHelper(Context context) {


super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME + " (" +
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
COLUMN_NAME + " TEXT, " +
COLUMN_MOBILE + " TEXT, " +
COLUMN_ADDRESS + " TEXT, " +
COLUMN_PINCODE + " TEXT);");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}

public void insertCustomer(String name, String mobile, String address, String


pincode) {
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("INSERT INTO " + TABLE_NAME + " (" +
COLUMN_NAME + ", " + COLUMN_MOBILE + ", " +
COLUMN_ADDRESS + ", " + COLUMN_PINCODE + ") VALUES ('" +
name + "', '" + mobile + "', '" + address + "', '" + pincode + "');");
db.close();
}

public Cursor getAllCustomers() {


SQLiteDatabase db = this.getReadableDatabase();
return db.rawQuery("SELECT * FROM " + TABLE_NAME, null);
}
}

2. Layout: 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:orientation="vertical"
android:padding="16dp">

<EditText android:id="@+id/editTextName" android:layout_width="match_parent"


android:layout_height="wrap_content" android:hint="Name"/>
<EditText android:id="@+id/editTextMobile" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="Mobile No."/>
<EditText android:id="@+id/editTextAddress" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="Address"/>
<EditText android:id="@+id/editTextPincode" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="Pin-code"/>
<Button android:id="@+id/buttonInsert" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Insert Data"/>
<Button android:id="@+id/buttonShow" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Show Customers"/>
<ListView android:id="@+id/listViewCustomers" android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

3. MainActivity: MainActivity.java
java
CopyEdit
package com.example.customerdb;

import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

EditText editTextName, editTextMobile, editTextAddress, editTextPincode;


Button buttonInsert, buttonShow;
ListView listViewCustomers;
DatabaseHelper databaseHelper;

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

editTextName = findViewById(R.id.editTextName);
editTextMobile = findViewById(R.id.editTextMobile);
editTextAddress = findViewById(R.id.editTextAddress);
editTextPincode = findViewById(R.id.editTextPincode);
buttonInsert = findViewById(R.id.buttonInsert);
buttonShow = findViewById(R.id.buttonShow);
listViewCustomers = findViewById(R.id.listViewCustomers);

databaseHelper = new DatabaseHelper(this);

buttonInsert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = editTextName.getText().toString();
String mobile = editTextMobile.getText().toString();
String address = editTextAddress.getText().toString();
String pincode = editTextPincode.getText().toString();

if (!name.isEmpty() && !mobile.isEmpty() && !address.isEmpty() && !


pincode.isEmpty()) {
databaseHelper.insertCustomer(name, mobile, address, pincode);
Toast.makeText(MainActivity.this, "Customer Inserted",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Please fill all fields",
Toast.LENGTH_SHORT).show();
}
}
});

buttonShow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Cursor cursor = databaseHelper.getAllCustomers();
if (cursor.getCount() == 0) {
Toast.makeText(MainActivity.this, "No Data Available",
Toast.LENGTH_SHORT).show();
} else {
StringBuilder customerDetails = new StringBuilder();
while (cursor.moveToNext()) {
customerDetails.append("ID: ").append(cursor.getInt(0)).append("\
n")
.append("Name: ").append(cursor.getString(1)).append("\
n")
.append("Mobile: ").append(cursor.getString(2)).append("\
n")
.append("Address:
").append(cursor.getString(3)).append("\n")
.append("Pin-code:
").append(cursor.getString(4)).append("\n\n");
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(MainActivity.this,
android.R.layout.simple_list_item_1, customerDetails.toString().split("\n\n"));
listViewCustomers.setAdapter(adapter);
}
}
});
}
}

7. Write a program to find the direction from user's current location to MSBTE, Bandra (Java + manifest
only).

<?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"
android:padding="16dp">

<Button
android:id="@+id/btnMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Navigate to MSBTE Bandra" />
</LinearLayout>
✅ AndroidManifest.xml (

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

✅ MainActivity.java (3 Marks)
java
Copy
Edit
package com.example.directionapp;

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

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

btnMap = findViewById(R.id.btnMap);

btnMap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri gmmIntentUri = Uri.parse("google.navigation:q=MSBTE+Bandra");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
}
});
}
}

8. Develop a program to convert Text to Speech.

✅ 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/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter text" />

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

✅ MainActivity.java
java
CopyEdit
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 editText;
Button button;

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

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

tts = new TextToSpeech(MainActivity.this, new TextToSpeech.OnInitListener() {


@Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
tts.setLanguage(Locale.US);
}
}
});

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String text = editText.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null, null);
}
});
}

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

9. Write a program to demonstrate 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 (3 Marks)
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;

public class MainActivity extends Activity {


Button btnDate, btnTime;

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnDate = findViewById(R.id.btnDate);
btnTime = findViewById(R.id.btnTime);

btnDate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Calendar c = Calendar.getInstance();
DatePickerDialog dp = new DatePickerDialog(MainActivity.this,
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();
}
});
}
}
10.Write a program to demonstrate declaring and using permissions (with relevant example).
Java
package com.example.permissiondemo;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

public class MainActivity extends AppCompatActivity {

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

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


btn.setOnClickListener(v -> {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
} else {
Toast.makeText(this, "Permission Already Granted", Toast.LENGTH_SHORT).show();
}
});
}

@Override
public void onRequestPermissionsResult(int reqCode, String[] permissions, int[] results) {
if (reqCode == 1 && results.length > 0) {
String msg = (results[0] == PackageManager.PERMISSION_GRANTED) ?
"Permission Granted" : "Permission Denied";
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
}
}
}

Xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">

<Button
android:id="@+id/btn"
android:text="Request Permission"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

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

11.Write a program to convert temperature from Celsius to Fahrenheit and vice versa using Toggle
button.
Java
package com.example.tempconverter;

import android.os.Bundle;
import android.view.View;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

EditText inputTemp;
ToggleButton toggle;
TextView result;

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

inputTemp = findViewById(R.id.inputTemp);
toggle = findViewById(R.id.toggle);
result = findViewById(R.id.result);

toggle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String value = inputTemp.getText().toString();
if (!value.isEmpty()) {
double temp = Double.parseDouble(value);
if (toggle.isChecked()) {
// Convert Celsius to Fahrenheit
double f = (temp * 9 / 5) + 32;
result.setText("Fahrenheit: " + f);
} else {
// Convert Fahrenheit to Celsius
double c = (temp - 32) * 5 / 9;
result.setText("Celsius: " + c);
}
} else {
result.setText("Enter Temperature");
}
}
});
}
}

Xml
<?xml version="1.0" encoding="utf-8"?>
<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">

<EditText
android:id="@+id/inputTemp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter temperature"
android:inputType="numberDecimal" />

<ToggleButton
android:id="@+id/toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="C to F"
android:textOff="F to C" />
<TextView
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="Result here" />
</LinearLayout>

12.Write a program to capture an image using camera and display it.

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"
android:paddingLeft="10dp"
android:paddingRight="10dp">

<Button
android:id="@+id/btnTakePicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Take a Photo"
android:textStyle="bold"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true" />

<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/capturedImage"
android:layout_above="@+id/btnTakePicture"/>
</RelativeLayout>

MainActivity.java
java
CopyEdit
package com.tutlane.cameraexample;

import android.content.Intent;
import android.graphics.Bitmap;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


private Button btnCapture;
private ImageView imgCapture;
private static final int Image_Capture_Code = 1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnCapture = (Button)findViewById(R.id.btnTakePicture);
imgCapture = (ImageView) findViewById(R.id.capturedImage);

btnCapture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cInt = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cInt, Image_Capture_Code);
}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == Image_Capture_Code) {
if (resultCode == RESULT_OK) {
Bitmap bp = (Bitmap) data.getExtras().get("data");
imgCapture.setImageBitmap(bp);
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
}
}
}
}

13.Write a program to implement Android Activity Life Cycle using toast messages.
Java
package com.example.lifecycle;

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

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.activity_main);
Toast.makeText(this, "onCreate", Toast.LENGTH_SHORT).show();
}

@Override
protected void onStart() {
super.onStart();
Toast.makeText(this, "onStart", Toast.LENGTH_SHORT).show();
}

@Override
protected void onResume() {
super.onResume();
Toast.makeText(this, "onResume", Toast.LENGTH_SHORT).show();
}
@Override
protected void onPause() {
super.onPause();
Toast.makeText(this, "onPause", Toast.LENGTH_SHORT).show();
}

@Override
protected void onStop() {
super.onStop();
Toast.makeText(this, "onStop", Toast.LENGTH_SHORT).show();
}

@Override
protected void onRestart() {
super.onRestart();
Toast.makeText(this, "onRestart", Toast.LENGTH_SHORT).show();
}

@Override
protected void onDestroy() {
super.onDestroy();
Toast.makeText(this, "onDestroy", Toast.LENGTH_SHORT).show();
}
}

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:text="Activity Life Cycle Example"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

14.Develop an application to display Google Map with user's current location.

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

public class MainActivity extends FragmentActivity implements OnMapReadyCallback {


GoogleMap map;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment mf = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map);
mf.getMapAsync(this);
}

public void onMapReady(GoogleMap googleMap) {


map = googleMap;
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED)
ActivityCompat.requestPermissions(this, new String[]
{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
else
map.setMyLocationEnabled(true);
}
}
Xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />

manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.maplocation">

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

<application
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:label="Map Location">

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

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

</application>
</manifest>

15. Design UI using TableLayout to display 0-9 number buttons, submit and clear button, and show

clicked numbers on Java

package com.example.tableinput;

import android.os.Bundle;

import android.view.View;

import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

StringBuilder input;

TextView display;

@Override

protected void onCreate(Bundle b) {

super.onCreate(b);

setContentView(R.layout.activity_main);

input = new StringBuilder();

display = findViewById(R.id.display);

int[] ids = {R.id.btn0, R.id.btn1, R.id.btn2, R.id.btn3, R.id.btn4,

R.id.btn5, R.id.btn6, R.id.btn7, R.id.btn8, R.id.btn9};

View.OnClickListener numberClickListener = new View.OnClickListener() {

@Override

public void onClick(View v) {

Button btn = (Button) v;

input.append(btn.getText().toString());

};

for (int id : ids) {

Button btn = findViewById(id);


btn.setOnClickListener(numberClickListener);

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

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

submit.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

display.setText("Clicked: " + input.toString());

});

clear.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

input.setLength(0);

display.setText("Clicked: ");

});

Xml

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

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

android:layout_width="match_parent"

android:layout_height="wrap_content"
android:stretchColumns="*"

android:padding="20dp">

<TextView

android:id="@+id/display"

android:text="Clicked: "

android:textSize="18sp"

android:padding="10dp"

android:layout_width="match_parent"

android:layout_height="wrap_content" />

<TableRow>

<Button android:id="@+id/btn1" android:text="1" />

<Button android:id="@+id/btn2" android:text="2" />

<Button android:id="@+id/btn3" android:text="3" />

</TableRow>

<TableRow>

<Button android:id="@+id/btn4" android:text="4" />

<Button android:id="@+id/btn5" android:text="5" />

<Button android:id="@+id/btn6" android:text="6" />

</TableRow>

<TableRow>

<Button android:id="@+id/btn7" android:text="7" />

<Button android:id="@+id/btn8" android:text="8" />

<Button android:id="@+id/btn9" android:text="9" />

</TableRow>
<TableRow>

<Button android:id="@+id/btn0" android:text="0" />

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

<Button android:id="@+id/clear" android:text="Clear" />

</TableRow>

</TableLayout>

16.Develop an Android application using RadioButton.


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

<RadioGroup android:id="@+id/group"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton android:id="@+id/opt1" android:text="Option A"/>
<RadioButton android:id="@+id/opt2" android:text="Option B"/>
</RadioGroup>

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


android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

Java
package com.example.radiodemo;

import android.os.Bundle;
import android.view.View;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.activity_main);

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


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

submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int id = group.getCheckedRadioButtonId();
if (id != -1) {
RadioButton selected = findViewById(id);
Toast.makeText(MainActivity.this, selected.getText(), Toast.LENGTH_SHORT).show();
}
}
});
}
}

17.Develop an application to perform addition, subtraction, multiplication, and division of two numbers.

18.Develop an application to convert 'thanks' text to speech.

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;

public class MainActivity extends AppCompatActivity {


TextToSpeech tts;

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

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

tts = new TextToSpeech(this, status -> {


if (status == TextToSpeech.SUCCESS) {
tts.setLanguage(Locale.US);
}
});

speakBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tts.speak("thanks", TextToSpeech.QUEUE_FLUSH, null, null);
}
});
}

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

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

19. Develop an application to update a record in SQLite where emp.id is 'E101'. Change name and

show updated record.


20.Develop a program to TURN ON and OFF Bluetooth.

Java
package com.example.bluetoothapp;

import android.bluetooth.BluetoothAdapter;
import android.os.Bundle;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


BluetoothAdapter bluetooth;

protected void onCreate(Bundle b) {


super.onCreate(b);

bluetooth = BluetoothAdapter.getDefaultAdapter();

Button on = new Button(this);


on.setText("Turn ON");
on.setOnClickListener(v -> {
if (!bluetooth.isEnabled())
bluetooth.enable();
});

Button off = new Button(this);


off.setText("Turn OFF");
off.setOnClickListener(v -> {
if (bluetooth.isEnabled())
bluetooth.disable();
});

LinearLayout layout = new LinearLayout(this);


layout.setOrientation(LinearLayout.VERTICAL);
layout.addView(on);
layout.addView(off);

setContentView(layout);
}
}
Manifest
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

21.Write a program to create first screen of a search engine using AutoCompleteTextView.

Java
package com.example.autocompletetest;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


String[] suggestions = {"Apple", "Banana", "Cherry", "Date", "Fig", "Grapes"};

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

AutoCompleteTextView autoText = findViewById(R.id.autoText);


ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_dropdown_item_1line, suggestions);
autoText.setAdapter(adapter);
}
}

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

<AutoCompleteTextView
android:id="@+id/autoText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Type here"
android:completionThreshold="1" />
</LinearLayout>

22.Develop Android application to enter a number and display its factorial on button click.

package com.example.factorialapp;

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

public class MainActivity extends AppCompatActivity {


EditText number;
Button calc;
TextView result;

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

number = findViewById(R.id.number);
calc = findViewById(R.id.calc);
result = findViewById(R.id.result);

calc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
int num = Integer.parseInt(number.getText().toString());
long fact = 1;
for (int i = 1; i <= num; i++) {
fact *= i;
}
result.setText("Factorial: " + fact);
});
}
}

Xml
<?xml version="1.0" encoding="utf-8"?>
<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">

<EditText
android:id="@+id/number"
android:hint="Enter a number"
android:inputType="number"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<Button
android:id="@+id/calc"
android:text="Find Factorial"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<TextView
android:id="@+id/result"
android:textSize="18sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"/>
</LinearLayout>

23.Write a program to show user's current location.

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

public class MainActivity extends FragmentActivity implements OnMapReadyCallback {


GoogleMap map;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment mf = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map);
mf.getMapAsync(this);
}

public void onMapReady(GoogleMap googleMap) {


map = googleMap;
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED)
ActivityCompat.requestPermissions(this, new String[]
{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
else
map.setMyLocationEnabled(true);
}
}
Xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />

manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.maplocation">

<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" />
</manifest>

24.Write a program to list all sensors supported by device.

25.Write a program to send email.

26.Write a program to show five CheckBoxes and toast selected ones using LinearLayout.

Java
package com.example.checkboxdemo;

import android.os.Bundle;
import android.view.View;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

CheckBox cb1, cb2, cb3, cb4, cb5;


Button btn;

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

cb1 = findViewById(R.id.cb1);
cb2 = findViewById(R.id.cb2);
cb3 = findViewById(R.id.cb3);
cb4 = findViewById(R.id.cb4);
cb5 = findViewById(R.id.cb5);
btn = findViewById(R.id.btnShow);

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
StringBuilder result = new StringBuilder("Selected: ");
if (cb1.isChecked()) result.append(cb1.getText()).append(" ");
if (cb2.isChecked()) result.append(cb2.getText()).append(" ");
if (cb3.isChecked()) result.append(cb3.getText()).append(" ");
if (cb4.isChecked()) result.append(cb4.getText()).append(" ");
if (cb5.isChecked()) result.append(cb5.getText());

Toast.makeText(getApplicationContext(), result.toString(), Toast.LENGTH_SHORT).show();


}
});
}
}

Xml
<?xml version="1.0" encoding="utf-8"?>
<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">

<CheckBox android:id="@+id/cb1" android:layout_width="wrap_content"


android:layout_height="wrap_content" android:text="Option 1" />

<CheckBox android:id="@+id/cb2" android:layout_width="wrap_content"


android:layout_height="wrap_content" android:text="Option 2" />

<CheckBox android:id="@+id/cb3" android:layout_width="wrap_content"


android:layout_height="wrap_content" android:text="Option 3" />

<CheckBox android:id="@+id/cb4" android:layout_width="wrap_content"


android:layout_height="wrap_content" android:text="Option 4" />

<CheckBox android:id="@+id/cb5" android:layout_width="wrap_content"


android:layout_height="wrap_content" android:text="Option 5" />

<Button android:id="@+id/btnShow" android:layout_width="wrap_content"


android:layout_height="wrap_content" android:text="Show Selected" />
</LinearLayout>

27.Develop Android app for student mark sheet using TableLayout (5 subjects, total, percentage).

xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:stretchColumns="1">

<TableRow>
<TextView android:text="Subject" />
<TextView android:text="Marks" />
</TableRow>

<TableRow>
<TextView android:text="Math" />
<EditText android:id="@+id/m1" android:inputType="number" />
</TableRow>

<TableRow>
<TextView android:text="Science" />
<EditText android:id="@+id/m2" android:inputType="number" />
</TableRow>

<TableRow>
<TextView android:text="English" />
<EditText android:id="@+id/m3" android:inputType="number" />
</TableRow>
<TableRow>
<TextView android:text="History" />
<EditText android:id="@+id/m4" android:inputType="number" />
</TableRow>

<TableRow>
<TextView android:text="Geography" />
<EditText android:id="@+id/m5" android:inputType="number" />
</TableRow>

<TableRow>
<Button
android:id="@+id/calc"
android:text="Calculate"
android:layout_span="2" />
</TableRow>

<TableRow>
<TextView android:text="Total" />
<TextView android:id="@+id/total" />
</TableRow>

<TableRow>
<TextView android:text="Percentage" />
<TextView android:id="@+id/percent" />
</TableRow>
</TableLayout>

java
package com.example.marksheet;

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

public class MainActivity extends AppCompatActivity {

EditText m1, m2, m3, m4, m5;


TextView total, percent;
Button calc;

protected void onCreate(Bundle b) {


super.onCreate(b);
setContentView(R.layout.activity_main);

m1 = findViewById(R.id.m1);
m2 = findViewById(R.id.m2);
m3 = findViewById(R.id.m3);
m4 = findViewById(R.id.m4);
m5 = findViewById(R.id.m5);
total = findViewById(R.id.total);
percent = findViewById(R.id.percent);
calc = findViewById(R.id.calc);

calc.setOnClickListener(v -> {
int a = Integer.parseInt(m1.getText().toString());
int b1 = Integer.parseInt(m2.getText().toString());
int c = Integer.parseInt(m3.getText().toString());
int d = Integer.parseInt(m4.getText().toString());
int e = Integer.parseInt(m5.getText().toString());

int t = a + b1 + c + d + e;
float p = t / 5f;

total.setText(String.valueOf(t));
percent.setText(p + "%");
});
}
}

28.Develop an application to store and retrieve student details using roll number in SQLite.

29.Write a program to demonstrate GridView and ImageView.

java
package com.example.simplegrid;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.activity_main);

GridView grid = findViewById(R.id.grid);


String[] items = {"A", "B", "C", "D", "E", "F"};
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,
items);
grid.setAdapter(adapter);
}
}

Xml
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3"
android:padding="20dp" />

Imageview java
package com.example.simpleimage;

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

public class MainActivity extends AppCompatActivity {


protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.activity_main);
}
}
Xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/ic_launcher_foreground" />
</LinearLayout>

30.Design a UI for employee registration form using components.


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:hint="Employee Name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<EditText
android:hint="Employee ID"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<EditText
android:hint="Email"
android:inputType="textEmailAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<EditText
android:hint="Phone Number"
android:inputType="phone"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<EditText
android:hint="Department"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Button
android:text="Register"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

31.Develop Android app for student feedback with DB connectivity.

32.Design an app to show list of paired Bluetooth devices.

33.Develop Android app to send SMS (Write XML, Java, Manifest).

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

public class MainActivity extends AppCompatActivity {


EditText etPhone, etMessage;
Button btnSend;

@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();
});
}
}

🔹 Minimal AndroidManifest.xml
xml
CopyEdit
<uses-permission android:name="android.permission.SEND_SMS" />

You might also like