0% found this document useful (0 votes)
11 views49 pages

Android Programming Guide for BCA Students

The document outlines a series of Android programming exercises for students at JAIRAM ARTS & SCIENCE COLLEGE. It includes detailed instructions for creating applications that demonstrate Android resources, layouts, intents, and user interfaces. Each section provides the aim, program description, procedure, and source code for the respective applications.
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)
11 views49 pages

Android Programming Guide for BCA Students

The document outlines a series of Android programming exercises for students at JAIRAM ARTS & SCIENCE COLLEGE. It includes detailed instructions for creating applications that demonstrate Android resources, layouts, intents, and user interfaces. Each section provides the aim, program description, procedure, and source code for the respective applications.
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

JAIRAM ARTS & SCIENCE COLLEGE, SALEM – 08

CLASS : III BCA SUBJECT: ANDROID PROGRAMMING


SUB. CODE: 19UCASP02 NO. OF PROGRAMS : 10

1. APPLICATION ABOUT ANDROID RESOURCES


AIM:
To write a android program to showing resources on Android application environment.
PROGRAM DESCRIPTION:
 In this program shows how to work with Android Studio Environment.
 Its shows
1. How to Install Android Studio
2. How to create new Application
3. How to make Design and Code for that application and
4. How to run the application
PROCEDURE:
Step 1: Install Android Studio IDE in computer.
It’s built following components:
a) Android Studio IDE.
b) Android SDK tools.
c) Android platform.
d) Android emulator system image with Google APIs.
Step 2: Open android studio under the Quick start menu, start -> Android studio.
Step 3: On the "Create New Project" window that opens, name your project "Welcome".
If you choose to, set the company domain as desired*.
Note where the project file location is and change it if desired.
Package name built automatically based on project name.
Select development language. JAVA or KOTLIN, Default language is JAVA.
Click "Next."
Step 4: Make sure on that "Phone and Tablet" is the only box that is checked.
Click "Next."

Step 5: In Activity window select “Empty Activity” and click “Next”.


Step 6: Leave all of the Activity name fields as they are.
Click "Finish."
Step 7: IDE window Elements

1. The toolbar lets you carry out a wide range of actions, including running your app and
launching Android tools.
2. The navigation bar helps you navigate through your project and open files for editing. It
provides a more compact view of the structure visible in the Project window.
3. The editor window is where you create and modify code. Depending on the current file
type, the editor can change. For example, when viewing a layout file, the editor displays the
Layout Editor.
4. The tool window bar runs around the outside of the IDE window and contains the buttons
that allow you to expand or collapse individual tool windows.
5. The tool windows give you access to specific tasks like project management, search,
version control, and more. You can expand them and collapse them.
6. The status bar displays the status of your project and the IDE itself, as well as any warnings
or messages.
Step 8: Design the Window with the help of Controls and its properties.
Step 9: Write a Source code for the project.

SOURCE CODE:
 Android studio auto generates code for activity_main.xml file. User may edit content with
the Design View or Code View. In Design View palettes show different types of Controls to
use the project.
activity_main.xml
Design View:

Code View:
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<TextView
android:layout_width="363dp"
android:layout_height="58dp"
android:text="My First Android Program"
android:textColor="@android:color/holo_red_dark"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.682"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</[Link]>

[Link]
package [Link].application1;
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
}

Step 10: Run the android application


 To run the android application, click the run icon on the toolbar or simply press Shift + F10.
