Android Programming Guide for BCA Students
Android Programming Guide for BCA Students
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);
}
}
import [Link];
import [Link];
@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:
</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];
@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];
@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:
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:
<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];
@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());
}
});
}
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
OUTPUT:
5. APPLICATION ABOUT ANIMATION
AIM:
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”.
[Link]
<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]
<translate
android:fromXDelta="0%p"
android:toXDelta="75%p"
android:duration="800" />
</set>
activity_main.xml
<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];
6.
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:
<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];
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();
}
}
);
}
OUTPUT:
7. CALCULATOR APP IN ANDROID
AIM:
Program Description:
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.
Source code:
activity_main.xml
<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];
EditText e1,e2;
TextView t1;
double val1, val2;
String s1,s2;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
s1 = [Link]().toString();
s2 = [Link]().toString();
OUTPUT:
8. SIMPLE ANDROID CAMERA APPLICATION
AIM:
To write a android program for simple camera application.
PROGRAM DESCRIPTION:
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.
SOURCE CODE:
activity_main.xml:
<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];
@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:
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.
SOURCE CODE:
activity_main.xml
<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];
[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:
PROGRAM DESCRIPTION:
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.
SOURCE CODE:
activity_main.xml
<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];
@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: