0% found this document useful (0 votes)
5 views214 pages

Mad Manual (Solved)

The document provides a detailed guide on installing and using the Android operating system, including practical exercises for programming in Java. It outlines steps for installation, differences between JVM and DVM, and includes sample code for displaying messages and user information in Android applications. The document also emphasizes the importance of development tools and environments in Android programming.

Uploaded by

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

Mad Manual (Solved)

The document provides a detailed guide on installing and using the Android operating system, including practical exercises for programming in Java. It outlines steps for installation, differences between JVM and DVM, and includes sample code for displaying messages and user information in Android applications. The document also emphasizes the importance of development tools and environments in Android programming.

Uploaded by

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

r-

i, Co'ff}tx)"le..,_va:frous ope'1fQ"t1h3 s3s t-e rn


w,+h And~ord os.

P'<>ocifcaJ '"oe\a_,:-gJ ~uestfons

~ Lfs t d~FFQ'le.nt A-_Dd'fo1d o.s. VQ 'oS10YJ •


-----,-,~> • Ct,tpca ke., Icec~orn sanc\w,tc.h
0

Dcrou.t 3~~ £eon


0
O

D S-c\ of~ ~ k-fbkot


' KOJD ~ LolHpop
~ _@'~~.lyr(2od .. 1-l)a-rsh.Qrnq) low
0
l-4on~cornb O
No_goJ:
!l D~0o__ .. Pfe,
0
A-nd1T))d 1D • Anam~ d j_j_

Stcrt-e.. cho~dQ1-tsncs o~ and--ro1d ope--rcili'n,g _s__ys\-e_rn.


--,,) Nf?Q, ~,0d CCY<DYn\JY)~CCU7Gn
0

• A )te"fne,J--Q., KQ(!bC>cod,,S,.
" ~nn'U'red ToOY)S)"<)?ssron
• ND -Touched ce:>nh--ol
" AuJ-orQ")ct.h<bo D .
• vJi"r-ceJess A pp ddwnle)ctd·

~ DrroL0 the., arch1t£2cJ-umJ dfogoarn oP Anc\Y01d OS-


f\pp)Fc-~tf oh.9
r ------ .
l
(
~oMej l Con-L qc_t~ [~hcr;e5 J
ISMS I [ [-_ )~) (L ii I [_~lrnd~ ~/
App)~('(Jt\0n•·1 rl '°})'i)( (t1t'1 ~-

I A· 1
111• >1 :•qr, !:l'j ll~~~c\Q''.' tli~no1•~ J,, n;i;.nt p;ovld~j V~(Lv
,., - -
--
~,i:·\crn
----
ele11~~~ j ~"''.' , j \/1 , 11 \ , rl ~'1_'"~:J ( r ri> t', ,-, •, "Yl1 y-,~

___________
l"'\~~;:-,~ {~:; J,'it).)t~. 7

Sl.rrRtce -.._:\r J'f" _;~" ·r\


-1-~-------'
I ' \ .j I ' r r ' ~ .. I ti ~-'t-; I ~b Y l"Jy' ( : l
f - --D,' " v'i 1 \ q I\. l

r - -
I
-
'l !

1,--"=="'-----"--~-,
1
rc-,,L._
Jt\,:.,:h me \'i 1•I!' ti
_
i-.
'---- - -
,v1.:

(\ L l.l_\•/ t)
'f
-.,J
1)r Vf. . .
I

PC> Lu{' ("( 11\ '\ V"\ tq t: · _


\"nC i't ..,
D?l='fe "lenn'ate., b e1tu Qe.r, w~ -ocl o wB DP e'l"cu-1'"!_9
Cl>
0
on<i Anc\~~d ape~~ 09 _+s~s:..:.t"i-e~ =-rr):.__
· -----------,
-~> eu~ndat.DS_ A-odrn,~d
opQT0.1i°D_9 S__:lst-evn o perolllf~ GjSte,m ·

0 'It- wct3 d~veJop onct Q) It- wa.s de.veJC)ped and ~ _


OtDned b~ Mfc.~o-S o~t owned b ~ CioC>'9 le., LLC .
ThccrrpDmti°on .

,® LauY)c,hed ~'D 2.C>o8

f s L0~'f8ows io· 'f's And~~A -::to ·


Dated signature of
Marks Obtained
Teacher

Process Product
Total(50)
Related(35) Related(15)
2 Tn9tall and ConfauTe Java development
i t C3D Andmdid Studio and android SDK:

Pracical Related Questions


L s t all step to înstall androd operautiog system

Step 1: Download Google Android OS.


Step 2 Wte So Îmaqe l e to CoJDVD or 0sB.
Step3 Boat uoum computex uSing CD)DUD oT USB.
Step y Tnstal1 6T TesE Run Go0gle Android in your
COmputer
Step 5: Runring Google Android S in your PC

List vavious IDEs that Can be used to exeute android


opesating Sustem
1 Eclipse
2 NetBeanS
3. Tntells *tresaseesss

V s u a l Studio
5. RAD Studio

ExerciSe

W h a t fs TDE why Java developmenE toolkit fs e ssential


to instal1 on android operating System
An nte qrated development enviroment CtDE) Te a
software applitaion that provides facilihies to compute
proqrammeTS for Sof tware development
3DX provides too)s such as Java compiler used by
TDEs and SDKs For developing Java program and
Android deveop in Java lamauage

9 Differeniate between JVM and DVM.


DVM JVM

1THiS Reaister based T s Stock based

T t Suppost Andmoid oper- 2 TH Support mulhple


CLhing System Onlu OpeTating System

3 For DVM vern few Re-tool 3 for JvM many Re-tools


Ose available Are available

Here h e exeutable s Here executable is JAR


APK -
Dated signature of
Marks Obtained
Teacher

Process Product
Total(50)
Related(35) Related(15)
r - - -~ _J?rrnilicoJ ReletJ-ed .cquasHb-os.

lf.s t ba.src a<29w'Ye.ment n)Y CO'nh3urnn3 u Y)ci'rOfd _OpQ_g_Q::


f::fn.9 s ~s t-e. 'so)•
·--) 1 · M,c.-.o.sc~t W 1ndDlDS ~)~I lb (32--b ,-t {jY 64-b'lt)
0
0

1. 3 G-B R-AM rn~n~mLlm 8&8 RA)--1\ rno..x~rnuY().


1

3 · .2G-£ oF QVOJ\Clb\e.. disk S?oce r<'l<~\,~rnurn-


~ . I Cl_)? X ~ D O m ~'(")~mu'('() s L 'Yee..Y'l 'ofl s O 101D 'O .

:i)l wh~ b~\:ecc,c\e_ CQY)ODt 'n_\\--) \n 'A-Dd'YDlc\ - - ~


- - ) _AY)e1"{\),A ctses 'Dvr-1, (Do\v~k_ v1,t_llru T'l)Qth~be...J ~nstE>od
oP JC\vo.. Vi'>'\• To oUn o_ :XovCA B8t-ecOdQ... ~ciLL be~ct jVM
(:JaYCL V~e-h..taJ Mo.th~ne,)

Exe'ocJse_

l> 1
V"-lha±- fs QLD'lo Tjpes )Y) Goo'(\\e_<s,
> A 2wlct ~PQ.. de.teo~)\')e_ how 0.'r) a__pp Fe PQ~ct3ed,. 8~
c\efq_wt 1 +he__ Rn<lrro~d plu3 - fn )o LD Ci-oad le.. s U-,f)pDo-r--5
-+too dff-FQ'oent 13?-e.S o~ 'bw\ds deb~ one oeJeose...

0 5 ><P \ OJY, b u1 ld pm cess ,\, on~ YO.o,d ~


~ i , Tue CC>Yr)?,le-rS C<'.Ynveors ~OU'a source.. codG. \'Ot-o
'I)&-)( R \e__ co '1~ c..h in dude__ bj \-e. c.od e ·
~- me A-9k PQc.kq_ges co)l)o,'{)~s +he DE-X RJes o nd
cDn,p1~ed. -a--esouYCe.s Fn\-D s~~,-e_ fi?k •
Dated signature of
Marks Obtained
Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical No:04

Write a program to display HelloWorld

INPUT:

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

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

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"

app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

package com.example.roshpr4;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
}}

OUTPUT:
Write a program to display student name and marks.

INPUT:

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

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

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"

app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

package com.example.roshpr4;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

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

<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: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="Name:Roshni 5th Sem percent:95%"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"

app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

package com.example.roshpr4;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}}
OUPUT:

Dated signature of
Marks Obtained
Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical No:05
Write a program to place Name, Age and mobile number linearly (Vertical) on the display screen
using Linear layout.

INPUT:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name:Roshni Chaudhari" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone number:8652075670" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age:19" />
</LinearLayout>

package com.example.roshpr5;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); }}
OUTPUT:
Write a program to place Name, Age and mobile number centrally on the display screen using Absolute
layout

INPUT:

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

<AbsoluteLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="vertical"

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

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="250px"

android:layout_y="250px"

android:text="Name:Roshni Chaudhari" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="250px"

android:layout_y="300px"

android:text="Phone number:8652075670" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="250px"

android:layout_y="350px"

android:text="Age:19" />

</AbsoluteLayout>
Package com.example.roshpr5;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);}}

OUTPUT:
Dated signature of
Marks Obtained
Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical No:05
Write a program to place Name, Age and mobile number linearly (Vertical) on the display screen
using Linear layout.

INPUT:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name:Roshni Chaudhari" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone number:8652075670" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age:19" />
</LinearLayout>

package com.example.roshpr5;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); }}
OUTPUT:
Write a program to place Name, Age and mobile number centrally on the display screen using Absolute
layout

INPUT:

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

<AbsoluteLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="vertical"

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

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="250px"

android:layout_y="250px"

android:text="Name:Roshni Chaudhari" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="250px"

android:layout_y="300px"

android:text="Phone number:8652075670" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="250px"

android:layout_y="350px"

android:text="Age:19" />

</AbsoluteLayout>
Package com.example.roshpr5;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);}}

OUTPUT:
Dated signature of
Marks Obtained
Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical No: 7
Develop a program to implement Text View and Edit Text.
1) Write a program to accept username and password from the end user using Text View and Edit
Text.

INPUT:
<?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="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/editname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter User Name"
android:textSize="25dp"/>
<EditText
android:id="@+id/editpass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter Password"
android:textSize="25dp"/>
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:textSize="20dp"/>
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="25dp" />
</LinearLayout>

package com.example.rosh_pr7;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText username = (EditText) findViewById(R.id.editname);
final EditText password = (EditText) findViewById(R.id.editpass);
final TextView text = (TextView) findViewById(R.id.text1);
Button btn = (Button) findViewById(R.id.btn1);

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(username.getText().toString().isEmpty()||password.getText().toString().isEmpty()){
text.setText("ALL DETAILS ARE MANDATORY");
}
else {
text.setText("AUTHENTICATION SUCCESSFULL!");
}
}
}); } }
OUTPUT:
2) Write a program to accept and display personal information of the student
INPUT:
<?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="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
/>
<EditText
android:id="@+id/edit1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="UserName"
/>
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="College Name"
/>
<EditText
android:id="@+id/edit2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Your College Name"
/>
<TextView
android:id="@+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Branch"
/>
<EditText
android:id="@+id/edit3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Your Branch"
/>
<TextView
android:id="@+id/text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DOB"
/>
<EditText
android:id="@+id/edit4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Your DOB"
/>
<TextView
android:id="@+id/text5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mobile No"
/>
<EditText
android:id="@+id/edit5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Mobile no"
/>
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:textSize="20dp"/>
<TextView
android:id="@+id/text6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="20dp"
/>
<TextView
android:id="@+id/text7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="20dp"
/>
<TextView
android:id="@+id/text8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="20dp"
/>
<TextView
android:id="@+id/text9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="20dp"
/>
<TextView
android:id="@+id/text10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="20dp"
/>
</LinearLayout>

package com.example.rosh_pr8;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView t1 = (TextView) findViewById(R.id.text1);
final EditText e1 = (EditText) findViewById(R.id.edit1);
final TextView t2 = (TextView) findViewById(R.id.text2);
final EditText e2 = (EditText) findViewById(R.id.edit2);
final TextView t3 = (TextView) findViewById(R.id.text3);
final EditText e3 = (EditText) findViewById(R.id.edit3);
final TextView t4 = (TextView) findViewById(R.id.text4);
final EditText e4 = (EditText) findViewById(R.id.edit4);
final TextView t5 = (TextView) findViewById(R.id.text5);
final EditText e5 = (EditText) findViewById(R.id.edit5);
final TextView t6 = (TextView) findViewById(R.id.text6);
final TextView t7 = (TextView) findViewById(R.id.text7);
final TextView t8 = (TextView) findViewById(R.id.text8);
final TextView t9 = (TextView) findViewById(R.id.text9);
final TextView t10 = (TextView) findViewById(R.id.text10);
Button b1 = (Button) findViewById(R.id.btn1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (e1.getText().toString().isEmpty() || e2.getText().toString().isEmpty() ||
e3.getText().toString().isEmpty() || e4.getText().toString().isEmpty() ||
e5.getText().toString().isEmpty()) {
t6.setText("ALL DETAILS ARE MANDATORY");
} else {
t6.setText("First Name: " + e1.getText().toString());
t7.setText("College Name: " + e2.getText().toString());
t8.setText("Branch: " + e3.getText().toString());
t9.setText("DOB: " + e4.getText().toString());
t10.setText("Mobile No: " + e5.getText().toString());
}
} });}}
OUTPUT:

Dated signature of
Marks Obtained
Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical No.:8
1. Write a program to create a first display screen of any search engine using Auto Complete Text
View.
INPUT:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<AutoCompleteTextView
android:id="@+id/actv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Auto Complete Text View"
android:textSize="30dp"/>
</LinearLayout>

package com.example.prac8;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class MainActivity extends AppCompatActivity {

String[] fruits={"Apple","Acai Berry","Apricot","Banana","Blueberry","Cherry","Custard


Apple","Coconut","Dates","Dragon
Fruit","Fig","Grapes","Guava","Kiwi","Lime","Mango","Pear","Olive","Orange","Papaya","Pineapple","
Raspberry","Strawberry","Suger Cane","Tomato","Watermelon"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayAdapter<String> adapter=new ArrayAdapter<>(this,
android.R.layout.select_dialog_item,fruits);
AutoCompleteTextView av1 =(AutoCompleteTextView)findViewById(R.id.actv);
av1.setThreshold(1);
av1.setAdapter(adapter);

}
}
OUTPUT:
2) Write a program to display all the subjects of sixth semester using Auto Complete Text View.
INPUT:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<AutoCompleteTextView
android:id="@+id/actv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Sixth Semester Subject"
android:textSize="30dp"/>
</LinearLayout>

package com.example.prac8;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class MainActivity extends AppCompatActivity {

String[] fruits={"Mobile Application Development","Emerging Trends in Computer & Information


Technology","Wireless and Mobile Networks","Management","Network and Information
Security","Capstone Project-Eecution & Report Writing"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayAdapter<String> adapter=new ArrayAdapter<>(this,
android.R.layout.select_dialog_item,fruits);
AutoCompleteTextView av1 =(AutoCompleteTextView)findViewById(R.id.actv);
av1.setThreshold(1);
av1.setAdapter(adapter);
}
}
OUTPUT:

Dated signature of
Marks Obtained
Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical No:9
INPUT:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="35dp"
android:text="Bluetooth"/>
<ToggleButton
android:id="@+id/tb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:layout_marginTop="60dp"
android:text="Bluetooth ON"
android:textSize="35dp"
android:textOff="Off"
android:textOn="On"/>
<ToggleButton
android:id="@+id/tb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="60dp"
android:layout_marginTop="60dp"
android:text="Bluetooth OFF"
android:textSize="35dp"
android:textOff="Off"
android:textOn="On"/>

<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn"
android:scaleType="fitCenter"
android:layout_marginTop="55dp"
android:layout_marginBottom="85dp"
android:src="@drawable/xyz"/>
</LinearLayout>

package com.example.rosh_pr9;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;
import android.widget.ToggleButton;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private ToggleButton tbt1, tbt2;
private ImageButton button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButtonClick();
}
private void addListenerOnButtonClick(){
tbt1 = (ToggleButton)findViewById(R.id.tb1);
tbt2 = (ToggleButton)findViewById(R.id.tb2);
button = (ImageButton)findViewById(R.id.btn);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
StringBuilder result = new StringBuilder();
result.append("BLUETOOTH :").append(tbt1.getText());
result.append("\n BLUETOOTH :").append(tbt2.getText());

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

Dated signature of
Marks Obtained
Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical N0 :- 10
Write A Program To Create A Login Form For A Social Networking Site.
INPUT:
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="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter User Name :-"
android:textSize="30dp"
android:id="@+id/editname"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter Password :-"
android:textSize="30dp"
android:id="@+id/editpass"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="SUBMIT"
android:textSize="35dp"
android:id="@+id/btn1"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="30dp"
android:id="@+id/text1"/>

</LinearLayout>
MainActivity.Java:-
package com.demo.prac10;

import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText Username=(EditText) findViewById(R.id.editname);
final EditText Password=(EditText) findViewById(R.id.editpass);
Button btn=(Button) findViewById(R.id.btn1);

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Username.getText().toString().isEmpty()||Password.getText().toString().isEmpty())
{
Toast.makeText(MainActivity.this, "ALL DETAILS ARE MANDATORY",
Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(MainActivity.this, "AUTHENTICATION SUCCESSFULLY",
Toast.LENGTH_LONG).show();
}
}
});

}
OUTPUT:

Dated signature of
Marks Obtained
Teacher

Process Product
Total(50)
Related(35) Related(15)
Prcatical no:11
1. Write a program to show five checkboxes and toast selected checkboxes.
INPUT:
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="48dp"
android:text="Choose Your hobbies:"
android:textSize="40dp"
/>

<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/checkBox"
android:text="Painting"
android:layout_marginTop="16dp"
android:textSize="30dp" />

<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/checkBox2"
android:text="Reading"
android:layout_marginTop="16dp"
android:textSize="30dp" />

<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/checkBox3"
android:layout_marginTop="16dp"
android:text="Singing"
android:textSize="30dp" />

<CheckBox
android:id="@+id/checkBox4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Cooking"
android:layout_marginTop="16dp"
android:textSize="30dp" />

<CheckBox
android:id="@+id/checkBox5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Dancing"
android:layout_marginTop="16dp"
android:textSize="30dp"/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button"
android:layout_marginTop="16dp"
android:onClick="Check"
android:textSize="35dp"
android:text="submit" />
</LinearLayout>

MainActivity.java
package com.example.newapplication;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

CheckBox ch, ch1, ch2, ch3, ch4;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ch = (CheckBox) findViewById(R.id.checkBox);
ch1 = (CheckBox) findViewById(R.id.checkBox2);
ch2 = (CheckBox) findViewById(R.id.checkBox3);
ch3 = (CheckBox) findViewById(R.id.checkBox4);
ch4 = (CheckBox) findViewById(R.id.checkBox5);

public void Check(View v) {


if (!ch.isChecked() && !ch1.isChecked() && !ch2.isChecked() && !ch3.isChecked() &&
!ch4.isChecked()) {
String msg = "You have not selected any hobbies ";
Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
} else {
String msg = "You have selected ";

if (ch.isChecked())
msg = msg + "\n Painting ";
if (ch1.isChecked())
msg = msg + "\n Reading ";
if (ch2.isChecked())
msg = msg + "\n Singing ";
if (ch3.isChecked())
msg = msg + "\n Cooking ";
if (ch4.isChecked())
msg = msg + "\n Dancing ";

Toast.makeText(this, msg + " as hobbies",


Toast.LENGTH_LONG).show();
}

}
}
Output:
Dated signature of
Marks Obtained
Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical no.:15
INPUT:
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Single Radio button"
android:textSize="28dp" />

<RadioButton
android:id="@+id/rB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:checked="false"
android:text="Radio Button1"
android:textSize="20dp" />

<RadioButton
android:id="@+id/rB2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_weight="0.13"
android:checked="false"
android:text="Radio button2"
android:textSize="20dp" />

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="20dp"
android:text=" "/>

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:text="Radio button inside RadioGroup"
android:textSize="28dp" />

<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<RadioButton
android:id="@+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:layout_marginTop="15dp"
android:text="Male"
android:textSize="20dp" />

<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.13"
android:checked="false"
android:layout_marginTop="15dp"
android:text="Female"
android:textSize="20dp" />
</RadioGroup>

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/radioGroup"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:textSize="20dp"
android:text="SHOW SELECTED" />

</LinearLayout>

MainActivity.java :
package com.example.newapplication;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

private RadioGroup radioGenderGroup;


private RadioButton radioGenderButton,rB,rB2;
private Button btnDisplay;

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

radioGenderGroup=(RadioGroup)findViewById(R.id.radioGroup);

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

btnDisplay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int selectedId=radioGenderGroup.getCheckedRadioButtonId();
radioGenderButton=(RadioButton)findViewById(selectedId);
rB=(RadioButton)findViewById(R.id.rB);
rB2=(RadioButton)findViewById(R.id.rB2);
StringBuffer msg = new StringBuffer();
if (rB.isChecked()) {
msg.append("Radio Button1 : ").append(rB.getText());
}
if (rB2.isChecked()) {
msg.append("\n Radio Button2 : ").append(rB2.getText());
}
if (radioGenderButton.isChecked()) {
msg.append("\n Radio Button Group : ").append( radioGenderButton.getText());

}
Toast.makeText(getApplicationContext(),msg.append(" are selected").toString() ,
Toast.LENGTH_LONG).show();
}
});

}
}
Output:
Dated signature of
Marks Obtained
Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical No:13

1. Write a program to show following output.

INPUT:

Main activity.java

package com.example.newapplication;

import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

Button b1;
private ProgressDialog progressBar;
private int progressBarStatus = 0;
private Handler progressBarbHandler = new Handler();
private long fileSize = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
progressBar = new ProgressDialog(view.getContext());
progressBar.setCancelable(true);
progressBar.setMessage("File Downloading. .. ");
progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressBar.setProgress(0);
progressBar.setMax(100);
progressBar.show();
progressBarStatus = 0;
fileSize = 0;
new Thread(new Runnable() {
@Override
public void run() {
while (progressBarStatus < 100) {
progressBarStatus = downloadFile();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
progressBarbHandler.post(new Runnable() {
@Override public void run() {
progressBar.setProgress(progressBarStatus);
}
});
}
if (progressBarStatus >= 100) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
} progressBar.dismiss();
}
}
}).start();
}
});
}
public int downloadFile(){
while (fileSize <= 1000000){
fileSize++;
if (fileSize == 100000){
return 10;
}else if (fileSize == 200000)
{
return 20;
}else if (fileSize == 300000) {
return 30;
}else if (fileSize == 400000){
return 40;
}else if (fileSize == 500000){
return 50;
}else if (fileSize == 700000){
return 70;
}else if (fileSize == 800000){
return 80;
}
}
return 100;
}
}

.xml

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


<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Music Player" android:id="@+id/textview"
android:textSize="35dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" "/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="download"
android:id="@+id/button1"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="112dp" />
</LinearLayout>

OUTPUT:
Dated signature of
Marks Obtained
Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical No:14
1. Write a program to show following output. use appropriate view foe the same.
INPUT:
activity_main.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="fill_parent" />
</LinearLayout>

mylist.xml :
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:padding="5dp"
android:textColor="#4d4d4d" />
strings.xml :
<resources>
<string name="app_name">tuesday</string>
<string-array name="array_technology">
<item>Android</item>
<item>Java</item>
<item>Php</item>
<item>Hadoop</item>
<item>Sap</item>
<item>Python</item>
<item>Ajax</item>
<item>C++</item>
<item>Ruby</item>
<item>Rails</item>
<item>.Net</item>
<item>Perl</item>
</string-array>
</resources>

MainActivity.java :
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
ListView listView;
TextView textView;
String[] listItem;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView=(ListView)findViewById(R.id.listView);
textView=(TextView)findViewById(R.id.textView);
listItem = getResources().getStringArray(R.array.array_technology);
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, listItem);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int
position, long l) {
// TODO Auto-generated method stub
String value=adapter.getItem(position);

Toast.makeText(getApplicationContext(),value,Toast.LENGTH_SHORT).show();
}
});
}
}
OUTPUT:
2. Write a program to show 15 buttons using grid view.
INPUT:
activity_main.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Vertical ScrollView example"
android:id="@+id/textView"
android:layout_gravity="center_horizontal"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true" />
<ScrollView
android:layout_marginTop="30dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/scrollView">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 1" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 2" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 3" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 4" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 5" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 6" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 7" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 8" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 9" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 10" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 11" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 12" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 13" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 14" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 15" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 16" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 17" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 18" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 19" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 20" />
</LinearLayout>
</ScrollView>
</LinearLayout>

MainActivity.java
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}}
OUTPUT:
Dated signature of
Marks Obtained
Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical no.:15
1. Write a program to display Toast message.
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World, Toast Example"
android:textSize="25dp" />
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Toast"
android:textSize="20dp"/>
</LinearLayout>

MainActivity.java :
package com.example.prac15;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView text = (TextView) findViewById(R.id.txt);
Button bt = (Button) findViewById(R.id.btn);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Message for you: \n you got mail!",
Toast.LENGTH_SHORT).show();
}
});
}
}

OUTPUT:
2. Write a program to display three checkboxes and one button named “Order”. Once you
click on button it should toast different selected checkboxes along with items individual
and total price.
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity">

<CheckBox
android:id="@+id/cb1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pizza"
android:layout_marginTop="15dp"
android:textSize="30dp"/>
<CheckBox
android:id="@+id/cb2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Coffee"
android:layout_marginTop="15dp"
android:textSize="30dp"/>
<CheckBox
android:id="@+id/cb3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Burger"
android:layout_marginTop="15dp"
android:textSize="30dp"/>
<Button
android:id="@+id/b1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ORDER"
android:layout_marginTop="15dp"
android:textSize="35dp" />
</LinearLayout>

MainActivity.java :
package com.example.prac15;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

CheckBox c1,c2,c3;
Button btn;

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

private void addListenerOnButtonClick() {


c1 = (CheckBox) findViewById(R.id.cb1);
c2 = (CheckBox) findViewById(R.id.cb2);
c3 = (CheckBox) findViewById(R.id.cb3);
btn = (Button) findViewById(R.id.b1);

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int totalamount = 0;
StringBuilder result = new StringBuilder();
result.append("Selected Items:");
if(c1.isChecked()){
result.append("\nPizza 150Rs");
totalamount+=150;
}
if(c2.isChecked()){
result.append("\nCoffee 100Rs");
totalamount+=100;
}
if(c3.isChecked()){
result.append("\nBurger 180Rs");
totalamount+=180;
}
result.append("\nTotal:"+totalamount+"Rs");
Toast.makeText(getApplicationContext(),result.toString(),Toast.LENGTH_LONG).show();
}
});
}
}

Output:
Dated signature of
Marks Obtained
Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical No: 16
Write a program using TimePicker with spinnermode.
INPUT:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity" >
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/in_date"
android:layout_marginTop="82dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SELECT DATE"
android:id="@+id/btn_date"
android:layout_alignBottom="@+id/in_date"
android:layout_toRightOf="@+id/in_date"
android:layout_toEndOf="@+id/in_date" />

<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/in_time"
android:layout_below="@+id/in_date"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SELECT TIME"
android:id="@+id/btn_time"
android:layout_below="@+id/btn_date"
android:layout_alignLeft="@+id/btn_date"
android:layout_alignStart="@+id/btn_date" />
</RelativeLayout>
package com.example.calendar;
/*
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TimePicker;

import java.util.Calendar;

public class MainActivity extends AppCompatActivity implements


View.OnClickListener {
Button btnDatePicker, btnTimePicker;
EditText txtDate, txtTime;
private int mYear, mMonth, mDay, mHour, mMinute;

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

btnDatePicker=(Button)findViewById(R.id.btn_date);
btnTimePicker=(Button)findViewById(R.id.btn_time);
txtDate=(EditText)findViewById(R.id.in_date);
txtTime=(EditText)findViewById(R.id.in_time);

btnDatePicker.setOnClickListener(this);
btnTimePicker.setOnClickListener(this);

}
@Override
public void onClick(View v) {

if (v == btnDatePicker) {

// Get Current Date


final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);

DatePickerDialog datePickerDialog = new DatePickerDialog(this,


new DatePickerDialog.OnDateSetListener() {

@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, intdayOfMonth)
{

txtDate.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);

}
}, mYear, mMonth, mDay);
datePickerDialog.show();
}
if (v == btnTimePicker) {

// Get Current Time


final Calendar c = Calendar.getInstance();
mHour = c.get(Calendar.HOUR_OF_DAY);
mMinute = c.get(Calendar.MINUTE);

// Launch Time Picker Dialog


TimePickerDialog timePickerDialog = new TimePickerDialog(this,
new TimePickerDialog.OnTimeSetListener() {

@Override
public void onTimeSet(TimePicker view, int hourOfDay,
int minute) {

txtTime.setText(hourOfDay + ":" + minute);


}
}, mHour, mMinute, false);
timePickerDialog.show();
}
}

OUTPUT:
Dated signature of
Marks Obtained
Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical No :17
Write a program to create a HelloWorld Activity using all lifecycles methods to display
messages using Log.d
INPUT:
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="25dp"
android:layout_marginTop="40dp"
/>

</LinearLayout>

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("lifecycle","onCreate invoked");
}
@Override
protected void onStart() {
super.onStart();
Log.d("lifecycle","onStart invoked");
}
@Override
protected void onResume() {
super.onResume();
Log.d("lifecycle","onResume invoked");
}
@Override
protected void onPause() {
super.onPause();
Log.d("lifecycle","onPause invoked");
}
@Override
protected void onStop() {
super.onStop();
Log.d("lifecycle","onStop invoked");
}
@Override
protected void onRestart() {
super.onRestart();
Log.d("lifecycle","onRestart invoked");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d("lifecycle","onDestroy invoked");
}
}

OUTPUT:
Dated signature of
Marks Obtained Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical no.18:
1. Write a program to create a text field and a button “Navigate”. When you enter
“www.google.com” and press navigate button it should open google page.

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android" >

<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="60dp"
android:hint="Enter URL"
android:textSize="30dp"
android:ems="10"
/>

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_marginLeft="156dp"
android:layout_marginTop="172dp"
android:text="Navigate"
/>

</LinearLayout>

MainActivity.java :
package com.example.monday;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


Button button;
EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

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


editText = (EditText) findViewById(R.id.editText);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String url=editText.getText().toString();
Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);

}
});
}
}
Output:
2. Write a program to create button “Start Dialer”. When u click on this button it should open
the phone dialer.
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android" >
<Button android:id="@+id/b1" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="250dp"
android:layout_y="250dp"
android:layout_marginTop="300dp"
android:layout_marginLeft="75dp"
android:textSize="30dp"
android:text="Start Dialer" />
</LinearLayout>

MainActivity.java
package com.example.monday1;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


Button bx;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bx=(Button)findViewById(R.id.b1);
bx.setOnClickListener(new View.OnClickListener()
{
@Override public void onClick(View v)
{
Intent intent=new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:0123456789"));
startActivity(intent);

}
});
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.monday1">

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

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Monday1">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Output:
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android" >

<Button android:id="@+id/b1" android:layout_width="wrap_content"


android:layout_height="wrap_content"
android:layout_x="250dp"
android:layout_y="250dp"
android:layout_marginTop="300dp"
android:layout_marginLeft="155dp"
android:text="OPEN SECOND ACTIVITY"
android:onClick="opensecond"/>
</LinearLayout>

MainActivity.java :
package com.example.monday3;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void opensecond(View view)
{
Intent intent=new Intent(this,SecondActivity.class);
startActivity(intent);
}
}

activity_second.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" THIS IS FIRST PROGRAM OF ACTIVITY USING INTENT AND
YOU ARE IN SECOND ACTIVITY"
/>
</LinearLayout>

SecondActivity.java :
package com.example.monday3;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

public class SecondActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
}
}
Output:
Write a program to create two screens. First screen will take one number input from user.
After click on Factorial button, second screen will open and it should display factorial of the
same number. Also specify which type of intent you will use in this case
Activitymain.xml
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android" >

<EditText
android:id="@+id/no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="60dp"
android:layout_marginEnd="8dp"
android:ems="10"
android:hint="Enter a number"
android:textSize="30dp" />

<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="90dp"
android:layout_marginTop="30dp"
android:layout_x="250dp"
android:layout_y="250dp"
android:onClick="opensecond"
android:text="CALCULATE FACTORIAL" />

</LinearLayout>

MainActivity.java
package com.demo.prac_18_1;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import static java.lang.Integer.*;

public class MainActivity extends AppCompatActivity {


EditText num;
int ans;
Button button;
static String item = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.b1);
num = (EditText) findViewById(R.id.no);

public void opensecond(View view)


{

Intent intent=new Intent(this,SecondActivity.class);


startActivity(intent);

String value= num.getText().toString();


int num1= parseInt(value);
ans = fact(num1);
item=item+ans;
}
public static String getMyString(){
return item;
}
private int fact(int nume){
if (nume<2){
return 1;
}else {
return nume*fact(nume-1);
}
}}
Activitysecond.xml
<LinearLayout android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android" >
<TextView
android:id="@+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="30dp"
android:layout_marginTop="150dp"
android:layout_marginLeft="80dp"
/>
</LinearLayout>

Secondactivity.java
package com.demo.prac_18_1;

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

public class SecondActivity extends AppCompatActivity {


TextView text2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
String myValue = MainActivity.getMyString();
text2 = (TextView) findViewById(R.id.textview2);
text2.setText("Factorial of Entered number: " +myValue);
}
}

OUTPUT:
Dated signature of
Marks Obtained
Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical No:19

Activity_main.xml

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


<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Content Provider View "
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="30dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText2"
android:hint="Name"
android:textColorHint="@android:color/holo_blue_light" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText3"
android:layout_below="@+id/editText"
android:layout_alignLeft="@+id/editText2"
android:layout_alignStart="@+id/editText2"
android:layout_alignRight="@+id/editText2"
android:layout_alignEnd="@+id/editText2"
android:hint="Grade"
android:textColorHint="@android:color/holo_blue_bright" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:text="Add Name"
android:layout_below="@+id/editText3"
android:onClick="onClickAddName"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Retrive student"
android:id="@+id/button"
android:layout_below="@+id/button2"
android:layout_alignRight="@+id/editText3"
android:layout_alignEnd="@+id/editText3"
android:layout_alignLeft="@+id/button2"
android:layout_alignStart="@+id/button2"
android:onClick="onClickRetrieveStudents"/>
</LinearLayout>
Students_provider.java

package com.example.rosh_pr19;
import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.text.TextUtils;

import java.util.HashMap;

public class StudentsProvider extends ContentProvider {


static final String PROVIDER_NAME =
"com.example.myapplicationcontent.StudentsProvider";
static final String URL = "content://" + PROVIDER_NAME + "/students";
static final Uri CONTENT_URI = Uri.parse(URL);

static final String _ID = "_id";


static final String NAME = "name";
static final String GRADE = "grade";

private static HashMap<String, String> STUDENTS_PROJECTION_MAP;


static final int STUDENTS = 1;
static final int STUDENT_ID = 2;

static final UriMatcher uriMatcher;


static{
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI(PROVIDER_NAME, "students", STUDENTS);
uriMatcher.addURI(PROVIDER_NAME, "students/#", STUDENT_ID);
}

/**
* Database specific constant declarations
*/