OUTPUT:
2. APPLICATION ABOUT ANDROID LAYOUTS
AIM:
To write a android program to shows layouts in android environment.
PROGRAM DESCRIPTION:
In this program design the application with different layout.
Layout: A layout defines the structure for a user interface in your app, such as in an activity. All
elements in the layout are built using a hierarchy of View and ViewGroup objects.
A View usually draws something the user can see and interact with. Whereas a ViewGroup is an
invisible container that defines the layout structure for View and other ViewGroup objects,
Layout Types:
a) Linear Layout - LinearLayout is a view group that aligns all children in a single
direction, vertically or horizontally.
b) Relative Layout - RelativeLayout is a view group that displays child views in relative
positions.
c) Table Layout - TableLayout is a view that groups views into rows and columns.
d) Absolute Layout - AbsoluteLayout enables you to specify the exact location of its
children.
e) Frame Layout - The FrameLayout is a placeholder on screen that you can use to display
a single view.
f) List View - ListView is a view group that displays a list of scrollable items.
g) Grid View - GridView is a ViewGroup that displays items in a two-dimensional,
scrollable grid.
PROCEDURE:
Step 1: Open android studio under the Quick start menu, start -> Android studio.
Step 2: On the "Create New Project" window that opens, name your project "LayoutAndroid".
Set the company domain as desired*.
Note where the project file location is and change it if desired.
Package name built automatically based on project name.
Select development language. JAVA or KOTLIN, Default language is JAVA.
Click "Next."
Step 3: Make sure on that "Phone and Tablet" is the only box that is checked.
Click "Next."
Step 4: In Activity window select “Empty Activity” and click “Next”.
Step 5: Leave all of the Activity name fields as they are.
Click "Finish."
Step 6: Select multiple Layout (Nested) for displaying elements on screen.
Step 7: Write the source code for this project.
Step 8: Run the project and get output form emulator.
SOURCE CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFF59D"
tools:context="[Link]">
<!--Light Yellow Color-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/l1"
android:background="#FF9E80">
<!--Light Pink Color-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PROGRAMMING IN"
android:textAllCaps="true"
android:textSize="40dp"
android:textColor="#F44336"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android"
android:textAllCaps="true"
android:textSize="40dp"
android:textColor="#F44336"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@id/l1"
android:background="#039BE5"
android:id="@+id/l2">
<!--Light Blue Color-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PROGRAMMING IN"
android:textAllCaps="true"
android:textSize="30dp"
android:textColor="#76FF03"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android"
android:textAllCaps="true"
android:textSize="30dp"
android:textColor="#76FF03"
/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/l2"
android:background="#7E57C2"
>
<!--Light Purple Color-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"
android:id="@+id/b1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"
android:layout_toRightOf="@id/b1"
android:id="@+id/b2"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3"
android:layout_below="@id/b1"
android:id="@+id/b3"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 4"
android:layout_below="@id/b2"
android:layout_toRightOf="@id/b3"
/>
</RelativeLayout>
</RelativeLayout>
[Link]
package [Link].application2;

import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
}
OUTPUT:
3. APPLICATION ABOUT INTENT

AIM:
To write a android program to expose intent between two pages.
PROGRAM DESCRIPTION:
 In this program to do the navigation(Intents) between one or more activities with implicitly
or explicitly.
Intents: it used for communicating between the components and it also provide the
connectivity between two applications.
Types:
1) Explicit Intent: Its used to connect the application internally.
2) Implicit Intent: Its used to connect the another application.
PROCEDURE:
Step 1: Open android studio under the Quick start menu, start -> Android studio.
Step 2: On the "Create New Project" window that opens, name your project “Intents".
Set the company domain as desired*.
Note where the project file location is and change it if desired.
Package name built automatically based on project name.
Select development language. JAVA or KOTLIN, Default language is JAVA.
Click "Next."
Step 3: Make sure on that "Phone and Tablet" is the only box that is checked.
Click "Next."
Step 4: In Activity window select “Empty Activity” and click “Next”.
Step 5: Name the Activity as “activity_a.xml” and java file as “[Link]”
Click "Finish."
Step 6: Create New activity in project: Right mouse click on layout folder, then
New -> Activity -> EmptyActivity -> Name the activity as “activity_b.xml”
And Name the java file as “[Link]”
Step 7: Write the source code for this project
Step 8: Run the project and get output from emulator.
activity_a.xml:

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


<RelativeLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".First_Activity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Intent program in Android"
android:layout_marginTop="80dp"
android:textColor="#bb2233"
android:textSize="30dp"
android:layout_centerHorizontal="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Explicit Intent"
android:id="@+id/explicit_Intent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="147dp" />

