Full Manual Mad2022
Full Manual Mad2022
NAME :
REG.NO :
SUBJECT CODE :
DEVELOPMENT LAB
CLASS : II M.SC., CS
YEAR : 2022-2023
GOVERNMENT ARTS AND SCIENCE COLLEGE
THIRUVENNAINALLUR-607 203, VILLUPURAM. PG
BONAFIDE CERTIFICATE
Date:
Chief Superintendent
CONTENT
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 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.
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;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@Override
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
OutPut :
Result :
Aim:
Algorithm:
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.
<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;
@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) {
}
});
}
}
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 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.
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">
</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">
</FrameLayout>
MainActivity class
package example.javatpoint.com.fragmentexample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
@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;
@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;
@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:
Aim:
To create a program using UI controls (Text, Edit Text, Button, Radio Button).
Algorithm:
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.
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;
@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);
@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:
Aim:
Algorithm:
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.
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"
<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"
<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: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;
@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);
@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()+" ");
// @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:
Aim:
To create a Image button component and display the string using ADT.
Algorithm:
Step 2: Create a new Project by clicking the file menu and select new Android Application
Project.
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.
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;
@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:
Aim:
To create a Toggle button component and display the string using ADT.
Algorithm:
Step 2: Create a new Project by clicking the file menu and select new Android Application
Project.
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.
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;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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);
@Override
result.append("ToggleButton1 : ").append(toggleButton1.getText());
result.append("\nToggleButton2 : ").append(toggleButton2.getText());
Toast.makeText(getApplicationContext(),
result.toString(),Toast.LENGTH_LONG).show();
});
}
Output:
Result:
Algorithm:
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.
<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;
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) {
} } ); }
@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:
Algorithm:
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.
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;
RatingBar ratingbar;
Button button;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButtonClick();
ratingbar=(RatingBar)findViewById(R.id.rb1);
button=(Button)findViewById(R.id.bt1);
button.setOnClickListener(new View.OnClickListener(){
@Override
String rating=String.valueOf(ratingbar.getRating());
});
}
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 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.
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 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.
activity_main.xml
File : res/layout/main.xml
<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;
{ Button buttonSend;
EditText textTo;
EditText textSubject;
EditText textMessage;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textSubject = (EditText)
findViewById(R.id.editTextSubject);
buttonSend.setOnClickListener(new OnClickListener() {
@Override
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, message);
only
email.setType("message/rfc822");
});
}
Output:
Result:
Aim :
To create a phone call in android application and display the string using ADT.
Algorithm:
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.
activity_main.xml
File : res/layout/main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/buttonCall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
</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;
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button.setOnClickListener(new OnClickListener()
@Override
callIntent.setData(Uri.parse("tel:0377778888"));
startActivity(callIntent);
}
});
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mkyong.android"
android:versionCode="1"
android:versionName="1.0" >
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".MainActivity" >
<intent-filter >
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java:
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;
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// add PhoneStateListener
this
.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
button.setOnClickListener(new OnClickListener()
@Override
callIntent.setData(Uri.parse("tel:0377778888"));
startActivity(callIntent);
});
@Override
{ if (TelephonyManager.CALL_STATE_RINGING == state)
// phone ringing
if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
// active
Log.i(LOG_TAG, "OFFHOOK");
isPhoneCalling = true;
if (TelephonyManager.CALL_STATE_IDLE == state) {
Log.i(LOG_TAG, "IDLE");
if (isPhoneCalling) {
// 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" >
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".MainActivity" >
<intent-filter >
</intent-filter>
</activity>
</application>
</manifest>
Output:
Result :
To create a SMS android application and display the string using ADT.
Algorithm:
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.
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.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
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: