Mad Manual (Solved)
Mad Manual (Solved)
• 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·
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
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
•
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:
V s u a l Studio
5. RAD Studio
ExerciSe
Process Product
Total(50)
Related(35) Related(15)
r - - -~ _J?rrnilicoJ ReletJ-ed .cquasHb-os.
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...
Process Product
Total(50)
Related(35) Related(15)
Practical No:04
INPUT:
<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;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}}
OUTPUT:
Write a program to display student name and marks.
INPUT:
<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;
@Override
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"
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;
@Override
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:
<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"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="250px"
android:layout_y="300px"
<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;
@Override
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:
<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"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="250px"
android:layout_y="300px"
<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;
@Override
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;
}
}
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;
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;
@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;
@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);
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 ";
}
}
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;
@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
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;
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
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;
@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;
@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;
CheckBox c1,c2,c3;
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButtonClick();
}
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;
@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) {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, intdayOfMonth)
{
}
}, mYear, mMonth, mDay);
datePickerDialog.show();
}
if (v == btnTimePicker) {
@Override
public void onTimeSet(TimePicker view, int hourOfDay,
int minute) {
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;
@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;
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;
}
});
}
}
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" >
MainActivity.java :
package com.example.monday3;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
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;
<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;
@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);
Secondactivity.java
package com.demo.prac_18_1;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
OUTPUT:
Dated signature of
Marks Obtained
Teacher
Process Product
Total(50)
Related(35) Related(15)
Practical No:19
Activity_main.xml
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;
/**
* Database specific constant declarations
*/
/**
* Helper class that actually creates and manages
* the provider's underlying data repository.
*/
@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;
}
@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:
}
@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
<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;
@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());
Toast.makeText(getBaseContext(),
uri.toString(), Toast.LENGTH_LONG).show();
}
public void onClickRetrieveStudents(View view) {
// Retrieve student records
String URL = "content://com.example.myapplicationcontent.StudentsProvider";
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
<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;
<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" />
Process Product
Total(50)
Related(35) Related(15)
Practical No:20
<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;
<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" />
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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@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;
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);
<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" />
</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);
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" />
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" />
</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 :-
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;
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 :-
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;
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:-
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)