</RelativeLayout>

activity_b.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Second_Activity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is Second Activity"
android:id="@+id/textView"
android:textSize="35dp"
android:textColor="#1155bb"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />

</RelativeLayout>

[Link]
package [Link].application3;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class First_Activity extends AppCompatActivity


{
Button exp_btn;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_a);
exp_btn = (Button)findViewById([Link].explicit_Intent);
exp_btn.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getBaseContext(),Second_Activity.class);
startActivity(intent);
}
}

);}
}

[Link]
package [Link].application3;
import [Link];
import [Link];
import [Link];

public class Second_Activity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_b);
[Link](getApplicationContext(),"Welcome to Second
Activity",Toast.LENGTH_LONG).show();
}
}
OUTPUT:
4. APPLICATION ABOUT USER INTERFACE

AIM:

To write the android program to intent application with user interface.

PROGRAM DESCRIPTION:

 In this application create an activity that includes two Edit Text, one Text and one Button
fields to get input from user.
 To send the content of the Edit Text to another activity when the button is tapped.
 That Second activity displays the Content from First activity.
 If the users enter wrong data in Edit Text field then first activity shows toast Message “wrong
entry”.

PROCEDURE:

Step 1: Open android studio under the Quick start menu, start -> Android studio.
Step 2: On the "Create New Project" window that opens, name your project “UserInterface".
Set the company domain as desired*.
Note where the project file location is and change it if desired.
Package name built automatically based on project name.
Select development language. JAVA or KOTLIN, Default language is JAVA.
Click "Next."
Step 3: Make sure on that "Phone and Tablet" is the only box that is checked.
Click "Next."
Step 4: In Activity window select “Empty Activity” and click “Next”.
Step 5: Name the Activity as “activity_a.xml” and java file as “[Link]”
Click "Finish."
Step 6: Create New activity in project: Right mouse click on layout folder, then
New -> Activity -> EmptyActivity -> Name the activity as “activity_b.xml”
And Name the java file as “[Link]”.
Step 7: Write the source code for this project.
Step 8: Run the project and get output from emulator.
activity_a.xml:

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


<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ActivityA">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="false"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:text="Login Form"
android:textAppearance="@style/[Link]"
app:layout_constraintBottom_toTopOf="@+id/uname"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.036" />

<EditText
android:id="@+id/uname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="60dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="User Name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.3" />

<EditText
android:id="@+id/pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="60dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="password"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/uname"
app:layout_constraintVertical_bias="0.0" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pass"
app:layout_constraintVertical_bias="0.214" />

</[Link]>
[Link]:

package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class ActivityA extends AppCompatActivity


{
EditText user;
EditText pass;
Button submit;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_a);
user = (EditText)findViewById([Link]);
pass = (EditText)findViewById([Link]);
submit = (Button)findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
validate([Link]().toString(),[Link]().toString());
}
});
}

public void validate(String user, String pass)


{

if([Link]("Jairam") && [Link]("1234") )


{
Intent intent = new Intent([Link],[Link]);
[Link]("name",user);
startActivity(intent);
}
else
{
[Link](getBaseContext(), "Wrong Username & Password",
Toast.LENGTH_SHORT).show();
}
}
}
activity_b.xml:

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


<RelativeLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Second_Activity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:id="@+id/txt2"
android:text="Welcome,"
android:textSize="30dp"
android:textColor="#112233"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:layout_centerHorizontal="true"
android:id="@+id/txt1"
android:textSize="40dp"
android:textColor="#112233"
/>
</RelativeLayout>

[Link]

package [Link];

import [Link];
import [Link];
import [Link];

public class ActivityB extends AppCompatActivity {


TextView text1;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_b);
text1 = (TextView) findViewById([Link].txt1);
Bundle bundle= getIntent().getExtras();
String data = [Link]("name");
[Link](data);
}
}

OUTPUT:
5. APPLICATION ABOUT ANIMATION

AIM:

To write the android program to create Animation.

PROGRAM DESCRIPTION:

 In this program to Design an Activity with one Text Box and Three Buttons.
 Then Create Android Resource Directory under “res” directory on project Explorer
