Professional Documents
Culture Documents
1
2
INDEX
3
4
LAB – 1
5
Step 1 : To download the Android Studio, visit the official Android Studio website in your web
browser.
6
Step 4 : "Android Studio Setup" will appear on the screen and click "Next" to
proceed.
Step 5 : Select the components that you want to install and click on the "Next"
button.
7
Step 6 : Now, browse the location where you want to install the Android Studio and
click "Next" to proceed.
Step 7 : Choose a start menu folder for the "Android Studio" shortcut and click the
"Install" button to proceed.
8
Step 8 : After the successful completion of the installation, click on the "Next"
button.
9
10
LAB - 2
Working with J2ME Features
11
import javax.microedition.midlet.*; import
javax.microedition.lcdui.*;
ch.append("cut", null);
ch.append("copy", null);
ch.append("paste", null);
ch.append("delete", null);
ch.setSelectedIndex(1, true);
form.append(ch);
12
Exit = new Command("Exit", Command.EXIT, 1); Back
form.addCommand(View); form.addCommand(Exit);
form1.addCommand(Back);
form.setCommandListener(this);
form1.setCommandListener(this);
form.setItemStateListener(this);
{ display.setCurrent(form);
ch.getSelectedFlags(opt);
opt.length; i++) {
13
if (opt[i]) {
options.setText(values);
form1.append(options); display.setCurrent(form1);
destroyApp(true);
notifyDestroyed();
if (command == Back)
{ display.setCurrent(form);
options.setText("");
if (item == ch1) {
(ch1.getSelectedIndex() == 0)
ch.setSelectedIndex(i, true);
else
14
ch.setSelectedIndex(i, false);
i++;
Output :
15
16
17
c. Input Checking
a) J2me code :
import javax.microedition.lcdui.*; import javax.microedition.midlet.*;
// display manager
// textbox
// command
18
static final Command exitCommand = new Command("Exit",
Command.STOP, 2);
// constructor.
public EventEx1() {
/**
* Start the MIDlet by creating a list of items and associating the * exit
command with it.
*/
mainMenu();
// main menu
void mainMenu() {
display.setCurrent(menu); currentMenu =
"Main";
19
/**
* a generic method that will be called when selected any of * the items on
the list.
*/
public void prepare() { input = new TextBox("Enter some text: ", "", 5,
TextField.ANY); input.addCommand(backCommand);
input.setCommandListener(this); input.setString("");
display.setCurrent(input);
/**
* Test item1.
*/
currentMenu = "item1";
/**
* Test item2.
*/
currentMenu = "item2";
/**
* Test item3.
*/
currentMenu = "item3";
/**
* Test item4.
*/
20
public void testItem4() { prepare();
currentMenu = "item4";
/**
* Handle events.
*/
// go back to menu
mainMenu();
} else {
}}}
OUTPUT :
21
b),c) j2me code:
import javax.microedition.lcdui.Alert; import javax.microedition.lcdui.AlertType; import
22
private TextField password = new TextField("Password:", "", 10, TextField.PASSWORD);
private Form form = new Form("Sign in"); private Command cancel = new
Command("Cancel", Command.CANCEL, 2);
Display.getDisplay(this);
form.append(userName);
form.append(password);
form.addCommand(cancel);
form.addCommand(login);
form.setCommandListener(this);
display.setCurrent(form);
menu();
} else {
tryAgain();
23
}
display.setCurrent(services);
(label.equals("Cancel"))
{ destroyApp(true);
password.getString());
}}
24
OUTPUT :
25
CORRECT USERNAME & PASSWORD :
26
INCORRECT USERNAME AND PASSWORD :
27
LAB - 3
28
Android Application that uses GUI components, Font and Colors
Procedure:
Open Android Stdio and then click on File -> New -> New project.
Then select the Minimum SDK as shown below and click Next.
29
Then select the Empty Activity and click Next.
30
It will take some time to build and load the project.
After completion it will look as given below.
31
Now click on Text as shown below.
Then delete the code which is there and type the code as given below.
Code for Activity_main.xml:
32
<Button android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:gravity="center"
android:text="Change font size"
android:textSize="25sp" />
<Button android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:gravity="center"
android:text="Change color"
android:textSize="25sp" />
</LinearLayout>
Now click on Design and your application will look as given below.
33
Then delete the code which is there and type the code as given below.
Code for MainActivity.java: package com.example.exno1; import
android.graphics.Color; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.view.View; import
android.widget.Button; import android.widget.TextView;
@Override
}
});
34
Button b2= (Button) findViewById(R.id.button2);
b2.setOnClickListener(new View.OnClickListener() {
t.setTextColor(Color.RED);
break;
case 2:
t.setTextColor(Color.GREEN);
break;
case 3:
t.setTextColor(Color.BLUE);
break;
case 4:
t.setTextColor(Color.CYAN);
break;
case 5:
t.setTextColor(Color.YELLOW);
break;
case 6:
t.setTextColor(Color.MAGENTA);
break;
} ch++;
if (ch == 7)
ch = 1;
}
});
}
}
So now the Coding part is also completed.
Now run the application to see the output.
Output:
35
36
Result:
Thus a Simple Android Application that uses GUI components, Font and Colors is developed
and executed successfully.
37
LAB - 4
Develop an application that uses Layout
Managers and event listeners.
Aim :
38
Develop an application that uses Layout Managers and event listeners.
Language : Java
Main_activity.xml file:
<?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:id="@+id/assign"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/tan_background"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/numbers"
android:layout_gravity="center"
android:layout_height="80dp"
android:layout_width="match_parent"
android:textStyle="bold"
android:textSize="30dp"
android:textColor="@color/white"
android:padding="16dp"
android:background="@color/lab1"
android:text="Lab 1" />
<TextView
android:id="@+id/family"
android:layout_gravity="center"
android:layout_height="80dp"
android:layout_width="match_parent"
android:textStyle="bold"
android:textSize="30dp"
android:textColor="@color/white"
android:padding="16dp"
android:background="@color/lab2"
android:text="Lab 2" />
<TextView
android:id="@+id/colors"
android:layout_gravity="center"
android:layout_height="80dp"
android:layout_width="match_parent"
android:textStyle="bold"
android:textSize="30dp"
android:textColor="@color/white"
android:padding="16dp"
android:background="@color/lab3"
39
android:text="Lab 3" />
<TextView
android:id="@+id/phrases"
android:layout_gravity="center"
android:layout_height="80dp"
android:layout_width="match_parent"
android:textStyle="bold"
android:textSize="30dp"
android:textColor="@color/white"
android:padding="16dp"
android:background="@color/lab4"
android:text="Lab 4" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="209dp"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="@+id/like"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginStart="-6dp"
android:padding="10dp"
android:text="👍"
android:textSize="30dp" />
<Button
android:id="@+id/hate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="58dp"
android:layout_toRightOf="@id/like"
android:padding="10dp"
android:text="👎"
android:textSize="30dp" />
</RelativeLayout>
</LinearLayout>
Activity_main.java file
package com.example.mobiledev;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
40
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button likebutton= (Button) findViewById(R.id.like);
Button hatebutton= (Button) findViewById(R.id.hate);
final LinearLayout linearlayout = findViewById(R.id.assign);
likebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
linearlayout.setBackgroundResource(R.color.green);
}
});
hatebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
linearlayout.setBackgroundResource(R.color.red);
}
});
}
}
OUTPUT :
41
<!--<?xml version="1.0" encoding="utf-8"?>-->
<!--<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"-->
<!-- android:orientation="vertical"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent">-->
<!-- <Button-->
<!-- android:id="@+id/button6"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_weight="1"-->
<!-- android:text="Button" />-->
<!-- <Button-->
<!-- android:id="@+id/button4"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_weight="1"-->
<!-- android:text="Button" />-->
<!-- <Button-->
<!-- android:id="@+id/button5"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_weight="1"-->
<!-- android:text="Button" />-->
<!-- <Button-->
<!-- android:id="@+id/button7"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_weight="1"-->
<!-- android:text="Button" />-->
<!-- <Button-->
<!-- android:id="@+id/button8"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_weight="1"-->
<!-- android:text="Button" />-->
<!-- <Button-->
<!-- android:id="@+id/button9"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_weight="1"-->
<!-- android:text="Button" />-->
<!-- <Button-->
<!-- android:id="@+id/button9"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_weight="1"-->
42
<!-- android:text="Button" />-->
<!-- <Button-->
<!-- android:id="@+id/button9"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_weight="1"-->
<!-- android:text="Button" />-->
<!-- </LinearLayout>-->
<!-- </LinearLayout>-->
43
LAB - 5
Develop a native calculator application
44
Aim : develop a native calculator application
Language : Java
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp">
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="numberDecimal"
android:textSize="20sp" />
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="numberDecimal"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp">
<Button
android:id="@+id/Add"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="+"
android:textSize="30sp"/>
<Button
android:id="@+id/Sub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
45
android:layout_weight="1"
android:text="-"
android:textSize="30sp"/>
<Button
android:id="@+id/Mul"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="*"
android:textSize="30sp"/>
<Button
android:id="@+id/Div"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="/"
android:textSize="30sp"/>
</LinearLayout>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:textColor="@color/white"
android:text="Answer is"
android:textSize="30sp"
android:gravity="center"/>
</LinearLayout>
Mainactivity.java
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
@Override
public void onCreate(Bundle savedInstanceState)
{
46
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// set a listener
Add.setOnClickListener(this);
Sub.setOnClickListener(this);
Mul.setOnClickListener(this);
Div.setOnClickListener(this);
}
@Override
public void onClick (View v)
{
float num1 = 0;
float num2 = 0;
float result = 0;
String oper = "";
// defines the button that has been clicked and performs the
corresponding operation
// write operation into oper, we will use it later for output
switch (v.getId())
{
case R.id.Add:
oper = "+";
result = num1 + num2;
break;
case R.id.Sub:
oper = "-";
result = num1 - num2;
break;
case R.id.Mul:
oper = "*";
result = num1 * num2;
break;
case R.id.Div:
oper = "/";
result = num1 / num2;
break;
default:
break;
}
47
// form the output line
Result.setText(num1 + " " + oper + " " + num2 + " = " + result);
}
}
output
48
49
LAB - 6
Write an application that draws basic
graphical primitives on the screen
50
Aim : To develop a Simple Android Application that draws basic Graphical
Primitives on the screen..
Language : Java
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ImageView android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView" /> </RelativeLayout>
51
{
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
//Creating a Bitmap
//Creating the Paint Object and set its color & TextSize Paint paint = new
Paint(); paint.setColor(Color.BLUE); paint.setTextSize(50); //To draw a
Rectangle canvas.drawText("Rectangle", 420, 150, paint);
canvas.drawRect(400, 200, 650, 700, paint);
}}
Output:
52
53
LAB – 7
Develop an application that makes use of
database.
54
Aim : Develop an application that makes use of database.
Language : Java
MainActivity.java
package com.example.useofdatabase;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
@Override
e1 = (EditText) findViewById(R.id.student_name);
e2 = (EditText) findViewById(R.id.student_roll);
e3 = (EditText) findViewById(R.id.branch_name);
}
55
bf.append("Name : " + c.getString(0) + "\n");
bf.append("Roll No : " + c.getString(1) + "\n");
bf.append("Branch : " + c.getString(2) + "\n");
}
showDialog("Data", bf.toString());
}
}
DBHelper.java
package com.example.useofdatabase;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
// Our database
@Override
56
public void onCreate(SQLiteDatabase db) {
@Override
onCreate(db);
cv.put("sname", student_name);
cv.put("rollno", student_roll);
cv.put("branch", branch_name);
57
}
activity_main.xml
<androidx.constraintlayout.widget.ConstraintLayout
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:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="30dp"
android:text="Student Name"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
58
android:id="@+id/student_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="80dp"
android:layout_marginEnd="30dp"
android:ems="10"
android:inputType="textPersonName"
android:minHeight="48dp"
android:text="Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="30dp"
android:text="Roll Number"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/student_name" />
59
<EditText
android:id="@+id/student_roll"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="30dp"
android:layout_marginRight="30dp"
android:ems="10"
android:inputType="textPersonName"
android:minHeight="48dp"
android:text="Roll no."
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="30dp"
android:text="Branch"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
60
app:layout_constraintTop_toBottomOf="@+id/student_roll" />
<EditText
android:id="@+id/branch_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="30dp"
android:layout_marginBottom="372dp"
android:autoText="true"
android:ems="10"
android:inputType="textPersonName"
android:minHeight="48dp"
android:text="Branch"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/textView3" />
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="0dp"
android:layout_height="71dp"
android:layout_marginStart="25dp"
android:layout_marginTop="458dp"
android:layout_marginEnd="25dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
61
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save"
android:onClick="insert"/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Clear"
android:onClick="clear"/>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="View"
android:onClick="viewData"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
62
Ouput : -
63
LAB – 8
Develop an application that makes use of
RSS Feed.
64
Aim : Develop an application that makes use of RSS Feed.
Language : Java
65
package com.example.madlab8;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.InputDevice;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
ListView lvRSS;
ArrayList<String> titles;
ArrayList<String> links;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
66
67
68
return exception;
@Override
super.onPostExecute(s);
lvRSS.setAdapter(adapter);
progressDialog.dismiss();
<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
="match_parent"
android
:layout_height
="match_parent"
android
:orientation
="vertical"
tools:context
=".MainActivity"
>
<ListView
android
:id="@+id/lvRSS"
android
:layout_width
="match_parent"
android
:layout_height
="match_parent"
/>
</LinearLayout
>
Step 4 : Code for AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
category
< android:name="android.intent.category.LAUNCHER"
/>
package="com.example.madlab8"
</
intent-filter
> >
<uses-permission
</
activity
> android:name="android.permission.INTERNET"
></uses-permission>
<application
</application
>
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
</manifest>
Step 5 : Output
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" 70
android:theme="@style/Theme.MADLab8">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
LAB – 9
Implement an application that implements multithreading
71
72
LAB – 10
Develop a native application that uses GPS location
information.
73
74