LUKHDHIRJI ENGINEERING COLLEGE
Certificate
This is to certify that Mr. / Ms. ___________________________________
________ Enrollment No. _______________of B.E. Semester _____
Information Technology of this Institute (GTU Code: 016) has satisfactorily
completed the Practical / Tutorial work for the subject Mobile App. Dev. for the
academic year 2024-25.
Place: __________
Date: __________
Name and Sign of Faculty Member
Index
Sr. No. Objective(s) of Experiment Date Sign
1 Calculator App
2 Currency Converter App (INR to
USD)
3 Library Overdue Counter App
4 Ball Size and Color Animation
5 Mark Daily Route on Map
6 Record and Play Audio/Video
(Topic: Intent)
7 Hello World Android App
8 Activity Navigation Using Intents
9 Fragment Example
10 Using AutoCompleteTextView
11 Orientation Change Handling
12 Handling Button Click
13 Creating Options Menu
14 Internal Storage
15 External Storage
16 SQLite Database Example
1. Calculator App
What: Simple calculator that performs addition, subtraction, multiplication, and
division.
// MainActivity.java
public class MainActivity extends AppCompatActivity {
EditText num1, num2;
TextView result;
Button add, sub, mul, div;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
num1 = findViewById(R.id.num1);
num2 = findViewById(R.id.num2);
result = findViewById(R.id.result);
add = findViewById(R.id.add);
sub = findViewById(R.id.sub);
mul = findViewById(R.id.mul);
div = findViewById(R.id.div);
add.setOnClickListener(v -> calculate("+"));
sub.setOnClickListener(v -> calculate("-"));
mul.setOnClickListener(v -> calculate("*"));
div.setOnClickListener(v -> calculate("/"));
}
private void calculate(String op) {
double a = Double.parseDouble(num1.getText().toString());
double b = Double.parseDouble(num2.getText().toString());
double res = 0;
switch (op) {
case "+": res = a + b; break;
case "-": res = a - b; break;
case "*": res = a * b; break;
case "/": res = a / b; break;
}
result.setText("Result: " + res);
}
}
2. Currency Converter App (INR to USD)
// MainActivity.java
public class MainActivity extends AppCompatActivity {
EditText inr;
TextView usd;
Button convert;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
inr = findViewById(R.id.inr);
usd = findViewById(R.id.usd);
convert = findViewById(R.id.convert);
convert.setOnClickListener(v -> {
double rupee = Double.parseDouble(inr.getText().toString());
double dollar = rupee / 83.0;
usd.setText("USD: $" + String.format("%.2f", dollar));
});
}
}
3. Library Overdue Counter App
What: Calculate overdue days and fine (e.g., ₹5 per day).
// MainActivity.java
public class MainActivity extends AppCompatActivity {
EditText issueDate, returnDate;
TextView result;
Button calc;
@SuppressLint("SimpleDateFormat")
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
issueDate = findViewById(R.id.issueDate);
returnDate = findViewById(R.id.returnDate);
result = findViewById(R.id.result);
calc = findViewById(R.id.calc);
calc.setOnClickListener(v -> {
try {
Date issue = sdf.parse(issueDate.getText().toString());
Date ret = sdf.parse(returnDate.getText().toString());
long diff = ret.getTime() - issue.getTime();
long days = TimeUnit.DAYS.convert(diff,
TimeUnit.MILLISECONDS);
long fine = days > 15 ? (days - 15) * 5 : 0;
result.setText("Days: " + days + "\nFine: ₹" + fine);
} catch (ParseException e) {
result.setText("Invalid date format.");
}
});
}
}
4. Ball Size and Color Animation
What: Animate a ball (View) that changes size and color every 20 seconds and
rotates.
// MainActivity.java
public class MainActivity extends AppCompatActivity {
View ball;
int[] sizes = {100, 200, 300};
int[] colors = {Color.RED, Color.BLUE, Color.GREEN};
int current = 0;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ball = new View(this);
setContentView(ball);
animateBall();
}
private void animateBall() {
ball.setBackgroundColor(colors[current]);
ball.setLayoutParams(new ViewGroup.LayoutParams(sizes[current],
sizes[current]));
RotateAnimation rotate = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(60000);
rotate.setRepeatCount(Animation.INFINITE);
ball.startAnimation(rotate);
new Handler().postDelayed(() -> {
current = (current + 1) % 3;
animateBall();
}, 60000);
}
}
5. Mark Daily Route on Map
What: Show user’s daily travel route using Google Maps and
FusedLocationProviderClient.
// MainActivity.java (add map and location permissions in Manifest)
public class MainActivity extends FragmentActivity implements
OnMapReadyCallback {
private GoogleMap mMap;
FusedLocationProviderClient fusedLocationClient;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
fusedLocationClient =
LocationServices.getFusedLocationProviderClient(this);
}
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
fusedLocationClient.getLastLocation().addOnSuccessListener(this,
location -> {
if (location != null) {
LatLng current = new LatLng(location.getLatitude(),
location.getLongitude());
mMap.addMarker(new MarkerOptions().position(current).title("Start
Point"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(current,
15));
}
});
}
}
6. Record and Play Audio/Video (Topic: Intent)
What: Record and playback audio/video using intents.
// Start recording video
Intent takeVideoIntent = new
Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(takeVideoIntent, 101);
// Start recording audio
Intent recordAudioIntent = new
Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
startActivityForResult(recordAudioIntent, 102);
// Playing recorded media
MediaPlayer mediaPlayer = MediaPlayer.create(this, videoOrAudioUri);
mediaPlayer.start();
7. Hello World Android App
What: A basic app to print "Hello World" on the screen.
// MainActivity.java
package com.example.helloworld;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView text = new TextView(this);
text.setText("Hello World");
setContentView(text);
}
}
9. Fragment Example
What: Demonstrate switching between fragments in an activity.
MainActivity.java
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val buttonFragmentOne =
findViewById<Button>(R.id.button_fragment_one)
val buttonFragmentTwo =
findViewById<Button>(R.id.button_fragment_two)
buttonFragmentOne.setOnClickListener {
supportFragmentManager.beginTransaction()
.replace(R.id.fragment_container, FragmentOne())
.commit()
}
buttonFragmentTwo.setOnClickListener {
supportFragmentManager.beginTransaction()
.replace(R.id.fragment_container, FragmentTwo())
.commit()
}
}
}
<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">
<Button
android:id="@+id/button_fragment_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Load Fragment One" />
<Button
android:id="@+id/button_fragment_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Load Fragment Two" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp"/>
</LinearLayout>
10. Using AutoCompleteTextView
What: Implement AutoCompleteTextView with suggestions.
activity_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:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Country Name:"
android:textSize="16sp"/>
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Type here..."
android:textSize="16sp"/>
</LinearLayout>
MainActivity.java:
package com.example.autocompletetextviewexample;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class MainActivity extends AppCompatActivity {
// Sample country list for suggestions
String[] countries = {
"India", "Indonesia", "United States", "United Kingdom",
"Australia", "Austria", "Brazil", "Bangladesh",
"Canada", "China", "Denmark", "Egypt", "France",
"Germany", "Greece", "Japan", "Kenya", "Mexico",
"Netherlands", "Norway", "Pakistan", "Russia",
"Saudi Arabia", "South Africa", "Sri Lanka",
"Sweden", "Switzerland", "Thailand", "United Arab Emirates"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize AutoCompleteTextView
AutoCompleteTextView autoCompleteTextView =
findViewById(R.id.autoCompleteTextView);
// Create ArrayAdapter with country list
ArrayAdapter<String> adapter = new ArrayAdapter<>(
this,
android.R.layout.simple_dropdown_item_1line,
countries
);
// Set the adapter to the AutoCompleteTextView
autoCompleteTextView.setAdapter(adapter);
// Set the threshold (minimum characters to start suggesting)
autoCompleteTextView.setThreshold(1);
}
}
12. Handling Button Click
What: Show a Toast message on button click.
<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/button_show_toast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Toast" />
</LinearLayout>
package com.example.toastmessageexample;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize the Button
Button buttonShowToast = findViewById(R.id.button_show_toast);
// Set OnClickListener for the Button
buttonShowToast.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Displaying a Toast message
Toast.makeText(MainActivity.this, "Hello, this is a Toast message!",
Toast.LENGTH_SHORT).show();
}
});
}
}
13. Creating Options Menu
What: Create an options menu with items.
<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">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select an option from the menu"
android:textSize="18sp"/>
</LinearLayout>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_option_one"
android:title="Option One"/>
<item
android:id="@+id/menu_option_two"
android:title="Option Two"/>
<item
android:id="@+id/menu_option_three"
android:title="Option Three"/>
</menu>
package com.example.optionsmenuexample;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize the TextView
textView = findViewById(R.id.textView);
}
// Create the Options Menu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_main, menu);
return true;
}
// Handle Menu Item Clicks
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_option_one:
textView.setText("You selected Option One");
Toast.makeText(this, "Option One Selected",
Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_option_two:
textView.setText("You selected Option Two");
Toast.makeText(this, "Option Two Selected",
Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_option_three:
textView.setText("You selected Option Three");
Toast.makeText(this, "Option Three Selected",
Toast.LENGTH_SHORT).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
14. Internal Storage
What: Save and retrieve data from internal storage.
<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"
android:gravity="center">
<EditText
android:id="@+id/editTextData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your data here" />
<Button
android:id="@+id/buttonSave"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Save Data" />
<Button
android:id="@+id/buttonLoad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Load Data"
android:layout_marginTop="8dp"/>
<TextView
android:id="@+id/textViewData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Loaded data will appear here"
android:paddingTop="16dp"
android:textSize="16sp"/>
</LinearLayout>
package com.example.internalstorageexample;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
private static final String FILE_NAME = "mydata.txt";
EditText editTextData;
TextView textViewData;
Button buttonSave, buttonLoad;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextData = findViewById(R.id.editTextData);
textViewData = findViewById(R.id.textViewData);
buttonSave = findViewById(R.id.buttonSave);
buttonLoad = findViewById(R.id.buttonLoad);
// Save Data to Internal Storage
buttonSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saveData();
}
});
// Load Data from Internal Storage
buttonLoad.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadData();
}
});
}
// Method to Save Data
private void saveData() {
String data = editTextData.getText().toString();
FileOutputStream fos = null;
try {
fos = openFileOutput(FILE_NAME, MODE_PRIVATE);
fos.write(data.getBytes());
editTextData.setText(""); // Clear input after saving
Toast.makeText(this, "Data saved to " + FILE_NAME,
Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
} }}
// Method to Load Data
private void loadData() {
FileInputStream fis = null;
try {
fis = openFileInput(FILE_NAME);
StringBuilder sb = new StringBuilder();
int character;
while ((character = fis.read()) != -1) {
sb.append((char) character);
}
textViewData.setText(sb.toString());
} catch (IOException e) {
e.printStackTrace();
textViewData.setText("No data found.");
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
16. SQLite Database Example
What: Insert and read data from SQLite.
<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"
android:gravity="center">
<EditText
android:id="@+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Name" />
<EditText
android:id="@+id/editTextAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Age"
android:inputType="number" />
<Button
android:id="@+id/buttonInsert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Insert Data"
android:layout_marginTop="8dp"/>
<Button
android:id="@+id/buttonView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="View Data"
android:layout_marginTop="8dp"/>
<TextView
android:id="@+id/textViewResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Data will appear here"
android:textSize="16sp"
android:paddingTop="16dp"/>
</LinearLayout>
package com.example.sqliteexample;
import android.content.ContentValues;
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 = "UserData.db";
private static final String TABLE_NAME = "user_table";
private static final String COL_1 = "ID";
private static final String COL_2 = "NAME";
private static final String COL_3 = "AGE";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME + " (ID INTEGER
PRIMARY KEY AUTOINCREMENT, NAME TEXT, AGE INTEGER)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
// Method to Insert Data
public boolean insertData(String name, int age) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_2, name);
contentValues.put(COL_3, age);
long result = db.insert(TABLE_NAME, null, contentValues);
return result != -1; // If result is -1, insertion failed
}
// Method to Read Data
public Cursor getAllData() {
SQLiteDatabase db = this.getWritableDatabase();
return db.rawQuery("SELECT * FROM " + TABLE_NAME, null);
}
}
package com.example.sqliteexample;
import androidx.appcompat.app.AppCompatActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText editTextName, editTextAge;
Button buttonInsert, buttonView;
TextView textViewResult;
DatabaseHelper databaseHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize UI Components
editTextName = findViewById(R.id.editTextName);
editTextAge = findViewById(R.id.editTextAge);
buttonInsert = findViewById(R.id.buttonInsert);
buttonView = findViewById(R.id.buttonView);
textViewResult = findViewById(R.id.textViewResult);
// Initialize Database Helper
databaseHelper = new DatabaseHelper(this);
// Insert Data
buttonInsert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = editTextName.getText().toString();
String ageText = editTextAge.getText().toString();
if (name.isEmpty() || ageText.isEmpty()) {
Toast.makeText(MainActivity.this, "Please enter all details",
Toast.LENGTH_SHORT).show();
return;
}
int age = Integer.parseInt(ageText);
boolean isInserted = databaseHelper.insertData(name, age);
if (isInserted) {
Toast.makeText(MainActivity.this, "Data Inserted",
Toast.LENGTH_SHORT).show();
editTextName.setText("");
editTextAge.setText("");
} else {
Toast.makeText(MainActivity.this, "Insertion Failed",
Toast.LENGTH_SHORT).show();
}
}
});
// View Data
buttonView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Cursor cursor = databaseHelper.getAllData();
if (cursor.getCount() == 0) {
textViewResult.setText("No Data Found");
return;
}
StringBuilder sb = new StringBuilder();
while (cursor.moveToNext()) {
sb.append("ID: ").append(cursor.getString(0)).append("\n");
sb.append("Name: ").append(cursor.getString(1)).append("\n");
sb.append("Age: ").append(cursor.getString(2)).append("\n\n");
}
textViewResult.setText(sb.toString());
cursor.close();
}
});
}
}