window.
 Then create three Animation Resource files (.xml) for Animation.
 Code the [Link] with Three new methods for Animation that will refer from
Animation Resource files.

PROCEDURE:

Step 1: Open android studio under the Quick start menu, start -> Android studio.
Step 2: On the "Create New Project" window that opens, name your project
“AnimationProject".
Step 3: Make sure on that "Phone and Tablet" is the only box that is checked.
Click "Next."
Step 4: In Activity window select “Empty Activity” and click “Next”.
Step 5: Name the Activity as “activity_main.xml” and java file as “[Link]”
Click "Finish."
Step 6: Create resource xml files for creating animation on this project.
Select “res” folder and right click on mouse then select New ->
“AndroidResourceDirectory”.

Naming that directory as “anim”, its constructed under “res” directory.


Step 7: Then select anim directory and right click on mouse then select New -> “Animation
Resource file”.
Naming that file as blink now “[Link]” file created under “anim” directory.
Do this process for creating [Link] and [Link]
Sept 8: Write the xml source code in corresponding xml files in “anim” directory.
Step 9: Design the “activity_main.xml” page for displaying one textview and three buttons
naming like move, clockwise and blick.
Step 10: Code the “[Link]” code as in source code.
Step 11: Run the code and result will be show in emulator.
SOURCE CODE:

[Link]

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


<set xmlns:android="[Link]
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="600"
android:repeatMode="reverse"
android:repeatCount="infinite"/>
</set>
[Link]

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


<set xmlns:android="[Link]
<rotate xmlns:android="[Link]
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="5000" >
</rotate>

<rotate xmlns:android="[Link]
android:startOffset="5000"
android:fromDegrees="360"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="5000" >
</rotate>
</set>
[Link]

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


<set
xmlns:android="[Link]
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">

<translate
android:fromXDelta="0%p"
android:toXDelta="75%p"
android:duration="800" />
</set>

activity_main.xml

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


<RelativeLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="@+id/text"
android:textSize="35dp"
android:textColor="#112255"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"/>

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginStart="73dp"
android:layout_marginLeft="73dp"
android:layout_marginTop="122dp"
android:layout_marginEnd="50dp"
android:layout_marginRight="50dp"
android:layout_marginBottom="50dp"
android:onClick="move"
android:text="Move" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginStart="214dp"
android:layout_marginLeft="214dp"
android:layout_marginTop="117dp"
android:layout_toRightOf="@+id/button1"
android:onClick="clockwise"
android:text="clockwise" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginStart="145dp"
android:layout_marginLeft="145dp"
android:layout_marginTop="25dp"
android:onClick="blink"
android:text="blink" />
</RelativeLayout>

[Link]

package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


TextView txt;
Animation clockwise;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
public void clockwise(View view)
{
TextView txt = (TextView)findViewById([Link]);
Animation animation = [Link](getApplicationContext(),
[Link]);
[Link](animation);
}
public void blink(View view)
{
TextView txt = (TextView)findViewById([Link]);
Animation animation = [Link](getApplicationContext(),
[Link]);
[Link](animation);
}
public void move(View view)
{
TextView txt = (TextView)findViewById([Link]);
Animation animation = [Link](getApplicationContext(),
[Link]);
[Link](animation);
}
}
OUTPUT:

6.

APPLICATION ABOUT SQLITE I


AIM:

To Write a Android program to access SQLITE I Application.

Program Description:

 In this Application Connect the SQLITE I database with the help of [Link] class
 First Design the Activity with one Text Box, one Edit Text and two buttons.
 Create [Link] Class for Create, Insert, Update and Retrieve the data in SQLITE I.
 Code the [Link] Class file to connect Activity page and SQLITE I.

PROCEDURE:

