Record
Record
Record
Index
1
191CSC611L 310619104019
AIM
To develop an application that uses GUI components, layout manager and event
listener.
ALGORITHM
Step 1: Open Android Studio and then click on File New New Project.
Step 2: Type the Application name as “exno1” and click Next.
Step 3: Select Empty Activity and click Next.
Step 4: Click Finish.
Step 5: It will build and load the project.
Step 6: Click on app res layout activity_main.xml and design the layout.
Step 7: Click on app java com.example.exno1 MainActivity and type the java code.
Step 8: Run the project.
PROGRAM
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="200dp"
android:gravity="center"
android:text="0"
android:textSize="24sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
2
191CSC611L 310619104019
<Button
android:id="@+id/increase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="105dp"
android:layout_marginRight="20dp"
android:gravity="center"
android:text="Next" />
<Button
android:id="@+id/decrease"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Prev" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
MainActivity.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
3
191CSC611L 310619104019
@Override
public void onClick (View view){
if(counter!=0) {
counter--;
tv.setText(Integer.toString(counter));
}
}
});
}
}
OUTPUT
RESULT:
Thus a simple android application that uses GUI components, layout manager and
event listener has been developed and executed successfully.
4
191CSC611L 310619104019
AIM
To develop an application to stimulate a keyboard.
ALGORITHM
Step 1: Open Android Studio and then click on File New New Project.
Step 2: Type the Application name as “exno2” and click Next.
Step 3: Select Empty Activity and click Next.
Step 4: Click Finish.
Step 5: It will build and load the project.
Step 6: Click on app res layout activity_main.xml and design the layout.
Step 7: Click on app java com.example.exno2 MainActivity and type the java code.
Step 8: Run the project.
PROGRAM
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="200dp"
android:gravity="center"
android:text=""
android:scrollbars="vertical"/>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
5
191CSC611L 310619104019
android:layout_marginLeft="75dp"
android:layout_marginTop="50dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5" />
<Button
6
191CSC611L 310619104019
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">
<Button
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter" />
<Button
android:id="@+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0" />
<Button
android:id="@+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete" />
</TableRow>
</TableLayout>
</LinearLayout>
</RelativeLayout>
MainActivity.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
7
191CSC611L 310619104019
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv = (TextView) findViewById(R.id.textView);
Button one = (Button) findViewById(R.id.button);
one.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tv.append("1");
}
});
Button two = (Button) findViewById(R.id.button2);
two.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tv.append("2");
}
});
Button three = (Button) findViewById(R.id.button3);
three.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tv.append("3");
}
});
Button four = (Button) findViewById(R.id.button4);
four.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tv.append("4");
}
});
Button five = (Button) findViewById(R.id.button5);
five.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tv.append("5");
}
});
Button six = (Button) findViewById(R.id.button6);
six.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tv.append("6");
}
});
Button enter = (Button) findViewById(R.id.button7);
8
191CSC611L 310619104019
enter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tv.append("\n");
}
});
Button zero = (Button) findViewById(R.id.button8);
zero.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tv.append("0");
}
});
Button del = (Button) findViewById(R.id.button9);
del.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(tv.getText().toString().length()!=0)
tv.setText(tv.getText().toString().substring(0,tv.getText().toString().length()-1));
}
});
}
}
9
191CSC611L 310619104019
OUTPUT
RESULT:
Thus an android application that stimulates a keyboard has been developed and
executed successfully.
10
191CSC611L 310619104019
AIM
To develop an application that uses graphical primitive.
ALGORITHM
Step 1: Open Android Studio and then click on File New New Project.
Step 2: Type the Application name as “exno3” and click Next.
Step 3: Select Empty Activity and click Next.
Step 4: Click Finish.
Step 5: It will build and load the project.
Step 6: Click on app res layout activity_main.xml and design the layout.
Step 7: Click on app java com.example.exno3 MainActivity and type the java code.
Step 8: Run the project.
PROGRAM
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:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
MainActivity.java
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.*;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.widget.ImageView;
11
191CSC611L 310619104019
setContentView(R.layout.activity_main);
paint.setColor(Color.GREEN);
paint.setTextSize(50);
}
}
12
191CSC611L 310619104019
OUTPUT
RESULT:
Thus an android application that uses graphical primitive has been developed and
executed successfully.
13
191CSC611L 310619104019
AIM
To develop an application that make use of database.
ALGORITHM
Step 1: Open Android Studio and then click on File New New Project.
Step 2: Type the Application name as “exno4” and click Next.
Step 3: Select Empty Activity and click Next.
Step 4: Click Finish.
Step 5: It will build and load the project.
Step 6: Click on app res layout activity_main.xml and design the layout.
Step 7: Click on app java com.example.exno4 MainActivity and type the java code.
Step 8: Run the project.
PROGRAM
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Student Details"
android:textSize="30sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Name:"
android:textSize="20sp" />
<EditText
android:id="@+id/Name"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:digits="a-z A-Z"
android:inputType="text"
android:textSize="20sp" />
14
191CSC611L 310619104019
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Register No:"
android:textSize="20sp" />
<EditText
android:id="@+id/RegisterNo"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:inputType="number"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter CGPA:"
android:textSize="20sp" />
<EditText
android:id="@+id/CGPA"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:inputType="number"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/Insert"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:text="Insert"
android:textSize="30dp" />
<Button
android:id="@+id/Delete"
android:layout_width="165dp"
android:layout_height="wrap_content"
android:text="Delete"
android:textSize="30dp" />
15
191CSC611L 310619104019
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/Update"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Update"
android:textSize="30dp" />
<Button
android:id="@+id/View"
android:layout_width="165dp"
android:layout_height="wrap_content"
android:text="View"
android:textSize="30dp" />
</LinearLayout>
<Button
android:id="@+id/ViewAll"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="View All"
android:textSize="30dp" />
</LinearLayout>
MainActivity.java
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.view.View.OnClickListener;
import android.view.View;
16
191CSC611L 310619104019
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RegisterNo=(EditText)findViewById(R.id.RegisterNo);
Name=(EditText)findViewById(R.id.Name);
CGPA=(EditText)findViewById(R.id.CGPA);
Insert=(Button)findViewById(R.id.Insert);
Delete=(Button)findViewById(R.id.Delete);
Update=(Button)findViewById(R.id.Update);
View=(Button)findViewById(R.id.View);
ViewAll=(Button)findViewById(R.id.ViewAll);
Insert.setOnClickListener(this);
Delete.setOnClickListener(this);
Update.setOnClickListener(this);
View.setOnClickListener(this);
ViewAll.setOnClickListener(this);
if(view==Delete){
if(RegisterNo.getText().toString().trim().length()==0)
17
191CSC611L 310619104019
{
showMessage("Error", "Please enter RegisterNo");
return;
}
Cursor c=db.rawQuery("SELECT * FROM student WHERE
RegisterNo='"+RegisterNo.getText()+"'", null);
if(c.moveToFirst())
{
db.execSQL("DELETE FROM student WHERE
RegisterNo='"+RegisterNo.getText()+"'");
showMessage("Success", "Record Deleted");
}
else
{
showMessage("Error", "Invalid Register No");
}
clearText();
}
if(view==Update){
if(RegisterNo.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter RegisterNo");
return;
}
Cursor c=db.rawQuery("SELECT * FROM student WHERE
RegisterNo='"+RegisterNo.getText()+"'", null);
if(c.moveToFirst()) {
db.execSQL("UPDATE student SET name='" + Name.getText() + "',CGPA='" +
CGPA.getText() +
"' WHERE RegisterNo='"+RegisterNo.getText()+"'");
showMessage("Success", "Record Modified");
}
else {
showMessage("Error", "Invalid RegisterNo");
}
clearText();
}
if(view==View){
if(RegisterNo.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter RegisterNo");
return;
}
Cursor c=db.rawQuery("SELECT * FROM student WHERE
18
191CSC611L 310619104019
RegisterNo='"+RegisterNo.getText()+"'", null);
if(c.moveToFirst())
{
Name.setText(c.getString(1));
CGPA.setText(c.getString(2));
}
else
{
showMessage("Error", "Invalid RegisterNo");
clearText();
}
}
if(view==ViewAll){
Cursor c=db.rawQuery("SELECT * FROM student", null);
if(c.getCount()==0)
{
showMessage("Error", "No records found");
return;
}
StringBuffer buffer=new StringBuffer();
while(c.moveToNext())
{
buffer.append("RegisterNo: "+c.getString(0)+"\n");
buffer.append("Name: "+c.getString(1)+"\n");
buffer.append("CGPA: "+c.getString(2)+"\n\n");
}
showMessage("Student Details", buffer.toString());
}
19
191CSC611L 310619104019
}
}
OUTPUT
RESULT:
Thus an android application that uses database has been developed and executed
successfully.
20
191CSC611L 310619104019
AIM
To develop an application that uses multithreading.
ALGORITHM
Step 1: Open Android Studio and then click on File New New Project.
Step 2: Type the Application name as “exno5” and click Next.
Step 3: Select Empty Activity and click Next.
Step 4: Click Finish.
Step 5: It will build and load the project.
Step 6: Click on app res layout activity_main.xml and design the layout.
Step 7: Click on app java com.example.exno5 MainActivity and type the java code.
Step 8: Run the project.
PROGRAM
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:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Load Thread" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ABC" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ABC" />
21
191CSC611L 310619104019
</LinearLayout>
MainActivity.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
btn1 = (Button)findViewById(R.id.button);
btn2 = (Button)findViewById(R.id.button2);
btn3 = (Button)findViewById(R.id.button3);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new Thread(new Runnable() {
@Override
public void run() {
btn2.setText("DEF");
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
btn3.setText("DEF");
}
}).start();
}
});
}
}
22
191CSC611L 310619104019
OUTPUT
RESULT:
Thus an android application that uses multithreading has been developed and
executed successfully.
23
191CSC611L 310619104019
AIM
To develop an application that uses GPS location information.
ALGORITHM
Step 1: Open Android Studio and then click on File New New Project.
Step 2: Type the Application name as “exno6” and click Next.
Step 3: Select Empty Activity and click Next.
Step 4: Click Finish.
Step 5: It will build and load the project.
Step 6: Click on app manifests AndroidManifest.xml and give location and internet
permission.
Step 7: Click on app res layout activity_main.xml and design the layout.
Step 8: Click on app java com.example.exno6 MainActivity and type the java code.
Step 9: Click on app java com.example.exno6 GpsTracker and type the java code.
Step 10: Run the project.
PROGRAM
activity_main.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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Latitude"
android:textSize="18sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/latitude"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="-"
android:textSize="20sp"
android:textStyle="bold"/>
24
191CSC611L 310619104019
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Longitude"
android:textSize="18sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/longitude"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="20sp"
android:textStyle="bold"
android:text="-"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="getLocation"
android:text="GET LOCATION" />
</LinearLayout>
MainActivity.java
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
tvLatitude = (TextView)findViewById(R.id.latitude);
tvLongitude = (TextView)findViewById(R.id.longitude);
25
191CSC611L 310619104019
try {
if (ContextCompat.checkSelfPermission(getApplicationContext(),
android.Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED ) {
ActivityCompat.requestPermissions(this, new
String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, 101);
}
} catch (Exception e){
e.printStackTrace();
}
}
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityCompat;
26
191CSC611L 310619104019
27
191CSC611L 310619104019
if (isNetworkEnabled) {
//check the network permission
if (ActivityCompat.checkSelfPermission(mContext,
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(mContext,
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions((Activity) mContext, new
String[]{android.Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION}, 101);
}
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("Network", "Network");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
28
191CSC611L 310619104019
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return location;
}
/**
* Stop using GPS listener
* Calling this function will stop using GPS in your app
* */
/**
* Function to get latitude
* */
// return latitude
return latitude;
}
29
191CSC611L 310619104019
/**
* Function to get longitude
* */
// return longitude
return longitude;
}
/**
* Function to check GPS/wifi enabled
* @return boolean
* */
/**
* Function to show settings alert dialog
* On pressing Settings button will lauch Settings Options
* */
30
191CSC611L 310619104019
@Override
public void onLocationChanged(Location location) {
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
}
31
191CSC611L 310619104019
OUTPUT
RESULT:
Thus an android application that uses GPS location information has been developed
and executed successfully.
32
191CSC611L 310619104019
AIM
To develop an application that writes data to SD card.
ALGORITHM
Step 1: Open Android Studio and then click on File New New Project.
Step 2: Type the Application name as “exno7” and click Next.
Step 3: Select Empty Activity and click Next.
Step 4: Click Finish.
Step 5: It will build and load the project.
Step 6: Click on app manifests AndroidManifest.xml and give SD card permission.
Step 7: Click on app res layout activity_main.xml and design the layout.
Step 8: Click on app java com.example.exno7 MainActivity and type the java code.
Step 9: Run the project.
PROGRAM
activity_main.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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/write"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Write Data" />
<Button
android:id="@+id/read"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Read Data" />
<Button
33
191CSC611L 310619104019
android:id="@+id/clear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Clear Data" />
</LinearLayout>
MainActivity.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.*;
import java.io.*;
EditText edit;
Button write, read, clear;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
write.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String message = edit.getText().toString();
try {
File folder = null;
if (android.os.Build.VERSION.SDK_INT >=
android.os.Build.VERSION_CODES.KITKAT) {
folder =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS
);
}
File f = new File(folder, "myfile.txt");
f.createNewFile();
FileOutputStream fos = new FileOutputStream(f);
OutputStreamWriter osw = new OutputStreamWriter(fos);
34
191CSC611L 310619104019
osw.append(message);
osw.close();
fos.close();
Toast.makeText(getBaseContext(), "Data written to SD card",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
});
read.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String message;
String buf = "";
try {
File folder = null;
if (android.os.Build.VERSION.SDK_INT >=
android.os.Build.VERSION_CODES.KITKAT) {
folder =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS
);
}
File f = new File(folder, "myfile.txt");
FileInputStream fin = new FileInputStream(f);
BufferedReader br = new BufferedReader(new InputStreamReader(fin));
while((message = br.readLine()) != null){
buf += message;
}
edit.setText(buf);
br.close();
fin.close();
Toast.makeText(getBaseContext(), "Data read from SD card",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
});
clear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
35
191CSC611L 310619104019
edit.setText("");
}
});
}
}
OUTPUT
RESULT:
Thus an android application that writes data to SD card has been developed and
executed successfully.
36
191CSC611L 310619104019
AIM
To develop an application that sends a SMS and create an alert.
ALGORITHM
Step 1: Open Android Studio and then click on File New New Project.
Step 2: Type the Application name as “exno8” and click Next.
Step 3: Select Empty Activity and click Next.
Step 4: Click Finish.
Step 5: It will build and load the project.
Step 6: Click on app res layout activity_main.xml and design the layout.
Step 7: Click on app java com.example.exno8 MainActivity and type the java code.
Step 8: Click on File New Activity Empty Activity to create a new activity.
Step 9: Click on app res layout activity_second.xml and design the layout.
Step 10: Click on app java com.example.exno8 SecondActivity and type the java
code.
Step 11: Run the project.
PROGRAM
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message"
android:textSize="30sp" />
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="30sp" />
<Button
android:id="@+id/button"
37
191CSC611L 310619104019
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:layout_gravity="center"
android:text="Notify"
android:textSize="30sp"/>
</LinearLayout>
MainActivity.java
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
notify.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
PendingIntent pending = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);
Notification noti = new
Notification.Builder(MainActivity.this).setContentTitle("New
Message").setContentText(e.getText().toString()).setSmallIcon(R.mipmap.ic_launcher).setC
ontentIntent(pending).build();
NotificationManager manager = (NotificationManager)
38
191CSC611L 310619104019
getSystemService(NOTIFICATION_SERVICE);
noti.flags |= Notification.FLAG_AUTO_CANCEL;
manager.notify(0, noti);
}
});
}
}
activity_second.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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context=".SecondActivity">
<TextView
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Notification"/>
<TextView
android:id="@+id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
SecondActivity.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
39
191CSC611L 310619104019
OUTPUT
RESULT:
Thus an android application that sends a SMS and creates an alert has been developed
and executed successfully.
40
191CSC611L 310619104019
AIM
To develop an application that make use of menu.
ALGORITHM
Step 1: Open Android Studio and then click on File New New Project.
Step 2: Type the Application name as “exno1” and click Next.
Step 3: Select Empty Activity and click Next.
Step 4: Click Finish.
Step 5: It will build and load the project.
Step 6: Click on app res layout activity_main.xml and design the layout.
Step 7: Click on app res and create a new folder “menu” and two files inside the menu
folder named “menu_example.xml” and “options_menu.xml”.
Step 8: Click on app java com.example.exno9 MainActivity and type the java code.
Step 9: Run the project.
PROGRAM
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
menu_example.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
41
191CSC611L 310619104019
<item android:id="@+id/mail"
android:icon="@drawable/ic_mail"
android:title="@string/mail" />
<item android:id="@+id/upload"
android:icon="@drawable/ic_upload"
android:title="@string/upload"
app:showAsAction="ifRoom" />
<item android:id="@+id/share"
android:icon="@drawable/ic_share"
android:title="@string/share" />
</menu>
options_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/search_item"
android:title="Search" />
<item android:id="@+id/upload_item"
android:title="Upload" />
<item android:id="@+id/copy_item"
android:title="Copy" />
<item android:id="@+id/print_item"
android:title="Print" />
<item android:id="@+id/share_item"
android:title="Share" />
<item android:id="@+id/bookmark_item"
android:title="BookMark" />
</menu>
MainActivity.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
42
191CSC611L 310619104019
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Toast.makeText(this, "Selected Item: " +item.getTitle(),
Toast.LENGTH_SHORT).show();
switch (item.getItemId()) {
case R.id.search_item:
// do your code
return true;
case R.id.upload_item:
// do your code
return true;
case R.id.copy_item:
// do your code
return true;
case R.id.print_item:
// do your code
return true;
case R.id.share_item:
// do your code
return true;
case R.id.bookmark_item:
// do your code
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
43
191CSC611L 310619104019
OUTPUT
RESULT:
Thus an android application that make use of menu has been developed and executed
successfully.
44
191CSC611L 310619104019
AIM
To develop an application to build an alarm clock.
ALGORITHM
Step 1: Open Android Studio and then click on File New New Project.
Step 2: Type the Application name as “exno10” and click Next.
Step 3: Select Empty Activity and click Next.
Step 4: Click Finish.
Step 5: It will build and load the project.
Step 6: Click on app manifests AndroidManifest.xml and give vibrate and wake lock
permission.
Step 7: Click on app res layout activity_main.xml and design the layout.
Step 8: Click on app java com.example.exno10 MainActivity and type the java code.
Step 9: Click on app java com.example.exno10 AlarmReceiver and type the java
code.
Step 10: Run the project.
PROGRAM
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:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TimePicker
android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="20dp"
android:checked="false"
android:onClick="OnToggleClicked" />
45
191CSC611L 310619104019
</LinearLayout>
MainActivity.java
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TimePicker;
import android.widget.Toast;
import android.widget.ToggleButton;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Calendar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
46
191CSC611L 310619104019
import androidx.annotation.RequiresApi;
47
191CSC611L 310619104019
context.getSystemService(context.VIBRATOR_SERVICE);
vibrator.vibrate(4000);
// play ringtone
ringtone.play();
}
}
48
191CSC611L 310619104019
OUTPUT
RESULT:
Thus an android application to build an alarm clock has been developed and executed
successfully.
49
191CSC611L 310619104019
AIM
To develop a hybrid mobile application.
ALGORITHM
Step 1: Open Android Studio and then click on File New New Project.
Step 2: Type the Application name as “exno11” and click Next.
Step 3: Select Empty Activity and click Next.
Step 4: Click Finish.
Step 5: It will build and load the project.
Step 6: Click on app res layout activity_main.xml and design the layout.
Step 8: Click on app java com.example.exno11 MainActivity and type the java
code.
Step 9: Run the project.
PROGRAM
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:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/website_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/go"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Go"/>
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
50
191CSC611L 310619104019
MainActivity.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.*;
Button go;
EditText site;
WebView myWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
site = (EditText)findViewById(R.id.website_name);
go = (Button)findViewById(R.id.go);
go.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String url = site.getText().toString();
myWebView.loadUrl(url);
}
});
}
51
191CSC611L 310619104019
OUTPUT
RESULT:
Thus a hybrid mobile application has been developed and executed successfully.
52
191CSC611L 310619104019
AIM
To develop an application for Prescription Viewer.
ALGORITHM
Step 1: Open Android Studio and then click on File New New Project.
Step 2: Type the Application name as “PrescriptionViewer” and click Next.
Step 3: Select Empty Activity and click Next.
Step 4: Click Finish.
Step 5: It will build and load the project.
Step 6: Get patient’s prescription details from the doctor.
Step 7: Store each patient’s data as a pdf in SD card.
Step 8: Get the data to store it in history from the database.
Step 9: Run the project.
PROGRAM
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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:layout_marginTop="25sp"
tools:context=".MainActivity">
<EditText
android:id="@+id/name"
android:backgroundTint="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:hint="Name"
android:lines="1"/>
<EditText
android:id="@+id/address"
android:backgroundTint="@color/colorPrimary"
android:lines="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:layout_margin="15dp"
53
191CSC611L 310619104019
android:hint="Address" />
<EditText
android:id="@+id/symptoms"
android:backgroundTint="@color/colorPrimary"
android:lines="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/address"
android:layout_margin="15dp"
android:hint="Symptoms" />
<EditText
android:id="@+id/prescription"
android:backgroundTint="@color/colorPrimary"
android:lines="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/symptoms"
android:layout_margin="15dp"
android:hint="Prescription" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/prescription"
android:layout_marginTop="15dp"
android:gravity="center">
<Button
android:id="@+id/btn_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/prescription"
android:background="@color/colorPrimary"
android:text="SAVE "
android:textColor="#ffffff" />
<Button
android:id="@+id/btn_print"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/btn_save"
android:layout_marginLeft="15dp"
android:background="@color/colorPrimary"
android:text="History"
54
191CSC611L 310619104019
android:textColor="#ffffff" />
</LinearLayout>
</RelativeLayout>
activity_retrieve_previous_prescription.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:context=".RetrievePreviousPrescription">
<ir.androidexception.datatable.DataTable
android:id="@+id/data_table"
android:layout_width="403dp"
android:layout_height="match_parent"
android:layout_marginStart="8dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:corner_radius="8dp"
app:direction="ltr"
app:header_background_color="#fff"
app:header_gravity="center"
app:header_horizontal_padding="0dp"
app:header_text_color="#000"
app:header_text_size="4sp"
app:header_vertical_padding="16dp"
app:persian_number="false"
app:row_background_color="#fff"
app:row_gravity="center"
app:row_text_color="#000"
app:row_text_size="4sp"
app:row_vertical_padding="16dp"
app:shadow="8dp" />
</RelativeLayout>
MainActivity.java
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Canvas;
55
191CSC611L 310619104019
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.pdf.PdfDocument;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
DatabaseClass databaseClass;
SQLiteDatabase sqLiteDatabase;
Date date = new Date();
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String userName = String.valueOf(name.getText());
String userAddress = String.valueOf(address.getText());
String userSymptoms = String.valueOf(symptoms.getText());
56
191CSC611L 310619104019
databaseClass.insert(userName,userAddress,date.getTime(),userSymptoms,userPrescription);
Toast.makeText(getApplicationContext(),"Saved in Storage",
Toast.LENGTH_SHORT).show();
printInvoice();
name.setText("");
address.setText("");
symptoms.setText("");
prescription.setText("");
}
});
print.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,RetrievePreviousPrescription.class);
startActivity(intent);
}
});
paint.setTextSize(80);
canvas.drawText("Hospital Name",250,80,paint);
paint.setTextSize(30);
canvas.drawText("Dr. XYZ", 30, 150,paint);
paint.setTextAlign(Paint.Align.RIGHT);
canvas.drawText("Invoice No: ",canvas.getWidth()-70,150,paint);
canvas.drawText(String.valueOf(cursor.getInt(0)),canvas.getWidth()-40,150,paint);
57
191CSC611L 310619104019
paint.setTextAlign(Paint.Align.LEFT);
paint.setColor(Color.BLACK);
canvas.drawText("Date:",30,200, paint);
canvas.drawText(simpleDateFormat.format(cursor.getLong(3)),120,200,paint);
canvas.drawText("Time:",750,200,paint);
paint.setTextAlign(Paint.Align.RIGHT);
canvas.drawText(timepatternFormat.format(cursor.getLong(3)),canvas.getWidth()-
40,200,paint);
paint.setTextAlign(Paint.Align.LEFT);
paint.setColor(Color.BLACK);
canvas.drawText("Patient Name:",30,350,paint);
canvas.drawText("Address:",620,350,paint);
paint.setTextAlign(Paint.Align.RIGHT);
paint.setTextAlign(Paint.Align.LEFT);
paint.setColor(Color.BLACK);
canvas.drawText(cursor.getString(1),30,380,paint);
canvas.drawText(cursor.getString(2),620,380,paint);
paint.setTextAlign(Paint.Align.RIGHT);
paint.setTextAlign(Paint.Align.LEFT);
paint.setColor(Color.BLACK);
canvas.drawText("Symptoms:",30,450,paint);
canvas.drawText(cursor.getString(4),30,480,paint);
canvas.drawText("Prescription:",620,450,paint);
canvas.drawText(cursor.getString(5),620,480,paint);
paint.setTextAlign(Paint.Align.RIGHT);
canvas.drawText("STAY HEALTHY",900,800,paint);
pdfDocument.finishPage(page);
try {
pdfDocument.writeTo(new FileOutputStream(file));
} catch (IOException e) {
e.printStackTrace();
}
pdfDocument.close();
58
191CSC611L 310619104019
}
}
DatabaseClass.java
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;
@Override
public void onCreate(SQLiteDatabase db) {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
public void insert(String name, String address, Long date, String symptoms, String
prescription) {
SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("Name", name);
contentValues.put("address", address);
contentValues.put("date", date);
contentValues.put("symptoms",symptoms);
contentValues.put("prescription",prescription);
sqLiteDatabase.insert("myTable",null,contentValues);
}
}
59
191CSC611L 310619104019
RetrievePreviousPrescription.java
import androidx.appcompat.app.AppCompatActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import ir.androidexception.datatable.DataTable;
import ir.androidexception.datatable.model.DataTableHeader;
import ir.androidexception.datatable.model.DataTableRow;
DataTable dataTable;
DatabaseClass databaseClass;
SQLiteDatabase sqLiteDatabasel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_retrieve_previous_prescription);
dataTable = findViewById(R.id.data_table);
databaseClass = new DatabaseClass(this);
sqLiteDatabasel = databaseClass.getWritableDatabase();
DataTableHeader dataTableHeader = new DataTableHeader.Builder()
.item("Invoice No.", 5)
.item("Patient Name", 5)
.item("Date", 5)
.item("Time", 5)
.build();
60
191CSC611L 310619104019
.build();
rows.add(row);
}
dataTable.setHeader(dataTableHeader);
dataTable.setRows(rows);
dataTable.inflate(this);
}
}
OUTPUT
61
191CSC611L 310619104019
RESULT:
Thus an android application for Prescription Viewer has been developed and executed
successfully.
62