0% found this document useful (0 votes)
21 views106 pages

Full Manual Mad2022

Mobile applications development lab

Uploaded by

murugan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views106 pages

Full Manual Mad2022

Mobile applications development lab

Uploaded by

murugan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 106

GOVERNMENT ARTS AND SCIENCE COLLEGE,

THIRUVENNAINALLUR – 607 203, VILLUPURAM.

PG DEPARTMENT OF COMPUTER SCIENCE

NAME :

REG.NO :

SUBJECT CODE :

SUBJECT NAME : PRACTICAL 10 - MOBILE APPLICATION

DEVELOPMENT LAB

CLASS : II M.SC., CS

YEAR : 2022-2023
GOVERNMENT ARTS AND SCIENCE COLLEGE
THIRUVENNAINALLUR-607 203, VILLUPURAM. PG

DEPARTMENT OF COMPUTER SCIENCE

BONAFIDE CERTIFICATE

Certified that.....................................................Reg No………………...........of II M.Sc.,


Computer Science, IV SEMESTER has completed the PRACTICAL– 10 MOBILE APPLICATION
DEVELOPMENT LAB- by undergoing the university practical as per the syllabus during the academic
year 2022-2023.

Date:

Staff-in-Charge Head of the Department

Internal Examiner External Examiner

Chief Superintendent
CONTENT

S.NO DATE TITLE PAGE SIGN


NO.

1 Simple Android Application

2 Working With Activity

3 Working With Fragment

4 UI Control (Text,Edit Text,Button,Radio


Button)

5 UI Control(Check Box,And Loyout,Image


Butto,Toggle Button)

6 UI Control(Rating Bar,List View)

7 Crud Operation Using Sqlight Db

8 Emailing

9 Telephony

10 SMS
01. SIMPLE ANDROID APPLICATION

Aim :

To Create A Simple Android Application And Display The String Using ADT.

Algorithm:

Step 1: Start the Eclipse by Clicking launcher in ADT bundle.

Step 2: Create a new Project by clicking the file menu and select new Android Application

Project.

Step 3: Design a form layout by using the component Large, Middle and Small.

Step 4: select the large, middle and small components and assign name and values.

Step 5: Write the activity code in main activity then save all.

Step 6: Import package and declare the variably in activity program, write the initialize object.

Step 7: Start SDK manager.

Step 8: Create android virtual devices.

Step 9: Run the android application project.

Step 10: Exit from the eclipse.


Program :

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:id="@+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="31dp"
android:text="WELCOME"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/t3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/t2"
android:layout_centerHorizontal="true"
android:layout_marginTop="53dp"
android:text="Thiruvennainallur" android:textAppearance="?
android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/t2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/t1"
android:layout_marginTop="45dp"
android:text="Government Arts and Science College"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
MainActivity.java

package com.example.simple;

import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

public class MainActivity extends Activity

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

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

}
OutPut :
Result :

Thus the creation of using simple android application is executed successfully.


02. WORKING WITH ACTIVITY

Aim:

To create a command button, layout & display the using controls.

Algorithm:

Step 1: Start the eclipse by clicking launcher in ADT bundle.

Step 2: Create a new project by click the file menu and select new android application project.

Step 3: Design in a form Layout by using the component text view, command button.

Step 4: Select the text view, command button components & assign name and value.

Step 5: Write the activity code in main activity and save all.

Step 6: Import package & declare variable in activity program, write the instalialize object.

Step 7: Start SDK manager.

Step 8: Create android virtual devices.

Step 9: Run the android application project.

Step 10: Exit from the eclipse


Program
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:id="@+id/l1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/l2"
android:layout_alignParentTop="true"
android:layout_marginTop="63dp"
android:text="@string/l1"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/l2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/l1"
android:layout_marginTop="92dp"
android:text="@string/l2"
android:textAppearance="?android:attr/textAppearanceLarge" />

<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="33dp"
android:text="@string/b1" />
<EditText
android:id="@+id/t2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/l2"
android:layout_below="@+id/l2"
android:layout_marginTop="40dp"
android:ems="10"
android:text="@string/t2" />

<EditText
android:id="@+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/l1"
android:layout_below="@+id/l1"
android:layout_marginTop="31dp"
android:ems="10"
android:text="@string/t1" />