Step 1: Open android studio under the Quick start menu, start -> Android studio.
Step 2: On the "Create New Project" window that opens, name your project
“DataBaseProject".
Step 3: Make sure on that "Phone and Tablet" is the only box that is checked.
Click "Next."
Step 4: In Activity window select “Empty Activity” and click “Next”.
Step 5: Name the Activity as “activity_main.xml” and java file as “[Link]”
Click "Finish."
Step 6: Create another Java Class file as “[Link]” for creating, inserting and retrieving
data from SQLite.
Step 7: Design the activity_main.xml with two text view, one Edit text and two buttons.
Step 8: Code the [Link] as in Source Code.
Step 9: Run the project and get output from Emulator.
SOURCE CODE:

activity_main.xml:

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


<RelativeLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SQLite DataBase"
android:layout_centerHorizontal="true"
android:layout_marginTop="80dp"
android:textSize="35dp"
android:textColor="#112233"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Your Name"
android:layout_marginTop="150dp"
android:textSize="20dp"
android:textColor="#552233"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Name"
android:id="@+id/name"
android:layout_marginTop="150dp"
android:layout_marginLeft="200dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Data"
android:id="@+id/add"
android:layout_marginLeft="50dp"
android:layout_marginTop="200dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View Data"
android:id="@+id/view"
android:layout_marginLeft="200dp"
android:layout_marginTop="200dp"/>
</RelativeLayout>