private SQLiteDatabase db;


static final String DATABASE_NAME = "College";
static final String STUDENTS_TABLE_NAME = "students";
static final int DATABASE_VERSION = 1;
static final String CREATE_DB_TABLE =
" CREATE TABLE " + STUDENTS_TABLE_NAME +
" (_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
" name TEXT NOT NULL, " +
" grade TEXT NOT NULL);";

/**
* Helper class that actually creates and manages
* the provider's underlying data repository.
*/

private static class DatabaseHelper extends SQLiteOpenHelper {


DatabaseHelper(Context context){
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_DB_TABLE);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + STUDENTS_TABLE_NAME);
onCreate(db);
}
}

@Override
public boolean onCreate() {
Context context = getContext();
DatabaseHelper dbHelper = new DatabaseHelper(context);

/**
* Create a write able database which will trigger its
* creation if it doesn't already exist.
*/
db = dbHelper.getWritableDatabase();
return (db == null)? false:true;
}

@Override
public Uri insert(Uri uri, ContentValues values) {
/**
* Add a new student record
*/
long rowID = db.insert( STUDENTS_TABLE_NAME, "", values);

/**
* If record is added successfully
*/
if (rowID > 0) {
Uri _uri = ContentUris.withAppendedId(CONTENT_URI, rowID);
getContext().getContentResolver().notifyChange(_uri, null);
return _uri;
}

throw new SQLException("Failed to add a record into " + uri);


}

@Override
public Cursor query(Uri uri, String[] projection,
String selection, String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(STUDENTS_TABLE_NAME);

switch (uriMatcher.match(uri)) {
case STUDENTS:
qb.setProjectionMap(STUDENTS_PROJECTION_MAP);
break;

case STUDENT_ID:
qb.appendWhere( _ID + "=" + uri.getPathSegments().get(1));
break;

default:
}

if (sortOrder == null || sortOrder == ""){


/**
* By default sort on student names
*/
sortOrder = NAME;
}

Cursor c = qb.query(db, projection, selection,


selectionArgs,null, null, sortOrder);
/**
* register to watch a content URI for changes
*/
c.setNotificationUri(getContext().getContentResolver(), uri);
return c;
}

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
int count = 0;
switch (uriMatcher.match(uri)){
case STUDENTS:
count = db.delete(STUDENTS_TABLE_NAME, selection, selectionArgs);
break;

case STUDENT_ID:
String id = uri.getPathSegments().get(1);
count = db.delete( STUDENTS_TABLE_NAME, _ID + " = " + id +
(!TextUtils.isEmpty(selection) ?" AND (" + selection + ')' : ""), selectionArgs);
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}

getContext().getContentResolver().notifyChange(uri, null);
return count;
}

@Override
public int update(Uri uri, ContentValues values,
String selection, String[] selectionArgs) {
int count = 0;
switch (uriMatcher.match(uri)) {
case STUDENTS:
count = db.update(STUDENTS_TABLE_NAME, values, selection, selectionArgs);
break;

case STUDENT_ID:
count = db.update(STUDENTS_TABLE_NAME, values,
_ID + " = " + uri.getPathSegments().get(1) +
(!TextUtils.isEmpty(selection) ? " AND (" +selection + ')' : ""),
selectionArgs);
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri );
}

getContext().getContentResolver().notifyChange(uri, null);
return count;
}

@Override
public String getType(Uri uri) {
switch (uriMatcher.match(uri)){
/**
* Get all student records
*/
case STUDENTS:
return "vnd.android.cursor.dir/vnd.example.students";
/**
* Get a particular student
*/
case STUDENT_ID:
return "vnd.android.cursor.item/vnd.example.students";
default:
throw new IllegalArgumentException("Unsupported URI: " + uri);
}
}
}
Android manifest.xml

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rosh_pr19">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Rosh_pr19">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider android:name="StudentsProvider"
android:authorities="com.example.myapplicationcontent.StudentsProvider"/
</application>
</manifest>

Main Acticity.java

package com.example.rosh_pr19;

import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.example.rosh_pr19.R;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClickAddName(View view) {
// Add a new student record
ContentValues values = new ContentValues();
values.put(StudentsProvider.NAME,
((EditText)findViewById(R.id.editText2)).getText().toString());

values.put(StudentsProvider.GRADE,
((EditText)findViewById(R.id.editText3)).getText().toString());

Uri uri = getContentResolver().insert(


StudentsProvider.CONTENT_URI, values);

Toast.makeText(getBaseContext(),
uri.toString(), Toast.LENGTH_LONG).show();
}
public void onClickRetrieveStudents(View view) {
// Retrieve student records
String URL = "content://com.example.myapplicationcontent.StudentsProvider";

Uri students = Uri.parse(URL);


Cursor c = managedQuery(students, null, null, null, "name");

if (c.moveToFirst()) {
do{
Toast.makeText(this,
c.getString(c.getColumnIndex(StudentsProvider._ID)) +
", " + c.getString(c.getColumnIndex( StudentsProvider.NAME)) +
", " + c.getString(c.getColumnIndex( StudentsProvider.GRADE)),
Toast.LENGTH_SHORT).show();
} while (c.moveToNext());
}
}
}

OUTPUT:

Dated signature of
Marks Obtained Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical No:20

Write a program to display the following output.


INPUT:
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android" >

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:text="Start Services"
android:onClick="startService"
/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Stop Services"
android:id="@+id/button"
android:onClick="stopService"
/>
</LinearLayout>
Main_activity.java
package com.example.pr21;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import com.example.pr21.R;
public class MainActivity extends Activity {
String msg = "Android : ";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(msg, "The onCreate() event");
}
public void startService(View view) {
startService(new Intent(getBaseContext(), MyService.class));
}
// Method to stop the service
public void stopService(View view) {
stopService(new Intent(getBaseContext(), MyService.class));
}
}
My_Service.java
package com.example.pr21;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;

import androidx.annotation.Nullable;
public class MyService extends Service {
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Let it continue running until it is stopped.
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
}
}

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pr21">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Pr21">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".MyService" />
</application>
</manifest>
OUTPUT:
Write a program to start a Wi-Fi using service.
INPUT:
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnOn"
android:text="Turn On Wifi"
android:onClick="startWifi" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Turn Off Wifi"
android:id="@+id/btnOff"
android:onClick="stopWifi" />
</LinearLayout>

MainActivity.java :
package com.example.wifi;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btntOn = (Button)findViewById(R.id.btnOn);
Button btntOff = (Button)findViewById(R.id.btnOff);
btntOn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WifiManager wmgr =
(WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE);
Toast.makeText(MainActivity.this, "Wifi Turn On", Toast.LENGTH_SHORT).show();
wmgr.setWifiEnabled(true);
}
});
btntOff.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WifiManager wmgr =
(WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE);
Toast.makeText(MainActivity.this, "Wifi Turn Off", Toast.LENGTH_SHORT).show();
wmgr.setWifiEnabled(false);
}
});
}
}
AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.wifi">

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Wifi">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


</intent-filter>
</activity>
</application>
</manifest>
OUTPUT:
Dated signature of
Marks Obtained Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical No:20

Write a program to display the following output.


INPUT:
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android" >

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:text="Start Services"
android:onClick="startService"
/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Stop Services"
android:id="@+id/button"
android:onClick="stopService"
/>
</LinearLayout>
Main_activity.java
package com.example.pr21;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import com.example.pr21.R;
public class MainActivity extends Activity {
String msg = "Android : ";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(msg, "The onCreate() event");
}
public void startService(View view) {
startService(new Intent(getBaseContext(), MyService.class));
}
// Method to stop the service
public void stopService(View view) {
stopService(new Intent(getBaseContext(), MyService.class));
}
}
My_Service.java
package com.example.pr21;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;

import androidx.annotation.Nullable;
public class MyService extends Service {
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Let it continue running until it is stopped.
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
}
}

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pr21">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Pr21">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".MyService" />
</application>
</manifest>
OUTPUT:
Write a program to start a Wi-Fi using service.
INPUT:
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnOn"
android:text="Turn On Wifi"
android:onClick="startWifi" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Turn Off Wifi"
android:id="@+id/btnOff"
android:onClick="stopWifi" />
</LinearLayout>

MainActivity.java :
package com.example.wifi;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btntOn = (Button)findViewById(R.id.btnOn);
Button btntOff = (Button)findViewById(R.id.btnOff);
btntOn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WifiManager wmgr =
(WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE);
Toast.makeText(MainActivity.this, "Wifi Turn On", Toast.LENGTH_SHORT).show();
wmgr.setWifiEnabled(true);
}
});
btntOff.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WifiManager wmgr =
(WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE);
Toast.makeText(MainActivity.this, "Wifi Turn Off", Toast.LENGTH_SHORT).show();
wmgr.setWifiEnabled(false);
}
});
}
}
AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.wifi">

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Wifi">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


</intent-filter>
</activity>
</application>
</manifest>
OUTPUT:
Dated signature of
Marks Obtained Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical No.21:
1. Write a program to demonstrate all the system broadcast messages.
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="90dp"
android:onClick="broadcastIntent"
android:text="Send Broadcast" />
</LinearLayout>

MainActivity.java :
package com.example.broadcastreceiver;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {


MyReceiver receiver;
IntentFilter intentFilter;

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

receiver = new MyReceiver();


intentFilter = new IntentFilter("com.example.broadcastreceiver.SOME_ACTION");
}

@Override
protected void onResume() {
super.onResume();
registerReceiver(receiver, intentFilter);
}

@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(receiver);
}
public void broadcastIntent(View view)
{
Intent intent = new Intent("com.example.broadcastreceiver.SOME_ACTION");
sendBroadcast(intent);
}
}

MyReceiver.java :
package com.example.broadcastreceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import android.widget.Toast;