</RelativeLayout>
MainActivity.java:
package com.example.usingcontrols;

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText firstNum = (EditText)findViewById(R.id.t1);
final EditText secNum = (EditText)findViewById(R.id.t2);
Button btnAdd = (Button)findViewById(R.id.b1);
btnAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

int num1 = Integer.parseInt(firstNum.getText().toString());


int num2 = Integer.parseInt(secNum.getText().toString());
Toast.makeText(getApplicationContext(), "SUM = " + (num1 + num2),
Toast.LENGTH_SHORT).show();

}
});
}

}
Output:
Result:
Thus the creation of using various controls in the application is executed successfully.
03. ANDROID FRAGMENT

Aim :

To create a Fragment android application and display the string using ADT.

Algorithm:

Step 1: Start the Eclipse by Clicking launcher in ADT bundle.

Step 2: Create a new Project by clicking the file menu and select new Android Application

Project.

Step 3: Design a form layout by using the component Large, Middle and Small.

Step 4: select the Fragment1,fragment2 components and assign name and values.

Step 5: Write the activity code in main activity then save all.

Step 6: Import package and declare the variably in activity program, write the initialize object.

Step 7: Start SDK manager.

Step 8: Create android virtual devices.

Step 9: Run the android application project.

Step 10: Exit from the eclipse.


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="fill_parent"
android:layout_height="fill_parent"
tools:context="example.javatpoint.com.fragmentexample.MainActivity">

<fragment
android:id="@+id/fragment1"
android:name="example.javatpoint.com.fragmentexample.Fragment1"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
/>

<fragment
android:id="@+id/fragment2"
android:name="example.javatpoint.com.fragmentexample.Fragment2"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
/>

</LinearLayout>

File: fragment_fragment1.xml

<FrameLayout 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:background="#F5F5DC"
tools:context="example.javatpoint.com.fragmentexample.Fragment1">

<!-- TODO: Update blank fragment layout -->


<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />

</FrameLayout>

File: fragment_fragment2.xml

<FrameLayout 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:background="#F0FFFF"
tools:context="example.javatpoint.com.fragmentexample.Fragment2">

<!-- TODO: Update blank fragment layout -->


<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />

</FrameLayout>
MainActivity class
package example.javatpoint.com.fragmentexample;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

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

File: Fragment1.java

package example.javatpoint.com.fragmentexample;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class Fragment1 extends Fragment {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_fragment1, container, false);
}

}
File: Fragment2.java

package example.javatpoint.com.fragmentexample;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class Fragment2 extends Fragment {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_fragment2, container, false);
}
}
Output:
Result:

Thus the creation of Fragment using program is executed successfully .


04. UI CONTROLS(Text, Edit Text, Button, Radio Button)

Aim:

To create a program using UI controls (Text, Edit Text, Button, Radio Button).

Algorithm:

Step 1: Start the eclipse by clicking launcher in ADT bundle.

Step 2: Create a new project by click the file menu and select new android application project.

Step 3: Design in a form Layout by using the component Text view, Plain text, Radio button and

Button.

Step 4: Select the components Text view, Plain text, Radio button and Button & assign name

and value.

Step 5: Write the activity code in main activity and save all.

Step 6: Import package & declare variable in activity program, write the instalialize object.

Step 7: Start SDK manager.

Step 8: Create android virtual devices.

Step 9: Run the android application project.

Step 10: Exit from the eclipse


Program :

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:id="@+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="34dp"
android:layout_marginTop="33dp"
android:text="Enter Your Name" />

<TextView
android:id="@+id/t2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/t1"
android:layout_below="@+id/t1"
android:layout_marginTop="94dp"
android:text="Select Your Gender" />

<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/t2"
android:layout_below="@+id/t2"
android:layout_marginTop="30dp" >
</RadioGroup>
<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="47dp"
android:text="View" />

<EditText
android:id="@+id/p1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/t2"
android:layout_centerHorizontal="true"
android:layout_marginBottom="34dp"
android:ems="10" />

<RadioGroup
android:id="@+id/rg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/radioGroup1"
android:layout_centerHorizontal="true" >

<RadioButton
android:id="@+id/r1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Male" />