[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class DBHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "[Link]";
public static final String TABLE_NAME = "Person";
public static final String COL_1 = "NAME";
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
[Link]("create table " + TABLE_NAME +" (NAME TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
[Link]("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
public boolean insertData(String name) {
SQLiteDatabase db = [Link]();
ContentValues contentValues = new ContentValues();
[Link](COL_1,name);
long result = [Link](TABLE_NAME,null ,contentValues);
if(result == -1)
return false;
else
return true;
}
public Cursor getAllData() {
SQLiteDatabase db = [Link]();
Cursor res = [Link]("select * from "+TABLE_NAME,null);
return res;
}

[Link]
package [Link];

import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

DBHelper dbH;
EditText Ename;
Button AddBt,ViewBt;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
dbH = new DBHelper(this);
Ename = (EditText)findViewById([Link]);
AddBt = (Button)findViewById([Link]);
ViewBt=(Button)findViewById([Link]);
AddData();
ViewAll();
}
public void AddData() {
[Link](
new [Link]() {
@Override
public void onClick(View v) {
boolean isInserted = [Link]([Link]().toString());
if(isInserted == true)
[Link]([Link],"Data
Inserted",Toast.LENGTH_LONG).show();
else
[Link]([Link],"Data not
Inserted",Toast.LENGTH_LONG).show();
}
}
);
}

public void ViewAll() {


[Link](
new [Link]() {
@Override
public void onClick(View v) {
Cursor res = [Link]();
if([Link]() == 0) {
// show message
showMessage("Error","Nothing found");
return;
}

StringBuffer buffer = new StringBuffer();


while ([Link]()) {
[Link]("Name :"+ [Link](0)+"\n");
}

// Show all data


showMessage("Data",[Link]());
}
}
);
}

public void showMessage(String title,String Message){


[Link] builder = new [Link](this);
[Link](true);
[Link](title);
[Link](Message);
[Link]();
}

OUTPUT:
7. CALCULATOR APP IN ANDROID
AIM:

To Write a Android program to create Simple Calculator Application.

Program Description:

 In this Application Create a Simple Calculator.


 Design the layout with Two Text box, two Edit text and six buttons.
 Perform Calculation of Two Numbers from the Edit text field when the relevant buttons are
clicked.
 For Each calculation to create required methods in [Link] class file.
 The result will be shown in Text box.

PROCEDURE:

Step 1: Open android studio under the Quick start menu, start -> Android studio.
Step 2: On the "Create New Project" window that opens, name your project “Calculator".
Step 3: Make sure on that "Phone and Tablet" is the only box that is checked.
Click "Next."
Step 4: In Activity window select “Empty Activity” and click “Next”.
Step 5: Name the Activity as “activity_main.xml” and java file as “[Link]”
Click "Finish."
Step 6: Design the activity_main.xml with Two Text view, Two Edit Text and Six Button
controls.

Step 7: Code the [Link] file as in Source code.


Step 8: Run the project and get output form Emulator.

Source code:

activity_main.xml

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


<RelativeLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CALCULATOR"
android:textColor="#E91E63"
android:textSize="40dp"
android:layout_marginTop="50dp"
android:layout_centerHorizontal="true"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="First Number"
android:id="@+id/ET1"
android:layout_marginTop="200dp"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Second Number"
android:id="@+id/ET2"
android:layout_marginTop="250dp"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Result"
android:id="@+id/result"
android:textColor="#E91E63"
android:textSize="40dp"
android:layout_marginTop="400dp"
android:layout_centerHorizontal="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"
android:id="@+id/add"
android:textSize="30dp"
android:layout_marginTop="500dp"
android:layout_marginLeft="20dp"
android:onClick="addition"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
android:id="@+id/sub"
android:textSize="30dp"
android:layout_marginTop="500dp"
android:layout_marginLeft="150dp"
android:onClick="subtraction"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="*"
android:id="@+id/mul"
android:textSize="30dp"
android:layout_marginTop="500dp"
android:layout_marginLeft="270dp"
android:onClick="multiplication"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/"
android:id="@+id/div"
android:textSize="30dp"
android:layout_marginTop="580dp"
android:layout_marginLeft="20dp"
android:onClick="division"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="POW"
android:id="@+id/pow"
android:textSize="25dp"
android:layout_marginTop="580dp"
android:layout_marginLeft="150dp"
android:onClick="power"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MOD"
android:id="@+id/mod"
android:textSize="25dp"
android:layout_marginTop="580dp"
android:layout_marginLeft="270dp"
android:onClick="mod"
/>
</RelativeLayout>

[Link]

package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

EditText e1,e2;
TextView t1;
double val1, val2;
String s1,s2;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}

public boolean getNumber()


{
e1 = (EditText)findViewById([Link].ET1);
e2 = (EditText)findViewById([Link].ET2);
t1 = (TextView)findViewById([Link]);

s1 = [Link]().toString();
s2 = [Link]().toString();

if([Link](null) && [Link](null))


{
String result = "Please enter a value";
[Link](result);
return false;
}
else
{
val1 = [Link]([Link]().toString());
val2 = [Link]([Link]().toString());
}
return true;
}

public void addtion(View v)


{
if(getNumber())
{
double sum = val1 + val2;
[Link]([Link](sum));
}
}
public void subtraction(View v)
{
if(getNumber())
{
double sum = val1 - val2;
[Link]([Link](sum));
}
}
public void multiplication(View v)
{
if(getNumber())
{
double sum = val1 * val2;
[Link]([Link](sum));
}
}
public void division(View v)
{
if(getNumber())
{
double sum = val1 / val2;
[Link]([Link](sum));
}
}
public void power(View v)
{
if(getNumber())
{
double sum = [Link](val1,val2);
[Link]([Link](sum));
}
}
public void mod(View v)
{
if(getNumber())
{
double sum = val1 % val2;
[Link]([Link](sum));
}
}
}

OUTPUT:
8. SIMPLE ANDROID CAMERA APPLICATION

AIM:
To write a android program for simple camera application.

PROGRAM DESCRIPTION:

 In this application create camera application for android phones.


 Design the layout with One Image View and One Button Control.
 Code the [Link] file with Intent of camera Application, So when click the button
this application opens Camera.

PROCEDURE:

Step 1: Open android studio under the Quick start menu, start -> Android studio.
Step 2: On the "Create New Project" window that opens, name your project
“CameraApplication".
Step 3: Make sure on that "Phone and Tablet" is the only box that is checked.
Click "Next."
Step 4: In Activity window select “Empty Activity” and click “Next”.
Step 5: Name the Activity as “activity_main.xml” and java file as “[Link]”
Click "Finish."
Step 6: Design the “activity_main.xml” with one Image View and one Button control.

Step 7: Code the “[Link]” file as in Source code.

Step 8: Run the project and get output form Emulator.

SOURCE CODE:

activity_main.xml:

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


<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<ImageView
android:id="@+id/imageView"
android:layout_width="206dp"
android:layout_height="307dp"
android:layout_marginStart="113dp"
android:layout_marginLeft="113dp"
android:layout_marginTop="119dp"
android:layout_marginEnd="92dp"
android:layout_marginRight="92dp"
android:layout_marginBottom="305dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@mipmap/ic_launcher" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="173dp"
android:layout_marginLeft="173dp"
android:layout_marginTop="116dp"
android:layout_marginEnd="151dp"
android:layout_marginRight="151dp"
android:layout_marginBottom="141dp"
android:onClick="takePicture"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView" />
</[Link]>

[Link]

package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


private ImageView imgview;
private static final int REQUEST_IMAGE_CAPTURE =101;

@Override
protected void onCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
setContentView([Link].activity_main);
imgview = (ImageView)findViewById([Link]);
}
public void takePicture(View view)
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivity(intent);
}
}