public class MyReceiver extends BroadcastReceiver {


@Override
public void onReceive(Context context, Intent intent) {

Log.d("API123",""+intent.getAction());

if(intent.getAction().equals("com.example.broadcastrceiver.SOME_ACTION"))
Toast.makeText(context, "SOME_ACTION is received",
Toast.LENGTH_LONG).show();

else {
ConnectivityManager cm =
(ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo activeNetwork = cm.getActiveNetworkInfo();


boolean isConnected = activeNetwork != null &&
activeNetwork.isConnectedOrConnecting();
if (isConnected) {
try {
Toast.makeText(context, "Network is connected",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
} else {
Toast.makeText(context, "Network is changed or reconnected",
Toast.LENGTH_LONG).show();
}
}
}
}
AndroidManifest.java :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.broadcastreceiver">

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


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

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Broadcastreceiver">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


</intent-filter>
</activity>
<receiver android:name=".MyReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
</application>

</manifest>
Output:

Dated signature of
Marks Obtained Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical No. 22:
Develop a program to implement sensors.
1) Write a program to display the list of sensors supported by the mobile device.
activity_main.xml
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="92dp"
android:layout_marginTop="114dp"
android:text="TextView" />
</LinearLayout>
MainActivity.java
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
import java.util.List;
public class MainActivity extends Activity {
SensorManager sm = null;
TextView textView1 = null;
List list;
SensorEventListener sel = new SensorEventListener(){
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
public void onSensorChanged(SensorEvent event) {
float[] values = event.values;
textView1.setText("x: "+values[0]+"\ny: "+values[1]+"\nz: "+values[2]);
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

/* Get a SensorManager instance */


sm = (SensorManager)getSystemService(SENSOR_SERVICE);

textView1 = (TextView)findViewById(R.id.textView1);

list = sm.getSensorList(Sensor.TYPE_ACCELEROMETER);
if(list.size()>0){
sm.registerListener(sel, (Sensor) list.get(0),
SensorManager.SENSOR_DELAY_NORMAL);
}else{
Toast.makeText(getBaseContext(), "Error: No Accelerometer.",
Toast.LENGTH_LONG).show();
}
}

@Override
protected void onStop() {
if(list.size()>0){
sm.unregisterListener(sel);
}
super.onStop();
}
}
OUTPUT:
Dated signature of
Marks Obtained Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical No. 23:
Develop a program to build Camera.
INPUT:
activity_main.xml
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:id="@+id/imageView"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:id="@+id/button"
android:text="Click here to capture image "/>
</LinearLayout>
MainActivity.java
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button button ;
ImageView imageView ;
Intent intent ;
public static final int RequestPermissionCode = 1 ; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
imageView = (ImageView) findViewById(R.id.imageView);
EnableRuntimePermission();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
intent = new
Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 7);
}
});}
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 7 && resultCode == RESULT_OK) {
Bitmap bitmap = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(bitmap);
}
}
public void EnableRuntimePermission(){
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,
Manifest.permission.CAMERA)) {
Toast.makeText(MainActivity.this,"CAMERA permission allows us to Access
CAMERA app", Toast.LENGTH_LONG).show();
} else
{ ActivityCompat.requestPermissions(MainActivity.this,new
String[]{Manifest.permission.CAMERA}, RequestPermissionCode); } }
public void onRequestPermissionResult(int RC, String per[], int[] PResult) {
switch (RC) {
case RequestPermissionCode:
if (PResult.length > 0 && PResult[0] ==
PackageManager.PERMISSION_GRANTED) {
Toast.makeText(MainActivity.this,"Permission Granted, Now your application can
access CAMERA.", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(MainActivity.this,"Permission Canceled, Now your application
cannot access CAMERA.", Toast.LENGTH_LONG).show();
} break;
}}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplicationsensor">
<uses-permission android:name="android.permission.CAMERA" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplicationSensor">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


</intent-filter>
</activity>
</application>
</manifest>
OUTPUT:
Dated signature of
Marks Obtained
Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical No. 24:
Develop a program for providing Bluetooth connectivity
INPUT:
activity_main.xml
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/bluetooth"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:text="Bluetooth"
android:textSize="30dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b1"
android:text="Turn On"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b2"
android:text="Get Visible"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b3"
android:text="List Devices"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b4"
android:text="Turn Off"/>
<ListView
android:id="@+id/deviceList"
android:layout_width="200dp"
android:layout_height="100dp"/>
</LinearLayout>
MainActivity.java
import androidx.appcompat.app.AppCompatActivity;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Set;
public class MainActivity extends AppCompatActivity {
private static final int REQUEST_ENABLE_BT = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView bluetooth = (TextView) findViewById(R.id.bluetooth);
final Button button1 = (Button) findViewById(R.id.b1);
final Button button2 = (Button) findViewById(R.id.b2);
final Button button3 = (Button) findViewById(R.id.b3);
final Button button4 = (Button) findViewById(R.id.b4);
final ListView[] deviceList = {(ListView) findViewById(R.id.deviceList)};
final ArrayAdapter aAdapter;
final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
bluetooth.append("device not supported");
}
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!mBluetoothAdapter.isEnabled()) {
}
Intent enableBtIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
});
button4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mBluetoothAdapter.disable();
//out.append("TURN_OFF BLUETOOTH");
Toast.makeText(getApplicationContext(), "TURNING_OFF BLUETOOTH",
Toast.LENGTH_LONG);
}
});
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(mBluetoothAdapter==null){
Toast.makeText(getApplicationContext(),"Bluetooth Not
Supported",Toast.LENGTH_SHORT).show();
}
else{
Set<BluetoothDevice> pairedDevices =
mBluetoothAdapter.getBondedDevices();
ArrayList list = new ArrayList();
if(pairedDevices.size()>0){
for(BluetoothDevice device: pairedDevices){
String devicename = device.getName();
list.add("Name: "+devicename);
}
deviceList[0] = (ListView) findViewById(R.id.deviceList);
ArrayAdapter aAdapter = new ArrayAdapter(getApplicationContext(),
android.R.layout.simple_list_item_1, list);
deviceList[0].setAdapter(aAdapter);
}
}
}
});
}
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplicationsensor">

<uses-sdk android:minSdkVersion="8"
android:targetSdkVersion="16"/>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplicationSensor">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


</intent-filter>
</activity>
</application>

</manifest>
OUTPUT:
Dated signature of
Marks Obtained Teacher

Process Product
Total(50)
Related(35) Related(15)
26.1 Program to insert data in SQLite database using Async Task

Activity_main.xml :-

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


<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"
tools:context=".Exp_26_1">
<EditText
android:layout_marginTop="100dp"
android:textAlignment="center"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/editText"/>
<Button
android:layout_marginLeft="70dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnAdd"
android:text="Add"/>
<Button
android:layout_marginLeft="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnView"
android:text="View Data"
android:layout_toRightOf="@+id/btnAdd"/>
</RelativeLayout>
</RelativeLayout>

MainActivity.java :-

package com.example.mad;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Exp_26_1 extends AppCompatActivity {
private static final String TAG = "MainActivity";
DatabaseHelper mDatabaseHelper;
private Button btnAdd, btnViewData;
private EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_exp_26_1);
editText = (EditText) findViewById(R.id.editText);
btnAdd = (Button) findViewById(R.id.btnAdd);
btnViewData = (Button) findViewById(R.id.btnView);
mDatabaseHelper = new DatabaseHelper(this);
btnAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String newEntry = editText.getText().toString();
if (editText.length() != 0) {
AddData(newEntry);
editText.setText("");
} else {
toastMessage("You must put something in the text field!");
}
}
});
btnViewData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Exp_26_1.this, ListDataActivity.class);
startActivity(intent);
}
});
}
public void AddData(String newEntry) {
boolean insertData = mDatabaseHelper.addData(newEntry);
if (insertData) {
toastMessage("Data Successfully Inserted!");
} else {
toastMessage("Something went wrong");
}
}
private void toastMessage(String message){
Toast.makeText(this,message, Toast.LENGTH_SHORT).show();
}
}
OUTPUT:-

Dated signature of
Marks Obtained Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical No.27:
1. Write a program to create the login form and display login successful/ Unsuccessful
toastmessage.
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout 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="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="LOGIN"
android:layout_x="300px"
android:layout_y="350px"
android:textSize="40dp"
android:textAlignment="center"
android:gravity="center_horizontal" />
<EditText
android:id="@+id/editemail"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_x="75dp"
android:layout_y="204dp"
android:drawableLeft="@drawable/ic_email_24"
android:drawablePadding="10dp"
android:hint="User Email"
android:textSize="25dp" />
<EditText
android:id="@+id/editpass"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_x="75dp"
android:layout_y="271dp"
android:drawableLeft="@drawable/ic_baseline_security_24"
android:drawablePadding="10dp"
android:hint="Password"
android:inputType="textPassword"
android:textSize="25dp" />
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_x="112dp"
android:layout_y="354dp"
android:text="Submit"
android:textSize="20dp" />
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_x="105dp"
android:layout_y="439dp"
android:text=""
android:textSize="25dp" />
</AbsoluteLayout>

MainActivity.java :
package com.example.loginform;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText useremail = (EditText) findViewById(R.id.editemail);
final EditText password = (EditText) findViewById(R.id.editpass);
final TextView text = (TextView) findViewById(R.id.text1);
Button btn = (Button) findViewById(R.id.btn1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

if(useremail.getText().toString().equals("[email protected]")&&password.getText().toString().equ
als("abc123")){
Toast.makeText(MainActivity.this, "LOGIN SUCCESSFULL",
Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(MainActivity.this, "LOGIN UNSUCCESSFULL",
Toast.LENGTH_LONG).show();

}
}
});
}
}
Output:
Dated signature of
Marks Obtained Teacher

Process Product
Total(50)
Related(35) Related(15)
28.1 Program to create the login form with necessary validation

Activity_main.xml :-

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