<RadioButton
android:id="@+id/r2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />

<RadioButton
android:id="@+id/r3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Others" />
</RadioGroup>

</RelativeLayout>
MainActivity.java

package com.example.radio;

import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import android.widget.EditText;
import android.widget.TextView;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends Activity {


EditText name;
Button view;
TextView res;
// Creating Objects (Instances) for UI
Controls private RadioGroup
radioGender; private RadioButton
radioSex;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name=(EditText)findViewById(R.id.p1);
view = (Button) findViewById(R.id.b1);

radioGender = (RadioGroup) findViewById(R.id.rg);


// btnDisplay = (Button) findViewById(R.id.b1);

// Adding Listener to Button


view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int selectedId = radioGender.getCheckedRadioButtonId();
// find the radio button by returned id
radioSex = (RadioButton) findViewById(selectedId);

Toast.makeText(MainActivity.this, "Your name is "+name.getText()


+"Your Gender is "+radioSex.getText(), Toast.LENGTH_SHORT).show();
}
});
}

@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;
}}
Output :
Result:

Thus the creation of UI controls using program is executed successfully .


5. UI Controls(Check Box, Image Button, Toggle Button)

5a. Check Box

Aim:

To create a checkbox component and display the string using ADT.

Algorithm:

Step 1: Start the Eclipse by Clicking launcher in ADT bundle.

Step 2: Create a new Project by clicking the file menu and select new Android Application

Project.

Step 3: Design a form layout by using the component text view, Edit text & button and

checkbox.

Step 4: select the text view, edit text and button, checkbox components and assign name and

values.

Step 5: write the activity code in main activity then save all.

Step 6: Import package and declare the variably in activity program, write the initialize object.

Step 7: start SDK manager.

Step 8: create android virtual devices.

Step 9: Run the android application project.

Step 10: Exit from the eclipse.


Program:

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:id="@+id/tv1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_alignParentTop="true"

android:layout_marginLeft="68dp"

android:layout_marginTop="53dp"

android:text="enter name" />

<EditText

android:id="@+id/l1"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_below="@+id/tv1"

android:layout_centerHorizontal="true"

android:layout_marginTop="51dp"

android:ems="10" >

<requestFocus />

</EditText>

<TextView

android:id="@+id/tv2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/l1"

android:layout_centerVertical="true"

android:text="select fav subject" />

<CheckBox

android:id="@+id/ch3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_above="@+id/ch4"

android:layout_toRightOf="@+id/tv2"

android:text="computer science" />


<CheckBox

android:id="@+id/ch2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_above="@+id/ch3"

android:layout_alignLeft="@+id/ch3"

android:text="English" />

<CheckBox

android:id="@+id/ch1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_above="@+id/ch2"

android:layout_alignLeft="@+id/ch2"

android:text="Tamil" />

<CheckBox

android:id="@+id/ch4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:layout_alignRight="@+id/ch2"

android:layout_marginBottom="42dp"

android:text="maths" />
<Button

android:id="@+id/b1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/tv1"

android:layout_alignParentBottom="true"

android:text="ok" />

</RelativeLayout>
MainActivity.java

package com.example.checkbox;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;

import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {


EditText name;
private CheckBox chktamil, chkenglish, chkcomputerscience, chkmaths;
private Button btnDisplay;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name=(EditText)findViewById(R.id.l1);
btnDisplay = (Button) findViewById(R.id.b1);

chktamil = (CheckBox) findViewById(R.id.c1);


chkenglish = (CheckBox) findViewById(R.id.c2);
chkcomputerscience = (CheckBox) findViewById(R.id.c3);
chkmaths = (CheckBox) findViewById(R.id.c4);

// Adding Listener to Button


btnDisplay.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v)
{
StringBuffer result = new StringBuffer();
if (chktamil.isChecked())
result.append(chktamil.getText()+" ");
if (chkenglish.isChecked())
result.append(chkenglish.getText()+" ");
if (chkcomputerscience.isChecked())
result.append(chkcomputerscience.getText()+" ");
if (chkmaths.isChecked())
result.append(chkmaths.getText()+" ");

Toast.makeText(MainActivity.this, "your name is "+name.getText()


+" and Your fav subject is "+result.toString(), Toast.LENGTH_LONG).show();
}
});
}

