Android File Real
Android File Real
(U.S Nagar)
Semester :– 5th
Session (2024-25)
Branch :- Computer Science & Engineering
Subject :- Android Application Development
Submitted To :- Submitted by :-
Mr. Kumar Gaurav
HOD C.S.E.
Index
Click on the “I have read and agree with the above terms and conditions”
checkbox followed by the download button.
Step 3: After the downloading has finished, open the file from downloads
and run it. It will prompt the following dialog box. Click on next. In the next
prompt, it’ll ask for a path for installation. Choose a path and hit next.
Step 4: It will start the installation, and once it is completed, it will be like
the image shown below.
Click on next.
Step 7: After it has found the SDK components, it will redirect to the
Welcome dialog box.
Click on Next.
Step 8: Now it is time to download the SDK components.
Click on finish
The Android Studio has been successfully configured. Now it’s time to
launch and build apps. Click on the Finish button to launch it.
Step 9: Click on Start a new Android Studio project to build a new app.
Practical No.-02
• Android Studio
• Eclipse
• AIDE
• Droid Script
Android Studio
This IDE covers all required use cases, alongside providing efficient
debugging, syntax checkup, easy-to-use integration with AVD emulators,
and SDK management. The Android Software Development Kit (SDK)
integrates seamlessly with Android Studio, offering a comprehensive set of
tools and features tailored specifically for Android development. Plus, it’s
completely free of charge for all use types!
• APK analyzer
• UI for browsing
• Lint static code analysis framework includes over 365 lint checks
across the entirety of your app
• Long list of small fixes and added support for the newest Gradle and
Android SDK versions
Eclipse
Eclipse is a free and open-source IDE that was initially developed by IBM
and is currently maintained by the Eclipse Foundation. Before the rise of
Android Studio, Eclipse was widely used with ADT (Android Development
Tools) to provide an integrated development environment for Android app
development. It’s one of the most popular IDEs on the market thanks to its
support for over 100 programming languages, including C++, JavaScript,
Ada, and Rust. Eclipse is a full-featured, powerful IDE that enables
developers to write top-class software, which is why it’s on our best IDEs
for Android development list.
Xamarin is a free and open-source mobile application platform. It’s used for
building native and high-performance iOS, Android, tvOS, watchOS,
macOS, and Windows apps in C#. Meanwhile, Visual Studio is the most
popular tool for writing code using C#. Visual Studio and Xamarin
streamline the entire app development process by providing a
comprehensive set of tools and features to accelerate development,
simplify integration of native device features, and offer debugging support.
AIDE
Features of AIDE:
• What You See Is What You Get (WYSIWYG) editor
• Fast prototyping
Droid Script
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:background="#F1F1F1"
android:paddingVertical="16dp"
android:id="@+id/buttons_layout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="360dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_c"
app:backgroundTint="#F44134"
android:text="C"/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="360dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_open_bracket"
app:backgroundTint="#8E8E8D"
android:text="("/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="360dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_close_bracket"
app:backgroundTint="#8E8E8D"
android:text=")"/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="360dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_divide"
app:backgroundTint="#FF9800"
android:text="/"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="360dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_7"
android:text="7"/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="360dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_8"
android:text="8"/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="360dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_9"
android:text="9"/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="360dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_multiply"
app:backgroundTint="#FF9800"
android:text="X"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="360dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_4"
android:text="4"/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="360dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_5"
android:text="5"/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="360dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_6"
android:text="6"/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="360dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_plus"
app:backgroundTint="#FF9800"
android:text="+"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="360dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_1"
android:text="1"/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="360dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_2"
android:text="2"/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="360dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_3"
android:text="3"/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="360dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_minus"
app:backgroundTint="#FF9800"
android:text="-"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="360dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:textSize="20dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_ac"
app:backgroundTint="#F44336"
android:text="AC"/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="360dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_0"
android:text="0"/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="360dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_dot"
android:text="."/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="360dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_equals"
app:backgroundTint="#FF9800"
android:text="="/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
MainActivity.java
package com.example.myapplication;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import com.google.android.material.button.MaterialButton;
TextView resultTv,solutionTv;
MaterialButton buttonC,buttonBrackOpen,buttonBrackClose;
MaterialButton
buttonDivide,buttonMultiply,buttonPlus,buttonMinus,buttonEquals;
MaterialButton
button0,button1,button2,button3,button4,button5,button6,button7,button8,
button9;
MaterialButton buttonAC,buttonDot;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
resultTv=findViewById(R.id.result_tv);
solutionTv=findViewById(R.id.solution_tv);
assignId(buttonC,R.id.button_c);
assignId(buttonBrackOpen,R.id.button_open_bracket);
assignId(buttonBrackClose,R.id.button_close_bracket);
assignId(buttonDivide,R.id.button_divide);
assignId(buttonMultiply,R.id.button_multiply);
assignId(buttonPlus,R.id.button_plus);
assignId(buttonMinus,R.id.button_minus);
assignId(buttonEquals,R.id.button_equals);
assignId(button0,R.id.button_0);
assignId(button1,R.id.button_1);
assignId(button2,R.id.button_2);
assignId(button3,R.id.button_3);
assignId(button4,R.id.button_4);
assignId(button5,R.id.button_5);
assignId(button6,R.id.button_6);
assignId(button7,R.id.button_7);
assignId(button8,R.id.button_8);
assignId(button9,R.id.button_9);
assignId(buttonAC,R.id.button_ac);
assignId(buttonDot,R.id.button_dot);
}
if(buttonText.equals("AC")){
solutionTv.setText("");
resultTv.setText("0");
return;
}
if(buttonText.equals("=")){
solutionTv.setText(resultTv.getText());
return;
}
if(buttonText.equals("C")){
dataToCalculate=dataToCalculate.substring(0,dataToCalculate.length()-
1);
}
else{
dataToCalculate=dataToCalculate+buttonText;
}
solutionTv.setText(dataToCalculate);
String finalResult=getResult(dataToCalculate);
if(!finalResult.equals("Err")){
resultTv.setText(finalResult);
}
}
String getResult(String data){
try{
Context context=Context.enter();
context.setOptimizationLevel(-1);
Scriptable scriptable=context.initStandardObjects();
String finalResult=
context.evaluateString(scriptable,data,"Javascript",1,null).toString();
if (finalResult.endsWith(".0")){
finalResult=finalResult.replace(".0","");
}
return finalResult;
}
catch (Exception e){
return "Err";
}
}
}
Output:-
Practical No.-04
Development an Application for working with Menus
and screen navigation.
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start"
android:id="@+id/drawerLayout"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<include
layout="@layout/activity_main_content"/>
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigationView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="@menu/drawer_items"
app:itemIconPadding="30dp"
app:dividerInsetStart="60dp"
app:headerLayout="@layout/drawer_header"
android:layout_gravity="start"/>
</androidx.drawerlayout.widget.DrawerLayout>
activity_main_content.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#D5D4D4">
<ImageButton
android:id="@+id/buttonDrawerToggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/drawer_menu"
android:background="@android:color/transparent"
android:padding="10dp"/>
</androidx.appcompat.widget.Toolbar>
</LinearLayout>
drawer_header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:padding="20dp"
android:background="#00BCD4"
android:gravity="bottom"
android:layout_height="180dp">
<androidx.cardview.widget.CardView
android:layout_width="60dp"
android:layout_height="60dp"
app:cardCornerRadius="40dp"
app:cardElevation="0dp"
android:backgroundTint="#C1BDBD">>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/person"/>
</androidx.cardview.widget.CardView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="User Name"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:textColor="@color/black"
android:textStyle="bold"
android:textSize="15sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="User Email"
android:textColor="#646363"
android:textStyle="normal"
android:textSize="13sp"/>
</LinearLayout>
drawer_items.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group
android:id="@+id/group1">
<item
android:icon="@drawable/menu"
android:id="@+id/navMenu"
android:title="Menu"/>
<item
android:icon="@drawable/cart"
android:id="@+id/navCart"
android:title="Cart"/>
<item
android:icon="@drawable/favourite"
android:id="@+id/navFavourite"
android:title="Favourite"/>
</group>
<group
android:id="@+id/group2">
<item
android:icon="@drawable/ongoing"
android:id="@+id/navOrders"
android:title=" Ongoing Orders"/>
<item
android:icon="@drawable/history"
android:id="@+id/navHistory"
android:title="History"/>
</group>
<group
android:id="@+id/group3">
<item
android:icon="@drawable/feedback"
android:id="@+id/navFeedback"
android:title="Feedback"/>
<item
android:icon="@drawable/terms"
android:id="@+id/navTerms"
android:title="Terms and Conditions"/>
<item
android:icon="@drawable/contact"
android:id="@+id/navContact"
android:title="Contact us"/>
</group>
<group
android:id="@+id/group4">
<item
android:icon="@drawable/share"
android:id="@+id/navShare"
android:title="Share"/>
</group>
</menu>
Main_activity.java
package com.example.drawernavigation;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import com.google.android.material.navigation.NavigationView;
DrawerLayout drawerLayout;
ImageButton buttonDrawerToggle;
NavigationView navigationView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
drawerLayout=findViewById(R.id.drawerLayout);
buttonDrawerToggle=findViewById(R.id.buttonDrawerToggle);
navigationView=findViewById(R.id.navigationView);
buttonDrawerToggle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
drawerLayout.open();
}
});
navigationView.setNavigationItemSelectedListener(new
NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int itemiId= item.getItemId();
if(itemiId==R.id.navMenu){
Toast.makeText(MainActivity.this,"Menu
Clicked",Toast.LENGTH_SHORT).show();
}
if(itemiId==R.id.navCart){
Toast.makeText(MainActivity.this,"Cart
Clicked",Toast.LENGTH_SHORT).show();
}
if(itemiId==R.id.navOrders){
Toast.makeText(MainActivity.this,"Ongoing Order
Clicked",Toast.LENGTH_SHORT).show();
}
if(itemiId==R.id.navHistory){
Toast.makeText(MainActivity.this,"History
Clicked",Toast.LENGTH_SHORT).show();
}
if(itemiId==R.id.navFavourite){
Toast.makeText(MainActivity.this,"Favourite
Clicked",Toast.LENGTH_SHORT).show();
}
if(itemiId==R.id.navContact){
Toast.makeText(MainActivity.this,"Contact
Clicked",Toast.LENGTH_SHORT).show();
}
if(itemiId==R.id.navFeedback){
Toast.makeText(MainActivity.this,"Feedback
Clicked",Toast.LENGTH_SHORT).show();
}
if(itemiId==R.id.navTerms){
Toast.makeText(MainActivity.this,"Terms and Conditions
Clicked",Toast.LENGTH_SHORT).show();
}
if(itemiId==R.id.navShare){
Toast.makeText(MainActivity.this,"Share
Clicked",Toast.LENGTH_SHORT).show();
}
drawerLayout.close();
return false;
}
});
}
}
Output:-
Practical:5
Develop an application demonstrating internal storage to
store private data on the device memory.
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView2"
android:layout_width="337dp"
android:layout_height="28dp" android:text="
File Content "
android:textAlignment="center"
android:textColor="#000"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.52" />
<Button
android:id="@+id/write_button"
android:layout_width="wrap_content"
android:layout_height="48dp" android:layout_marginStart="160dp"
android:layout_marginEnd="159dp"
android:layout_marginBottom="16dp"
android:text="Write"
app:layout_constraintBottom_toTopOf="@+id/read_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.904" />
<Button
android:id="@+id/read_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="160dp"
android:layout_marginEnd="158dp"
android:layout_marginBottom="48dp"
android:text="Read"
app:layout_constraintBottom_toTopOf="@+id/textView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent" />
<EditText
android:id="@+id/userInput"
android:layout_width="319dp"
android:layout_height="50dp"
android:layout_marginStart="46dp"
android:layout_marginTop="91dp"
android:layout_marginEnd="46dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/content"
android:layout_width="332dp"
android:layout_height="306dp"
android:layout_marginStart="33dp"
android:layout_marginTop="21dp"
android:layout_marginEnd="33dp"
android:layout_marginBottom="6dp"
android:text=""
android:textAlignment="center"
android:textColor="#000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.461"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2"
app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.internalstorage;
import android.content.Context;
import android.os.Bundle; import
android.view.View; import
android.widget.Button; import
android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import java.io.IOException;
EditText userInput;
TextView fileContent;
@Override
return insets;
});
fileContent = findViewById(R.id.content);
@Override
// Get the button text: either 'read' or 'write' depending on the button
pressed
switch (b_text.toLowerCase()) {
case "write": {
writeData(); break;
case "read": {
readData(); break;
}
private void writeData() {
try {
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
try {
temp.append((char) a);
fileContent.setText(temp.toString());
fin.close();
} catch (IOException e) {
e.printStackTrace();
}
// A simple method to print messages to the fileContent TextView
private void printMessage(String message) {
fileContent.append("\n" + message);
}}
OUTPUT
Practical: 6
Design a simple to-do list application using SQLite
MainActivity.java
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/AppName"
android:layout_centerHorizontal="true"
android:textColor="#ff18be1c" android:textSize="20dp/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/input1"
android:layout_below="@+id/AppName"
android:id="@+id/EText1"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/input2"
android:layout_below="@+id/EText1"
android:id="@+id/EText2"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/EText2"
android:text="@string/submit"
android:onClick="addNew"
android:id="@+id/button"
android:layout_centerHorizontal="true"
android:textColor="#ff725fee"
/>
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/newlist"
android:layout_below="@+id/button">
</ListView>
DataBaseHelper.java
package com.example.to Do.List; import
android.content.ContentValues; import
SQLiteDatabase db = this.getWritableDatabase();
values.put(COLUMN_1,s1); values.put(COLUMN_2,s2);
db.insert(TABLE,null,values);
db.close();
SQLiteDatabase db = this.getReadableDatabase();
return db.rawQuery(str,null);
onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE);
onCreate(db);
}
Tasks.xml
OUTPUT
Practical:7
Develop an application for connecting to the internet and
sending email.
MainActivity.java
package com.example.sendingEmail;
import android.net.Uri; import
android.os.Bundle; import
android.app.Activity; import
android.content.Intent; import
android.util.Log; import
android.view.Menu; import
android.view.View; import
android.widget.Button; import
android.widget.Toast; public class
MainActivity extends Activity {
Activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="30dp" />
<TextView android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ff87ff09"
android:textSize="30dp"
android:layout_above="@+id/imageButton"
android:layout_alignRight="@+id/imageButton"
android:layout_alignEnd="@+id/imageButton" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:src="@drawable/abc"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button android:id="@+id/sendEmail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/compose_email"/>
</LinearLayout>
OUTPUT
Practical-8
Develop an application for working with graphics and
animations
(Animation)
activity_main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:id="@+id/imageView"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/ic_launcher_foreground"
android:layout_centerInParent="true" />
<Button
android:id="@+id/animateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Animate"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="30dp" />
</RelativeLayout>
MainActivity.java
package com.example.animationapp; import
android.animation.ObjectAnimator; import
android.os.Bundle;
android.widget.Button; import
android.widget.ImageView; import
androidx.appcompat.app.AppCompatActivity; public
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
animateButton.setOnClickListener(new View.OnClickListener() {
@Override public
void onClick(View v) {
animator.setDuration(1000); // 1 second
animator.start();
});
OUTPUT--
(Graphics)
MainActivity.java
package com.example.simplegraphics;
import android.os.Bundle; import
android.app.Activity; import
android.view.Menu; import
android.content.Context; import
android.graphics.Canvas; import
android.graphics.Color; import
android.graphics.Paint; import
android.view.View; public class
MainActivity extends Activity {
DemoView demoview;
@Override public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
demoview = new DemoView(this);
setContentView(demoview);
}
private class DemoView extends View{
public DemoView(Context context){
super(context);
}
@Override protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
canvas.drawPaint(paint); paint.setAntiAlias(false);
paint.setColor(Color.BLUE);
canvas.drawCircle(20, 20, 15, paint);
paint.setAntiAlias(true);
paint.setColor(Color.GREEN);
canvas.drawCircle(60, 20, 15, paint);
paint.setAntiAlias(false);
paint.setColor(Color.RED); canvas.drawRect(100, 5,
200, 30, paint);
canvas.rotate(-45);
paint.setStyle(Paint.Style.FILL);
canvas.drawText("Graphics Rotation", 40, 180, paint);
canvas.restore();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
activity_main.xml
<RelativeLayout xmlns: androidclass="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
OUTPUT
Pratctical-9
Develop an application for working with location based
service
activity_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical" android:layout_gravity="center"
android:gravity="center"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:src="@drawable/location"
android:layout_width="200dp"
android:layout_height="200dp"/>
<TextView
android:id="@+id/text_location"
android:textSize="18sp"
android:textStyle="bold"
android:layout_margin="10dp"
android:text="Current Location"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/button_location"
android:text="Get Location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
MainActivity.java
package com.example.mycurrentlocation; import
androidx.appcompat.app.AppCompatActivity; import
androidx.core.app.ActivityCompat; import
androidx.core.content.ContextCompat; import
android.Manifest; import
android.annotation.SuppressLint; import
android.content.pm.PackageManager; import
android.location.Address; import
android.location.Geocoder; import
android.location.Location; import
android.location.LocationListener; import
android.location.LocationManager; import
android.widget.Button; import
android.widget.TextView; import
android.widget.Toast;
Button button_location;
TextView textView_location;
LocationManager locationManager;
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView_location = findViewById(R.id.text_location);
button_location = findViewById(R.id.button_location);
//Runtime permissions
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(MainActivity.this,new String[]{
Manifest.permission.ACCESS_FINE_LOCATION
},100);
button_location.setOnClickListener(new View.OnClickListener() {
@Override public
void onClick(View v) {
//create method
getLocation();
});
@SuppressLint("MissingPermission")
try {
locationManager = (LocationManager)
getApplicationContext().getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,5000,5,MainActivity.thi
s
);
e.printStackTrace();
}
@Override public void
onLocationChanged(Location location) {
Toast.makeText(this, ""+location.getLatitude()+","+location.getLongitude(),
Toast.LENGTH_SHORT).show();
try {
List<Address> addresses =
geocoder.getFromLocation(location.getLatitude(),location.getLongitude(),1);
textView_location.setText(address);
e.printStackTrace();
Bundle extras) {
onProviderEnabled(String provider) {
onProviderDisabled(String provider) {
}
OUTPUT
Practical 10
Develop an application for working with device camera.
MainActivity.java
package com.example.cameraapp; import
android.app.Activity; import
android.content.Intent; import
android.os.Bundle; import
android.provider.MediaStore; import
android.view.Menu; import
android.view.View; import
android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn=(Button)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" android:orientation="vertical">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="81dp"
android:layout_marginTop="54dp"
android:text="Button" />
</RelativeLayout>
</android>
OUTPUT