<RelativeLayout 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"
tools:context=".Exp_28_1">
<EditText
android:id="@+id/User_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Password:"
android:inputType="textPassword"
android:layout_below="@+id/User_email"
android:layout_marginTop="50dp"
android:padding="10dp"/>
<TextView
android:id="@+id/User_Text"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:textSize="40dp"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Login"/>
<Button
android:id="@+id/User_login"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/User_password"
android:layout_marginTop="50dp"
android:text="Login"/>
<EditText
android:id="@+id/User_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/User_Text"
android:layout_marginTop="50dp"
android:hint="Email:"
android:padding="10dp"
android:inputType="textEmailAddress"/>
</RelativeLayout>
MainActivity.java:-
package com.example.mad;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.icu.text.UnicodeSetSpanner;
import android.os.Bundle;
import android.util.Patterns;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Exp_28_1 extends AppCompatActivity {
Button login;
EditText Uemail,Upass;
public String Uuseremail,Upassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_exp_28_1);
login = findViewById(R.id.User_login);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
check();
}
});
Uemail = findViewById(R.id.User_email);
Upass = findViewById(R.id.User_password);
}
public void check(){
Uuseremail = Uemail.getText().toString().trim();
Upassword = Upass.getText().toString().trim();
if(Uuseremail.isEmpty()) {
Uemail.setError("Enter an e-mail");
Uemail.requestFocus();
return;
}
if(!Patterns.EMAIL_ADDRESS.matcher(Uuseremail).matches()){
Uemail.setError("Enter an e-mail");
Uemail.requestFocus();
return;
}
if(Upassword.isEmpty()) {
Upass.setError("Enter a password");
Upass.requestFocus();
return;
}
if(Upassword.length()<6){
Upass.setError("Minimum length is 6 characters");
Upass.requestFocus();
return;
}
if(Uuseremail.equals("[email protected]") && Upassword.equals("abcd1234")){
Toast.makeText(Exp_28_1.this,"Welcome User",Toast.LENGTH_LONG).show();
Intent intent = new Intent(Exp_28_1.this,Empty_Activity.class);
startActivity(intent);
}
else{
Toast.makeText(this,"Wrong email or password",Toast.LENGTH_LONG).show();
}
}
}

OUTPUT:-
Dated signature of
Marks Obtained Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical No. 29:
Develop a program to: a) Send SMS b) Receive SMS
INPUT:
activity_main.xml
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:id = "@+id/asyncTask"
android:text = "Download"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content" />
<ImageView
android:id = "@+id/image"
android:layout_width = "300dp"
android:layout_height = "300dp" />
</LinearLayout>

MainActivity.java
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class MainActivity extends AppCompatActivity {
URL ImageUrl = null;
InputStream is = null;
Bitmap bmImg = null;
ImageView imageView= null;
ProgressDialog p;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button=findViewById(R.id.asyncTask);
imageView=findViewById(R.id.image);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AsyncTaskExample asyncTask=new AsyncTaskExample();
asyncTask.execute("https://www.google.com/images/tp-logo-diamond.png");
} }); }
private class AsyncTaskExample extends AsyncTask<String, String, Bitmap> {
@Override
protected void onPreExecute() {
super.onPreExecute();
p = new ProgressDialog(MainActivity.this);
p.setMessage("Please wait...It is downloading");
p.setIndeterminate(false);
p.setCancelable(false);
p.show();
}
@Override
protected Bitmap doInBackground(String... strings) {
try {
ImageUrl = new URL(strings[0]);
HttpURLConnection conn = (HttpURLConnection) ImageUrl.openConnection();
conn.setDoInput(true);
conn.connect();
is = conn.getInputStream();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.RGB_565;
bmImg = BitmapFactory.decodeStream(is, null, options);
} catch (IOException e) {
e.printStackTrace();
}
return bmImg }
@Override
protected void onPostExecute(Bitmap bitmap) {
super.onPostExecute(bitmap);
if(imageView!=null) {
p.hide();
imageView.setImageBitmap(bitmap);
}else {
p.show();
}
}}}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplicationsensor">
<uses-permission android:name = "android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplicationSensor">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
OUTPUT:
Dated signature of
Marks Obtained Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical No. 30
1) Develop a program to send and receive e-mail.
INPUT:
activity_main.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sending Mail Example"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="40dp" />

<Button
android:id="@+id/sendEmail"
android:layout_marginTop="80dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="25dp"
android:text="@string/compose_email"/>

</LinearLayout>
MainActivity.java
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {


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

Button startBtn = (Button) findViewById(R.id.sendEmail);


startBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
sendEmail();
}
});
}
@SuppressLint("LongLogTag")
protected void sendEmail() {
Log.i("Send email", "");
String[] TO = {""};
String[] CC = {""};
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
emailIntent.putExtra(Intent.EXTRA_CC, CC);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here");
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
Log.i("Finished sending email...", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this, "There is no email client installed.",
Toast.LENGTH_SHORT).show();
}
}
}
strings.xml
<resources>
<string name="app_name">My ApplicationEmail</string>
<string name="compose_email">Compose Email</string>
</resources>
OUTPUT:
Dated signature of
Marks Obtained Teacher

Process Product
Total(50)
Related(35) Related(15)
Practical No: 31
INPUT:
activity_maps.xml
<RelativeLayout 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"
tools:context=".MapsActivity">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/google_map"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>

MapsActivity.java
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.FragmentActivity;
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
Location currentLocation;
FusedLocationProviderClient fusedLocationProviderClient;
private static final int REQUEST_CODE = 101;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
fetchLastLocation();
}
private void fetchLastLocation() {
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
Task<Location> task = fusedLocationProviderClient.getLastLocation();
task.addOnSuccessListener(new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if(location != null){
currentLocation = location;
Toast.makeText(getApplicationContext(),currentLocation.getLatitude() + ""+
currentLocation.getLongitude()
,Toast.LENGTH_LONG).show();
SupportMapFragment supportMapFragment = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.google_map);
supportMapFragment.getMapAsync(MapsActivity.this);
}
}
});
}
@Override
public void onMapReady(GoogleMap googleMap) {
LatLng latLng = new
LatLng(currentLocation.getLatitude(),currentLocation.getLongitude());
MarkerOptions markerOptions = new MarkerOptions().position(latLng).title("I am here");
googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng,5));
googleMap.addMarker(markerOptions);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull
int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case REQUEST_CODE:
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
fetchLastLocation();
}
return;
}
}
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplicationmap">

<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the "MyLocation" functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplicationMap">
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is
used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
OUTPUT:
Dated signature of
Marks Obtained Teacher

Process Product
Total(50)
Related(35) Related(15)
32.1 Program to draw a route between two locations.

Activity_main.xml:-

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


<LinearLayout 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"
tools:context=".Exp_32_1"
android:orientation="vertical">
<fragment
android:id="@+id/mapFrag"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button android:id="@+id/btnGetDirection"
android:text="Get Direction"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

MainActivity.java:-

package com.example.mad;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions;
public class Exp_32_1 extends AppCompatActivity implements OnMapReadyCallback,
TaskLoadedCallback{
private GoogleMap mMap;
private MarkerOptions place1, place2;
Button getDirection;
private Polyline currentPolyline;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_exp_32_1);
getDirection = findViewById(R.id.btnGetDirection);
getDirection.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new FetchURL(Exp_32_1.this).execute(getUrl(place1.getPosition(), place2.getPosition(),
"driving"), "driving");
}});
place1 = new MarkerOptions().position(new LatLng(27.658143, 85.3199503)).title("Location
1");
place2 = new MarkerOptions().position(new LatLng(27.667491, 85.3208583)).title("Location
2");
MapFragment mapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.mapFrag);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
Log.d("mylog", "Added Markers");
mMap.addMarker(place1);
mMap.addMarker(place2);
}
private String getUrl(LatLng origin, LatLng dest, String directionMode) {
String str_origin = "origin=" + origin.latitude + "," + origin.longitude;
String str_dest = "destination=" + dest.latitude + "," + dest.longitude;
String mode = "mode=" + directionMode;
String parameters = str_origin + "&" + str_dest + "&" + mode;
String output = "json";
String url = "https://maps.googleapis.com/maps/api/directions/" + output + "?" + parameters +
"&key=" + getString(R.string.google_maps_key);
return url;
}
@Override
public void onTaskDone(Object... values) {
if (currentPolyline != null)
currentPolyline.remove();
currentPolyline = mMap.addPolyline((PolylineOptions) values[0]);
}
}
OUTPUT:-

Dated signature of
Marks Obtained Teacher

Process Product
Total(50)
Related(35) Related(15)

You might also like