Professional Documents
Culture Documents
ALGORITHM:
1. Create a New Android Project:
Click New in the toolbar.
In the window that appears, open the Android folder, select Android Application
Project, and click next.
Provide the application name and the project name and then finally give the desired
package name.
Choose a launcher icon for your application and then select Blank Activity and then
click Next
Provide the desired Activity name for your project and then click Finish.
2. Create a New AVD (Android Virtual Device):
In Eclipse, click Android Virtual Device Manager from the toolbar.
In the Android Virtual Device Manager panel, click New.
Fill in the details for the AVD. Give it a name, a platform target, an SD card
size, and a skin (HVGA is default).
Click Create AVD and Select the new AVD from the Android Virtual Device
Manager and click Start.
3. Design the graphical layout with a text view and two command buttons.
4. Run the application.
5. On pressing the change color button, color of the text gets changed.
6. On pressing the change font size button, the size of the font gets altered.
7. Close the Android project.
PROGRAM CODE
MainActivity.java
package com.example.gui;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Typeface;
import android.graphics.Color;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="WELCOME"
android:layout_margin="20sp"
android:gravity="center"
android:textSize="20sp"
android:textStyle="bold"
/>
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20sp"
android:gravity="center"
android:text="Change Font Size" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="20sp"
android:text="Change Color" />
</LinearLayout>
OUTPUT:
RESULT:
Thus, the program for android application GUI Components, Font and colors was executed
successfully.
ALGORITHM:
1. Create a New Android Project:
Click New in the toolbar.
In the window that appears, open the Android folder, select Android Application
Project, and click next.
Provide the application name and the project name and then finally give the desired
package name.
Choose a launcher icon for your application and then select Blank Activity and then
click Next
Provide the desired Activity name for your project and then click Finish.
2. Create a New AVD (Android Virtual Device):
In Eclipse, click Android Virtual Device Manager from the toolbar.
In the Android Virtual Device Manager panel, click New.
Fill in the details for the AVD. Give it a name, a platform target, an SD card
size, and a skin (HVGA is default).
Click Create AVD and Select the new AVD from the Android Virtual Device
Manager and click Start.
3. Design the graphical layout with buttons, edit text and text view.
4. Run the application.
5. Provide the required inputs to perform the desired arithmetic operation.
6. Display the result.
7. Close the Android project.
PROGRAM CODE:
MainActivity.java
package com.example.layout;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
catch(Exception e)
{
Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
}
}
});
Button clear = (Button)findViewById(R.id.button2);
clear.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
try
{
txtData1.setText("");
txtData2.setText("");
}
catch(Exception e)
{
Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
}
}
});
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ADDITION"
android:layout_gravity="center"
android:textSize="20dp" >
</TextView>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/linearLayout1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter No 1" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.20"
android:inputType="number" >
</EditText>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/linearLayout2" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter No 2" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.20"
android:inputType="number" >
</EditText>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/linearLayout3" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:text="Addition" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:text="Subtraction" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:text="Clear" />
</LinearLayout>
<View
android:id="@+id/linearLayout4"
android:layout_width="fill_parent"
android:layout_height="2px"
android:background="#DDFFDD" />
</RelativeLayout>
OUTPUT:
RESULT:
Thus, the program for android application that uses layout managers and event listeners was
executed successfully.
ALGORITHM:
1. Create a New Android Project:
Click New in the toolbar.
In the window that appears, open the Android folder, select Android Application
Project, and click next.
Provide the application name and the project name and then finally give the
desired package name.
Choose a launcher icon for your application and then select Blank Activity and
then click Next
Provide the desired Activity name for your project and then click Finish.
2. Create a New AVD (Android Virtual Device):
In Eclipse, click Android Virtual Device Manager from the toolbar.
In the Android Virtual Device Manager panel, click New.
Fill in the details for the AVD. Give it a name, a platform target, an SD card size,
and a skin (HVGA is default).
Click Create AVD and Select the new AVD from the Android Virtual Device
Manager and click Start.
3. Run the application.
4. Provide any two input numbers.
5. Choose any arithmetic operations of your choice and the output gets displayed on
the display screen of the calculator application.
6. Close the Android project.
PROGRAM CODE:
MainActivity.java
package com.example.calculator_two;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity implements OnClickListener {
private Button nine, eig, sev, six, fiv, four, thr, two, one, zero, dot,
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.b0:
case R.id.b1:
case R.id.b2:
case R.id.b3:
case R.id.b4:
case R.id.b5:
case R.id.b6:
case R.id.b7:
case R.id.b8:
case R.id.b9:
String inDigit = ((Button) v).getText().toString();
if (s.equals("0")) {
s = inDigit;
} else {
s += inDigit;
}
et.setText(s);
if (lO == '=') {
result = 0;
lO = ' ';
}
break;
case R.id.bpl:
compute();
lO = '+';
break;
case R.id.bmin:
compute();
lO = '-';
break;
case R.id.bdiv:
compute();
lO = '/';
break;
case R.id.bmul:
compute();
lO = '*';
break;
case R.id.beq:
compute();
lO = '=';
break;
case R.id.bcl:
result = 0;
s = "0";
lO = ' ';
et.setText("0");
break;
}
}
private void compute() {
int inNum = Integer.parseInt(s);
s = "0";
if (lO == ' ') {
result = inNum;
} else if (lO == '+') {
result += inNum;
} else if (lO == '-') {
result -= inNum;
} else if (lO == '*') {
result *= inNum;
} else if (lO == '/') {
result /= inNum;
} else if (lO == '=') {
// Keep the result for the next operation
}
et.setText(String.valueOf(result));
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="enter no. here"
android:textSize="30dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:orientation="horizontal"
android:weightSum="4" >
<Button
android:id="@+id/b9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="9"
android:textColor="#ff0000" />
<Button
android:id="@+id/b8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="8"
android:textColor="#ff0000" />
<Button
android:id="@+id/b7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="7"
android:textColor="#ff0000" />
<Button
android:id="@+id/bpl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="+"
android:textColor="#ff0000" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4" >
<Button
android:id="@+id/b6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="6"
android:textColor="#ff0000" />
<Button
android:id="@+id/b5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="5"
android:textColor="#ff0000" />
<Button
android:id="@+id/b4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="4"
android:textColor="#ff0000" />
<Button
android:id="@+id/bmin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-"
android:textColor="#ff0000" /> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4" >
<Button
android:id="@+id/b3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="3"
android:textColor="#ff0000" />
<Button
android:id="@+id/b2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="2"
android:textColor="#ff0000" />
<Button
android:id="@+id/b1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1"
android:textColor="#ff0000" />
<Button
android:id="@+id/bmul"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="*"
android:textColor="#ff0000" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="5" >
<Button
android:id="@+id/bd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="."
android:textColor="#ff0000" />
<Button
android:id="@+id/b0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="0"
android:textColor="#ff0000" />
<Button
android:id="@+id/bcl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Clr"
android:textColor="#ff0000" />
<Button
android:id="@+id/beq"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="="
android:textColor="#ff0000" />
<Button
android:id="@+id/bdiv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="/"
android:textColor="#ff0000" />
</LinearLayout>
</LinearLayout>
OUTPUT:
RESULT:
Thus, the program for android based calculator application was executed successfully.
ALGORITHM:
1. Create a New Android Project:
Click New in the toolbar.
In the window that appears, open the Android folder, select Android
Application Project, and click next.
Provide the application name and the project name and then finally give
the desired package name.
Choose a launcher icon for your application and then select Blank
Activity and then click Next
Provide the desired Activity name for your project and then click Finish.
2. Create a New AVD (Android Virtual Device):
In Eclipse, click Android Virtual Device Manager from the toolbar.
In the Android Virtual Device Manager panel, click New.
Fill in the details for the AVD. Give it a name, a platform target, an SD
card size, and a skin (HVGA is default).
Click Create AVD and Select the new AVD from the Android Virtual
Device Manager and click Start.
3. Design the layout by adding a ImageView button.
4. Run the application.
5. Draw straight line by moving the mouse over the screen.
6. Close the Android project.
PROGRAM CODE:
MainActivity.java
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
public class MainActivity extends Activity implements OnTouchListener {
private ImageView imageView;
private Bitmap bitmap;
private Canvas canvas;
private Paint paint;
private float downx = 0, downy = 0, upx = 0, upy = 0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) this.findViewById(R.id.imageView1);
Display currentDisplay = getWindowManager().getDefaultDisplay();
float dw = currentDisplay.getWidth();
float dh = currentDisplay.getHeight();
bitmap = Bitmap.createBitmap((int) dw, (int) dh, Bitmap.Config.ARGB_8888);
canvas = new Canvas(bitmap);
paint = new Paint();
paint.setColor(Color.BLUE);
imageView.setImageBitmap(bitmap);
imageView.setOnTouchListener(this);
}
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
downx = event.getX();
downy = event.getY();
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
upx = event.getX();
upy = event.getY();
canvas.drawLine(downx, downy, upx, upy, paint);
imageView.invalidate();
break;
case MotionEvent.ACTION_CANCEL:
break;
default:
break;
}
return true;
}
}
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" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
OUTPUT:
RESULT:
Thus, the program for android application that draws basic graphical primitives on the
screen. was executed successfully.
ALGORITHM:
1. Create a New Android Project:
Click New in the toolbar.
In the window that appears, open the Android folder, select Android
Application Project, and click next.
Provide the application name and the project name and then finally give the
desired package name.
Choose a launcher icon for your application and then select Blank Activity
and then click Next
Provide the desired Activity name for your project and then click Finish.
2. Create a New AVD (Android Virtual Device):
In Eclipse, click Android Virtual Device Manager from the toolbar.
In the Android Virtual Device Manager panel, click New.
Fill in the details for the AVD. Give it a name, a platform target, an SD card
size, and a skin (HVGA is default).
Click Create AVD and Select the new AVD from the Android Virtual
Device Manager and click Start.
3. Design the graphical layout.
4. Run the application.
5. The requested data is retrieved from the database named myFriendsDb.
6. Close the Android project.
PROGRAM CODE
CRUDonDB.java
package com.collabera.labs.db;
import java.util.ArrayList;
import android.app.ListActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
}}
crudondb.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" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
OUTPUT:
RESULT:
Thus, the program for android application that makes use of database was executed
successfully.
ALGORITHM:
1. Create a New Android Project:
Click New in the toolbar.
In the window that appears, open the Android folder, select Android Application
Project, and click next.
Provide the application name and the project name and then finally give the desired
package name.
Choose a launcher icon for your application and then select Blank Activity and then
click Next
Provide the desired Activity name for your project and then click Finish.
2. Create a New AVD (Android Virtual Device):
In Eclipse, click Android Virtual Device Manager from the toolbar.
In the Android Virtual Device Manager panel, click New.
Fill in the details for the AVD. Give it a name, a platform target, an SD card
size, and a skin (HVGA is default).
Click Create AVD and Select the new AVD from the Android Virtual Device
Manager and click Start.
3. Design the graphical layout using buttons, text and ImageView.
4. Run the application.
5. Fetch the details from the URL.
6. Display the output by clicking the result button.
7. Close the Android project.
PROGRAM CODE:
MainActivity.java
package com.example.rssfeed;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
// noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
HandleXML.java
package com.example.rssfeed;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
public class HandleXML {
private String title = "title";
private String link = "link";
private String description = "description";
private String urlString = null;
private XmlPullParserFactory xmlFactoryObject;
public volatile boolean parsingComplete = true;
public HandleXML(String url){
this.urlString = url;
}
public String getTitle(){
return title;
}
public String getLink(){
return link;
}
public String getDescription(){
return description;
}
public void parseXMLAndStoreIt(XmlPullParser myParser) {
int event;
String text=null;
try {
event = myParser.getEventType();
while (event != XmlPullParser.END_DOCUMENT) {
String name=myParser.getName();
switch (event){
case XmlPullParser.START_TAG:
break;
case XmlPullParser.TEXT:
text = myParser.getText();
break;
case XmlPullParser.END_TAG:
if(name.equals("title")){
title = text;
}
else if(name.equals("link")){
link = text;
}
else if(name.equals("description")){
description = text;
}
else{
}
break;
}
event = myParser.next();
}
parsingComplete = false;
}
catch (Exception e) {
e.printStackTrace();
}
}
public void fetchXML(){
Thread thread = new Thread(new Runnable(){
public void run() {
try {
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */);
conn.setRequestMethod("GET");
conn.setDoInput(true);
// Starts the query
conn.connect();
InputStream stream = conn.getInputStream();
xmlFactoryObject = XmlPullParserFactory.newInstance();
XmlPullParser myparser = xmlFactoryObject.newPullParser();
myparser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
myparser.setInput(stream, null);
parseXMLAndStoreIt(myparser);
stream.close();
}
catch (Exception e) {
}
}
});
thread.start();
}
}
Second.java
package com.example.rssfeed;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class Second extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
WebView w1=(WebView)findViewById(R.id.webView);
w1.loadUrl("http://tutorialspoint.com/android/sampleXML.xml");
}
}
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: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:text="RSS example" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textview"
android:textSize="35dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textview"
android:layout_centerHorizontal="true"
android:text="M.A.M College"
android:textColor="#ff7aff24"
android:textSize="35dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/srr"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_below="@+id/imageView"
android:hint="Title"
android:textColorHint="#ff69ff0e"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText2"
android:layout_below="@+id/editText"
android:layout_alignLeft="@+id/editText"
android:layout_alignStart="@+id/editText"
android:textColorHint="#ff21ff11"
android:hint="Link"
android:layout_alignRight="@+id/editText"
android:layout_alignEnd="@+id/editText" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText3"
android:layout_below="@+id/editText2"
android:layout_alignLeft="@+id/editText2"
android:layout_alignStart="@+id/editText2"
android:hint="Description"
android:textColorHint="#ff33ff20"
android:layout_alignRight="@+id/editText2"
android:layout_alignEnd="@+id/editText2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fetch"
android:id="@+id/button"
android:layout_below="@+id/editText3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/imageView"
android:layout_toStartOf="@+id/imageView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Result"
android:id="@+id/button2"
android:layout_alignTop="@+id/button"
android:layout_alignRight="@+id/editText3"
android:layout_alignEnd="@+id/editText3" />
</RelativeLayout>
activity_second.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">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView"
android:layout_gravity="center_horizontal" />
</LinearLayout>
OUTPUT:
RESULT:
Thus, the program for android application that makes use of RSS Feed was executed
successfully.
ALGORITHM:
1. Create a New Android Project:
Click New in the toolbar.
In the window that appears, open the Android folder, select Android Application
Project, and click next.
Provide the application name and the project name and then finally give the desired
package name.
Choose a launcher icon for your application and then select Blank Activity and then
click Next
Provide the desired Activity name for your project and then click Finish.
2. Create a New AVD (Android Virtual Device):
In Eclipse, click Android Virtual Device Manager from the toolbar.
In the Android Virtual Device Manager panel, click New.
Fill in the details for the AVD. Give it a name, a platform target, an SD card
size, and a skin (HVGA is default).
Click Create AVD and Select the new AVD from the Android Virtual Device
Manager and click Start.
3. Design the graphical layout.
4. Run the application.
5. The requested data is retrieved from the database named myFriendsDb.
6. Close the Android project.
PROGRAM CODE
ThreadHandlerAndroidExample.java
package com.androidexample.threadhandler;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class ThreadHandlerAndroidExample extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.android_example_thread_handler);
final Button GetServerData = (Button) findViewById(R.id.GetServerData);
// On button click call this listener
GetServerData.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// ALERT MESSAGE
Toast.makeText(getBaseContext(),"Please wait, connecting to
server.",Toast.LENGTH_SHORT).show();
// Create Inner Thread Class
Thread background = new Thread(new Runnable() {
private final HttpClient Client = new DefaultHttpClient();
private String
URL="http://androidexample.com/media/webservice/getPage.php";
// After call for background.start this run method call
public void run() {
try {
String SetServerString = "";
HttpGet httpget = new HttpGet(URL);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
SetServerString = Client.execute(httpget, responseHandler);
threadMsg(SetServerString);
} catch (Throwable t) {
// just end the background thread
Log.i("Animation", "Thread exception " + t);
}
}
}
}
// Define the Handler that receives messages from the
// thread and update the progress
private final Handler handler = new Handler() {
public void handleMessage(Message msg) {
String aResponse = msg.getData().getString("message");
if ((null != aResponse)) {
// ALERT MESSAGE
Toast.makeText(getBaseContext(),"Server Response: " +
aResponse,Toast.LENGTH_SHORT).show();
} else {
// ALERT MESSAGE
Toast.makeText(getBaseContext(),"Not Got Response From
Server.",Toast.LENGTH_SHORT).show();
}
}
};
});
// Start Thread
background.start();
// After call start method thread called run Method
}
});
}
}
Android_example_thread_handler.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"
tools:context=".ThreadHandler" >
<Button android:id="@+id/GetServerData"
android:text="Click To Get Server Data"
android:cursorVisible="true"
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
/>
</RelativeLayout>
OUTPUT:
RESULT:
Thus, the program for android application that makes use of multithreading was executed
successfully.
ALGORITHM:
1. Create a New Android Project:
Click New in the toolbar.
In the window that appears, open the Android folder, select Android Application
Project, and click next.
Provide the application name and the project name and then finally give the desired
package name.
Choose a launcher icon for your application and then select Blank Activity and then
click Next
Provide the desired Activity name for your project and then click Finish.
2. Create a New AVD (Android Virtual Device):
In Eclipse, click Android Virtual Device Manager from the toolbar.
In the Android Virtual Device Manager panel, click New.
Fill in the details for the AVD. Give it a name, a platform target, an SD card
size, and a skin (HVGA is default).
Click Create AVD and Select the new AVD from the Android Virtual Device
Manager and click Start.
3. Design the graphical layout.
4. Run the application.
5. The requested data is retrieved from the database named myFriendsDb.
6. Close the Android project.
PROGRAM CODE
UseGps.java
package com.emergency;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Emergency Alert System"
/>
<EditText
android:id="@+id/editTextSMS"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top" />
<EditText
android:id="@+id/textlon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top" />
<Button
android:id="@+id/buttonSend"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Send" />
</LinearLayout>
OUTPUT:
RESULT:
Thus, the program for android application that makes use of GPS information was executed
successfully.
ALGORITHM:
1. Create a New Android Project:
Click New in the toolbar.
In the window that appears, open the Android folder, select Android Application
Project, and click next.
Provide the application name and the project name and then finally give the desired
package name.
Choose a launcher icon for your application and then select Blank Activity and then
click Next
Provide the desired Activity name for your project and then click Finish.
2. Create a New AVD (Android Virtual Device):
In Eclipse, click Android Virtual Device Manager from the toolbar.
In the Android Virtual Device Manager panel, click New.
Fill in the details for the AVD. Give it a name, a platform target, an SD card
size, and a skin (HVGA is default).
Click Create AVD and Select the new AVD from the Android Virtual Device
Manager and click Start.
3. Design the graphical layout using buttons, Textview.
4. Run the application.
5. Writes the data into a file in the SD card.
6. Display the output by clicking the result button.
7. Close the Android project.
PROGRAM CODE:
MainActivity.java
package com.example.externalstorage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
private Button b1, b2;
private EditText e;
private String path = Environment.getExternalStorageDirectory().getPath()
+ "/myfile.txt";
private TextView result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.buttonone);
b2 = (Button) findViewById(R.id.buttontwoss);
e = (EditText) findViewById(R.id.editText1);
result = (TextView) findViewById(R.id.result);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
try {
File myfile = new File(path);
myfile.createNewFile();
FileOutputStream fos = new FileOutputStream(myfile);
OutputStreamWriter out = new OutputStreamWriter(fos);
out.append(e.getText());
out.close();
fos.close();
Toast.makeText(getApplicationContext(),
"saved 'myfile.txt'", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
});
b2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
try {
File myFile = new File(path);
FileInputStream fis = new FileInputStream(myFile);
BufferedReader bd = new BufferedReader(
new InputStreamReader(fis));
String adata = "";
String buff = "";
while ((adata = bd.readLine()) != null) {
buff += adata + "\n";
}
result.setText(buff);
bd.close();
Toast.makeText(getBaseContext(), "done reding 'myfile.txt",
Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
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" >
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<Button
android:id="@+id/buttonone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="save" />
<Button
android:id="@+id/buttontwoss"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="show" />
<TextView
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="35dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
OUTPUT:
RESULT:
Thus, the program for android application that writes data into the SD Card was
executed successfully.
super.onCreate(savedInstanceState);
setContentView(R.layout.second_activity);
}
}
second_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>
OUTPUT:
RESULT:
Thus, the program for android application that creates an alert upon receiving a
message was executed successfully.
ALGORITHM:
1. Create a New Android Project:
Click New in the toolbar.
In the window that appears, open the Android folder, select Android Application
Project, and click next.
Provide the application name and the project name and then finally give the desired
package name.
Choose a launcher icon for your application and then select Blank Activity and then
click Next
Provide the desired Activity name for your project and then click Finish.
2. Create a New AVD (Android Virtual Device):
In Eclipse, click Android Virtual Device Manager from the toolbar.
In the Android Virtual Device Manager panel, click New.
Fill in the details for the AVD. Give it a name, a platform target, an SD card
size, and a skin (HVGA is default).
Click Create AVD and Select the new AVD from the Android Virtual Device
Manager and click Start.
3. Design the graphical layout.
4. Run the application.
5. When the application starts alarm sound will be invoked.
6. Stop alarm button is clicked to stop the alarm.
7. Close the Android project.
PROGRAM CODE:
MainActivity.java
package com.example.alarm_final;
import java.util.Calendar;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
public class MainActivity extends Activity {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.alarm);
Button stopAlarm = (Button) findViewById(R.id.stopAlarm);
stopAlarm.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent arg1) {
mMediaPlayer.stop();
finish();
return false;
}
});
playSound(this, getAlarmUri());
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<TextView
android:id="@+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="alarm_hello" />
</RelativeLayout>
activity_alarm_receiver.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: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=".AlarmReceiverActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
alarm.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center" >
<Button
android:id="@+id/stopAlarm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="stop_alarm" />
</RelativeLayout>
OUTPUT:
RESULT:
Thus, the program for android application for an alarm was executed successfully.