// @Override

@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;
}
}
Output:
Result:

Thus the UI controls CheckBox is executed successfully.


5(B). IMAGE BUTTON

Aim:

To create a Image button component and display the string using ADT.

Algorithm:

Step 1: Start the Eclipse by Clicking launcher in ADT bundle.

Step 2: Create a new Project by clicking the file menu and select new Android Application

Project.

Step 3: Design a form layout by using the component Image button.

Step 4: select the Image button components and assign name and

values. Step 5: write the activity code in main activity then save all.

Step 6: Import package and declare the variably in activity program, write the initialize object.

Step 7: start SDK manager.

Step 8: create android virtual devices.

Step 9: Run the android application project.

Step 10: Exit from the eclipse.


Program:

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

<ImageButton
android:id="@+id/i1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" />

</RelativeLayout>
MainActivity.java :

package com.example.image;

import android.os.Bundle;
import android.app.Activity;
//import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.Toast;

public class MainActivity extends Activity {


ImageButton imageButton;

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

}
public void addListenerOnButton()
{
imageButton=(ImageButton)findViewById(R.id.i1);
imageButton.setOnClickListener(new OnClickListener()
{

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "ImageButton is
Clicked",
Toast.LENGTH_SHORT).show();

}
});
}
}
Output:
Result:

Thus tha creation a UI Controls using Image button is executed successfully.


5(C).TOGGLE BUTTON

Aim:

To create a Toggle button component and display the string using ADT.

Algorithm:

Step 1: Start the Eclipse by Clicking launcher in ADT bundle.

Step 2: Create a new Project by clicking the file menu and select new Android Application

Project.

Step 3: Design a form layout by using the component toggle button.

Step 4: select the toggle button components and assign name and

values. Step 5: write the activity code in main activity then save all.

Step 6: Import package and declare the variably in activity program, write the initialize object.

Step 7: start SDK manager.

Step 8: create android virtual devices.

Step 9: Run the android application project.

Step 10: Exit from the eclipse.


Program:

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

<ToggleButton

android:id="@+id/toggleButton1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:layout_marginTop="79dp"

android:text="ToggleButton" />

<ToggleButton

android:id="@+id/toggleButton2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:layout_alignRight="@+id/toggleButton1"

android:layout_centerVertical="true"

android:text="ToggleButton" />

</RelativeLayout>
MainActivity.java:

package com.example.toggle;

import android.os.Bundle;

import android.app.Activity;

//import android.view.Menu;

import android.view.View;

import android.widget.Button;

import android.widget.Toast;

import android.widget.ToggleButton;

public class MainActivity extends Activity

private ToggleButton toggleButton1, toggleButton2;

private Button buttonSubmit;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

addListenerOnButtonClick();