OUTPUT:
9. BASIC LIST VIEW DEMO IN ANDROID

AIM:
To write a Android Program for viewing list of items using List View.

PROGRAM DESCRIPTION:

 In this application create to display number of items in List View.


 Design the layout with One List View Control.
 Code the [Link] with Array of Items listed by List View.
 To run the application its shows the Array Elements in List View, Then Click the List
Item Toast message will be display.

PROCEDURE:

Step 1: Open android studio under the Quick start menu, start -> Android studio.
Step 2: On the "Create New Project" window that opens, name your project “ListViewApp".
Step 3: Make sure on that "Phone and Tablet" is the only box that is checked.
Click "Next."
Step 4: In Activity window select “Empty Activity” and click “Next”.
Step 5: Name the Activity as “activity_main.xml” and java file as “[Link]”
Click "Finish."
Step 6: Design the activity_main.xml file with Linear Layout and One List View controls.

Step 7: Code the “[Link]” file as in Source code.

Step 8: Run the project and get output form Emulator.

SOURCE CODE:

activity_main.xml

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


<RelativeLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#E3E9F3"
/>
</RelativeLayout>

[Link]

package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity


{
ListView ls;
String[] month
={"January","February","March","April","May","June","July","August","September","October",
"November","December"};
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
ls = (ListView)findViewById([Link]);
ArrayAdapter<String> arrayAdapter = new
ArrayAdapter<String>(this,[Link].simple_list_item_1,month);
[Link](arrayAdapter);

[Link](new [Link]() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
TextView tx = (TextView)view;
[Link]([Link],"Item Selected
"+[Link](),Toast.LENGTH_SHORT).show();

}
});
}
}

OUTPUT:
10. SIMPLE GOOGLE MAP APPLICATION IN ANDROID

AIM:

To write a android program to display Google map.

PROGRAM DESCRIPTION:

 In this application display the Google Map.


 Design the layout with one button control and one text control.
 When click the button its shows the Google Map.

PROCEDURE:

Step 1: Open android studio under the Quick start menu, start -> Android studio.
Step 2: On the "Create New Project" window that opens, name your project “GoogleMapApp".
Step 3: Make sure on that "Phone and Tablet" is the only box that is checked.
Click "Next."
Step 4: In Activity window select “Empty Activity” and click “Next”.
Step 5: Name the Activity as “activity_main.xml” and java file as “[Link]”
Click "Finish."
Step 6: Design the “activity_main.xml” file with one button control.

Step 7: Code the “[Link]” file as in source code.

Step 8: Run the project and get output form Emulator.

SOURCE CODE:

activity_main.xml

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


<RelativeLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click below button to open Google Map"
android:textSize="30dp"
android:layout_marginTop="100dp"
android:textColor="@color/black"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="300dp"
android:layout_centerHorizontal="true"
android:text="Google Map"
android:textSize="30dp"
android:onClick="process"
/>
</RelativeLayout>

[Link]

package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
public void process(View view)
{
Intent intent = new Intent(Intent.ACTION_VIEW);
[Link]([Link]("geo:13.75.986830"));
startActivity(intent);
}
}
OUTPUT:

You might also like