public void addListenerOnButtonClick(){

//Getting the ToggleButton and Button instance from the layout xml

file toggleButton1=(ToggleButton)findViewById(R.id.tg1);

toggleButton2=(ToggleButton)findViewById(R.id.tg2);

buttonSubmit=(Button)findViewById(R.id.bt1);

//Performing action on button click


buttonSubmit.setOnClickListener(new View.OnClickListener(){

@Override

public void onClick(View view) {

StringBuilder result = new StringBuilder();

result.append("ToggleButton1 : ").append(toggleButton1.getText());

result.append("\nToggleButton2 : ").append(toggleButton2.getText());

//Displaying the message in toast

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

});

}
Output:
Result:

Thus the toggle button is successful executed.


06(a).LIST VIEW
Aim:

To Create A View Components And Display The List View.

Algorithm:

step1: Start the eclipse by clicking launcher in ADT bundle.

step2: Create a new project by click the file menu and select new android application project.

step3: Design in a form layout by using the component list view and Label.

step4: Select the components list view to enter main activity.xml & java code.

step5: Write the activity code main activity and save all.

step6: Import packages and declare the variable in activity program and write the instalialize

object.

step7: Start SDK manager.

step8: Create android virtual device.

step9: Run the android application

project. step10: Exit from the eclipse.


Program:
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"
andr-oid: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:id="@+id/lb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="31dp"
android:layout_marginTop="50dp"
android:text="@string/lb1"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/lb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/lb1"
android:layout_below="@+id/lb1"
android:layout_marginTop="32dp"
android:text="@string/lb2"
android:textAppearance="?android:attr/textAppearanceMedium" />

<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/lb2"
android:layout_below="@+id/lb2"
android:layout_marginLeft="21dp"
android:layout_marginTop="101dp"
tools:listitem="@android:layout/simple_spinner_item" />

</RelativeLayout>
MainActivity.java

package com.example.listview;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class MainActivity extends Activity {


Spinner spnr;

String[] celebrities = {
"TRICHY",
"PERAMBALUR",
"THIRUKOVILUR",
"VPM",
"Tom Cruise",
"Johnny Depp",
"Megan Fox",
"Paul Walker",
"Vin Diesel"
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//
spnr = (Spinner)findViewById(R.id.spinner1);
ArrayAdapter<String> adapter = new
ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item, celebrities);

spnr.setAdapter(adapter);
spnr.setOnItemSelectedListener(
new AdapterView.OnItemSelectedListener() {

0 @Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {

int position = spnr.getSelectedItemPosition();


Toast.makeText(getApplicationContext(),"You have selected
"+celebrities[+position],Toast.LENGTH_LONG).show();
// TODO Auto-generated method stub
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub

} } ); }

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

}
Output:
Result:
Thus the creation of list view displayed successfully.
06(B).RATTINGBAR
Aim:

To create a view components and display the ratting bar.

Algorithm:

step1: Start the eclipse by clicking launcher in ADT bundle.

step2: Create a new project by click the file menu and select new android application project.

step3: Design in a form layout by using the component ratting bar and button.

step4: Select the components list view to enter main activity.xml & java code.

step5: Write the activity code main activity and save all.

step6: Import packages and declare the variable in activity program and write the instalialize

object.

step7: Start SDK manager.

step8: Create android virtual device.

step9: Run the android application

project. step10: Exit from the eclipse


Program.

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

<RatingBar

android:id="@+id/rb1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_alignParentTop="true"

android:layout_marginLeft="14dp"

android:layout_marginTop="102dp" />

<Button

android:id="@+id/b1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/rb1"

android:layout_centerHorizontal="true"
android:layout_marginTop="58dp"

android:text="ok" />

</RelativeLayout>
MainActivity.java

package com.example.ratingbar;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

//import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.RatingBar;

//import android.widget.RatingBar.OnRatingBarChangeListener;

//import android.widget.TextView;

import android.widget.Toast;

//import android.app.AppCompatActivity;

public class MainActivity extends Activity

RatingBar ratingbar;

Button button;

@Override

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

addListenerOnButtonClick();

public void addListenerOnButtonClick(){

ratingbar=(RatingBar)findViewById(R.id.rb1);
button=(Button)findViewById(R.id.bt1);

//Performing action on Button Click

button.setOnClickListener(new View.OnClickListener(){

@Override

public void onClick(View arg0) {

//Getting the rating and displaying it on the toast

String rating=String.valueOf(ratingbar.getRating());

Toast.makeText(getApplicationContext(), rating, Toast.LENGTH_LONG).show();

});

}
Output:
Result:
Thus the creation of Rating bar displayed successfully.
07.CRUD OPERATIONS USING SQLITE DB

Aim:

To create a SQLite-database components and select the particular event in the list.

Algorithm:

Step 1: Start the eclipse by clicking launcher in ADT bundle.

Step 2: Create a new project by click the file menu and select new android application project.

Step 3: Design in a form layout by using the Text box, Label and buttons of Add, view, update

& delete.

Step 4: Connect the Layout with database and Main activity to store the data in the database.

Step 5: Write the activity code main activity and save all.

Step 6: Import packages and declare the variable in activity program and write the instalialize

object.

Step 7: Start SDK manager.

Step 8: Create android virtual device.

Step 9: Run the android application project.

Step 10: Exit from the eclipse


Program:

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="com.example.ex_no_4.MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Reg. No."
android:textAppearance="?android:attr/textAppearanceMedium"
tools:ignore="HardcodedText" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/textView1"
android:layout_toRightOf="@+id/textView1"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/editText1"
android:layout_marginTop="20dp"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/editText2"
android:layout_marginTop="26dp"
android:text="Marks"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:ignore="HardcodedText" />
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView3"
android:layout_alignLeft="@+id/editText2"
android:ems="10"
android:inputType="number" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_alignLeft="@+id/editText1"
android:ems="10"
tools:ignore="TextFields" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView3"
android:layout_marginTop="32dp"
android:text="ADD"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button2"
android:layout_alignBottom="@+id/button2"
android:layout_alignParentRight="true"
android:text="VIEW ALL"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_alignLeft="@+id/editText3"
android:layout_marginLeft="24dp"
android:text="VIEW"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginLeft="27dp"
android:layout_marginTop="18dp"
android:text="UPDATE"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button4"
android:layout_alignBottom="@+id/button4"
android:layout_marginLeft="20dp"
android:layout_toRightOf="@+id/button4"
android:text="DELETE"
tools:ignore="HardcodedText" />
</RelativeLayout>
MainActivity.java:

package com.example.ex_no_4;
import android.support.v7.app.ActionBarActivity;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
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 ActionBarActivity {
EditText name,regno,mark;
Button btnAdd,btnDelete,btnUpdate,btnView,btnViewAll;
SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
regno= (EditText)findViewById(R.id.editText1);
name= (EditText)findViewById(R.id.editText2);
mark=(EditText)findViewById(R.id.editText3);
btnAdd=(Button)findViewById(R.id.button1);
btnView=(Button)findViewById(R.id.button2);
btnViewAll=(Button)findViewById(R.id.button3);
btnUpdate=(Button)findViewById(R.id.button4);
btnDelete=(Button)findViewById(R.id.button5);
db=openOrCreateDatabase("Students", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS student(regno VARCHAR,name
VARCHR,mark
VARCHAR);");
btnAdd.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(regno.getText().toString().trim().length()==0||name.getText().toString().trim().length()==0|
|mark.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter all values");
return;
}d
b.execSQL("INSERT INTO student VALUES('"+regno.getText()+"','"+name.getText()
+"','"+mark.getText()+"');"); showMessage("Success", "Record added");
clearText();
}
});
btnDelete.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(regno.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter Reg. No.");
return; }
Cursor c=db.rawQuery("SELECT * FROM student WHERE
regno='"+regno.getText()+"'", null);
if(c.moveToFirst())
{
db.execSQL("DELETE FROM student WHERE regno='"+regno.getText()+"'");
showMessage("Success", "Record Deleted");
}e
lse
{
showMessage("Error", "Invalid Reg. No.");
}
clearText();
}
});
btnUpdate.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(regno.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter Reg. No.");
return;
}C
ursor c=db.rawQuery("SELECT * FROM student
WHERE regno='"+regno.getText()+"'", null);
if(c.moveToFirst())
{
db.execSQL("UPDATE student SET
name='"+name.getText()+"',mark='"+mark.getText()+"' WHERE regno='"+regno.getText()+"'");
showMessage("Success", "Record Modified");
} else
{
showMessage("Error", "Invalid Reg. No.");
} clearText();
}
});
btnView.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(regno.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter Reg. No.");
return;
}C
ursor c=db.rawQuery("SELECT * FROM student WHERE
regno='"+regno.getText()+"'", null);
if(c.moveToFirst())
{
name.setText(c.getString(1));
mark.setText(c.getString(2));
} else
{
showMessage("Error", "Invalid Reg. No.");
clearText();
}
}
});
btnViewAll.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Cursor c=db.rawQuery("SELECT * FROM student", null);
if(c.getCount()==0)
{
showMessage("Error", "No records found");
return;
}S
tringBuffer buffer=new StringBuffer();
while(c.moveToNext())
{
buffer.append("Reg. No : "+c.getString(0)+"\n");
buffer.append("Name : "+c.getString(1)+"\n");
buffer.append("Mark : "+c.getString(2)+"\n\n");
}s
howMessage("Student Details", buffer.toString());
}
});
}
public void showMessage(String title,String message)
{
Builder builder=new Builder(this);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(message);
builder.show();
}
public void clearText()
{
regno.setText("");
name.setText("");
mark.setText("");
regno.requestFocus();
}
}
Output:
Result:
Thus the creation of SQLite data base is execute successfully.
8. SEND EMAIL IN ANDROID
Aim :

To create a SMS android application and display the string using ADT.

Algorithm:

Step 1: Start the Eclipse by Clicking launcher in ADT bundle.

Step 2: Create a new Project by clicking the file menu and select new Android Application

Project.

Step 3: Design a form layout by using the component Large, Middle and Small.

Step 4: select the Text view, Text Box and Button components and assign name and values.

Step 5: Write the activity code in main activity then save all.

Step 6: Import package and declare the variably in activity program, write the initialize

object.

Step 7: Start SDK manager.

Step 8: Create android virtual devices.

Step 9: Run the android application project.

Step 10: Exit from the eclipse.


Program:

activity_main.xml

File : res/layout/main.xml

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

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

android:id="@+id/linearLayout1"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

<TextView

android:id="@+id/textViewPhoneNo"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="To : "

android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText

android:id="@+id/editTextTo"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:inputType="textEmailAddress" >

<requestFocus />

</EditText>

<TextView

android:id="@+id/textViewSubject"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="Subject : "

android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText

android:id="@+id/editTextSubject"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

>

</EditText>

<TextView

android:id="@+id/textViewMessage"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Message : "

android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText

android:id="@+id/editTextMessage"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:gravity="top"

android:inputType="textMultiLine"

android:lines="5" />

<Button

android:id="@+id/buttonSend"
android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="Send" />

</LinearLayout>
Mainactivity.java

package com.mkyong.android;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;

public class SendEmailActivity extends Activity

{ Button buttonSend;

EditText textTo;

EditText textSubject;

EditText textMessage;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

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

textTo = (EditText) findViewById(R.id.editTextTo);

textSubject = (EditText)

findViewById(R.id.editTextSubject);

textMessage = (EditText) findViewById(R.id.editTextMessage);

buttonSend.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {


String to = textTo.getText().toString();

String subject = textSubject.getText().toString();

String message = textMessage.getText().toString();

Intent email = new Intent(Intent.ACTION_SEND);

email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to});

//email.putExtra(Intent.EXTRA_CC, new String[]{ to});

//email.putExtra(Intent.EXTRA_BCC, new String[]{to});

email.putExtra(Intent.EXTRA_SUBJECT, subject);

email.putExtra(Intent.EXTRA_TEXT, message);

//need this to prompts email client

only

email.setType("message/rfc822");

startActivity(Intent.createChooser(email, "Choose an Email client :"));

});

}
Output:
Result:

Thus the Email program is successful execute.


9. TO MAKE A PHONE CALL IN ANDROID

Aim :

To create a phone call in android application and display the string using ADT.

Algorithm:

Step 1: Start the Eclipse by Clicking launcher in ADT bundle.

Step 2: Create a new Project by clicking the file menu and select new Android Application

Project.

Step 3: Design a form layout by using the component Large, Middle and Small.

Step 4: select the Button components and assign name and values.

Step 5: Write the activity code in main activity then save all.

Step 6: Import package and declare the variably in activity program, write the initialize

object.

Step 7: Start SDK manager.

Step 8: Create android virtual devices.

Step 9: Run the android application project.

Step 10: Exit from the eclipse.


Program:

activity_main.xml

File : res/layout/main.xml

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

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

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

<Button

android:id="@+id/buttonCall"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="call 0377778888" />

</LinearLayout>
MainActivity.java:

package com.mkyong.android;

import android.app.Activity;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

public class MainActivity extends Activity

private Button button;

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

button = (Button) findViewById(R.id.buttonCall);

// add button listener

button.setOnClickListener(new OnClickListener()

@Override

public void onClick(View arg0) {

Intent callIntent = new Intent(Intent.ACTION_CALL);

callIntent.setData(Uri.parse("tel:0377778888"));

startActivity(callIntent);
}

});

AndroidManifest.xml:

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

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

package="com.mkyong.android"

android:versionCode="1"

android:versionName="1.0" >

<uses-sdk android:minSdkVersion="10" />

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

<application

android:icon="@drawable/ic_launcher"

android:label="@string/app_name" >

<activity

android:label="@string/app_name"

android:name=".MainActivity" >

<intent-filter >

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

</manifest>
MainActivity.java:

package com.Phone call.android;

import android.app.Activity;

import android.content.Context;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

import android.telephony.PhoneStateListener;

import

android.telephony.TelephonyManager;

import android.util.Log;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

public class MainActivity extends Activity

{ final Context context = this;

private Button button;

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

button = (Button) findViewById(R.id.buttonCall);

// add PhoneStateListener

PhoneCallListener phoneListener = new PhoneCallListener();

TelephonyManager telephonyManager = (TelephonyManager)

this

.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);

// add button listener

button.setOnClickListener(new OnClickListener()

@Override

public void onClick(View arg0) {

Intent callIntent = new Intent(Intent.ACTION_CALL);

callIntent.setData(Uri.parse("tel:0377778888"));

startActivity(callIntent);

});

//monitor phone call activities

private class PhoneCallListener extends PhoneStateListener {

private boolean isPhoneCalling = false;

String LOG_TAG = "LOGGING 123";

@Override

public void onCallStateChanged(int state, String incomingNumber)

{ if (TelephonyManager.CALL_STATE_RINGING == state)

// phone ringing

Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);

if (TelephonyManager.CALL_STATE_OFFHOOK == state) {

// active

Log.i(LOG_TAG, "OFFHOOK");
isPhoneCalling = true;

if (TelephonyManager.CALL_STATE_IDLE == state) {

// run when class initial and phone call ended,

// need detect flag from CALL_STATE_OFFHOOK

Log.i(LOG_TAG, "IDLE");

if (isPhoneCalling) {

Log.i(LOG_TAG, "restart app");

// restart app

Intent i = getBaseContext().getPackageManager()

.getLaunchIntentForPackage( getBaseContext().getP

ackageName());

i. addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

startActivity(i);

isPhoneCalling = false;

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mkyong.android"

android:versionCode="1"

android:versionName="1.0" >

<uses-sdk android:minSdkVersion="10" />

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

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

<application

android:icon="@drawable/ic_launcher"

android:label="@string/app_name" >

<activity

android:label="@string/app_name"

android:name=".MainActivity" >

<intent-filter >

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

</manifest>
Output:
Result :

Thus the phone call in Android application is executed successfully

10. SMS PROGRAM


Aim :

To create a SMS android application and display the string using ADT.

Algorithm:

Step 1: Start the Eclipse by Clicking launcher in ADT bundle.

Step 2: Create a new Project by clicking the file menu and select new Android Application

project

Step 3: Design a form layout by using the component Large, Middle and Small.

Step 4: select the Text view, Text Box and Button components and assign name and values.

Step 5: Write the activity code in main activity then save all.

Step 6: Import package and declare the variably in activity program, write the initialize

object.

Step 7: Start SDK manager.

Step 8: Create android virtual devices.

Step 9: Run the android application project.

Step 10: Exit from the eclipse.


Program:

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:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="62dp"
android:layout_marginTop="44dp"
android:text="Enter the number" />

<EditText
android:id="@+id/et1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tv1"
android:layout_below="@+id/tv1"
android:layout_marginTop="27dp"
android:ems="10" >

<requestFocus />
</EditText>

<TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/tv1"
android:layout_below="@+id/et1"
android:layout_marginTop="28dp"
android:text="Enter the message" />

<EditText
android:id="@+id/et2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tv2"
android:layout_centerVertical="true"
android:ems="10" />

<Button
android:id="@+id/bt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/et2"
android:layout_centerHorizontal="true"
android:layout_marginTop="42dp"
android:text="send" />

</RelativeLayout>
MainActivity.java

package com.example.sms;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.telephony.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {

Button buttonSend;
EditText textPhoneNo;
EditText textSMS;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

buttonSend = (Button) findViewById(R.id.bt);


textPhoneNo = (EditText) findViewById(R.id.et1);
textSMS = (EditText) findViewById(R.id.et2);

buttonSend.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

String phoneNo = textPhoneNo.getText().toString();


String sms = textSMS.getText().toString();

try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, sms, null, null);
Toast.makeText(getApplicationContext(), "SMS Sent!",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again later!",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}

}
});
}
}
Output:
Result:

Thus the SMS program is successful executed.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy