6.MAD Lab
6.MAD Lab
Aim:
To develop an Android Application that uses GUI components, Font and Colors.
Procedure:
Step 2: Click on File -> New -> New project -> enter the Application name as “[Link].1″
andclick Next and then select the Minimum SDK and click Next -> then select the
Empty Activity and click Next and Finish.
Step 3: Go to package explorer in the left hand side. Double click on the project name.
Step 4: Go to res folder and select layout. Double click the activity_main.xml file.
i. Design tab
a. One TextView with text.
b. Three Buttons with labeled as Change Font Size, Change Font Color and
Change Font Style.(or)
ii. Type the XML commands in the text tab to include the required layout
components.
Step 7: Go to package explorer in the left hand side. Select the project name.
Step 9: In java file write the activities done by the application such as, actions of buttons.
Activity_main.xml:
[Link]:
package [Link].exno1;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity
{
int ch=1;
float font=30;
@Override
protected void onCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
setContentView([Link].activity_main);
final TextView t= (TextView) findViewById([Link]);
Button b1= (Button) findViewById([Link].button1);
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link](font);
font = font + 5;
if (font == 50)
font = 30;
}
});
Button b2= (Button) findViewById([Link].button2);
[Link](new [Link]() {
@Override
public void onClick(View v) {
switch (ch) {
case 1:
[Link]([Link]);
break;
case 2:
[Link]([Link]);
break;
case 3:
[Link]([Link]);
break;
case 4:
[Link]([Link]);
break;
case 5:
[Link]([Link]);
break;
case 6:
[Link]([Link]);
break;
}
ch++;
if (ch == 7)
ch = 1;
}
});
}}
Output:
Result:
Thus a Simple Android Application that uses GUI components, Font and Colors
is developed successfully.
Ex. No.:2 Android Application for Layout Managers and Event
Date: Listeners
Aim:
To develop a Simple Android Application that uses Layout Managers and Event
Listeners.
Procedure:
Step 2: Click on File -> New -> New project -> enter the Application name as “[Link].2″
and click Next and then select the Minimum SDK and click Next -> then select the
Empty Activity and click Next and Finish.
Step 3: Go to package explorer in the left hand side. Double click on the project name.
Step 4: Go to res folder and select layout. Double click the activity_main.xml file.
Step 7: Go to package explorer in the left hand side. Select the project name.
Step 9: In java file write the activities done by the application such as, actions of buttons.
Activity_main.xml:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:text="Details Form"
android:textSize="25sp"
android:gravity="center"/>
</LinearLayout>
<GridLayout
android:id="@+id/gridLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="100dp"
android:layout_marginBottom="200dp"
android:columnCount="2"
android:rowCount="3">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_row="0"
android:layout_column="0"
android:text="Name"
android:textSize="20sp"
android:gravity="center"/>
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_row="0"
android:layout_column="1"
android:ems="10"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_row="1"
android:layout_column="0"
android:text="[Link]"
android:textSize="20sp"
android:gravity="center"/>
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_row="1"
android:layout_column="1"
android:inputType="number"
android:ems="10"/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_row="2"
android:layout_column="0"
android:text="Dept"
android:textSize="20sp"
android:gravity="center"/>
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_row="2"
android:layout_column="1"
android:spinnerMode="dropdown"/>
</GridLayout>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_marginBottom="150dp"
android:text="Submit"/>
</RelativeLayout>
Activity_second.xml:
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="New Text"
android:textSize="30sp"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="New Text"
android:textSize="30sp"/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="New Text"
android:textSize="30sp"/>
</LinearLayout>
[Link]:
package [Link].exno2;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
String [] dept_array={"CSE","ECE","IT","Mech","Civil"};
String name,reg,dept;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
s= (Spinner) findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
name=[Link]().toString();
reg=[Link]().toString();
dept=[Link]().toString();
[Link]("name_key", name);
[Link]("reg_key",reg);
[Link]("dept_key", dept);
startActivity(i);
}
});
}
}
[Link]:
package [Link].exno2;
import [Link];
import [Link];
import [Link];
import [Link];
TextView t1,t2,t3;
String name,reg,dept;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_second);
Intent i = getIntent();
name=[Link]("name_key");
reg=[Link]("reg_key");
dept=[Link]("dept_key");
[Link](name);
[Link](reg);
[Link](dept);
}
}
Output:
Result:
Thus a Simple Android Application that uses Layout Managers and Event
Listeners is developed successfully.
Ex. No.:3 Simple Android Application for Native Calculator
Date:
Aim:
Procedure:
Step 2: Click on File -> New -> New project -> enter the Application name as “[Link].3″
and click Next and then select the Minimum SDK and click Next -> then select the
Empty Activity and click Next and Finish.
Step 3: Go to package explorer in the left hand side. Double click on the project name.
Step 4: Go to res folder and select layout. Double click the activity_main.xml file.
i. Design tab
a. One TextView with to display the result.
b. Place two EditText for getting two numbers.
c. Place four buttons ( +, -, *, / ) to perform calculations. (or)
ii. Type the XML commands in the text tab to include the required layout
components.
Step 7: Go to package explorer in the left hand side. Select the project name.
Step 9: In java file write the activities done by the application such as, actions of buttons.
Activity_main.xml:
<Button
android:id="@+id/btn_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/edText1"
android:layout_marginTop="60dp"
android:onClick="PressOne"
android:text="1"
android:textSize="18sp"
tools:ignore="OnClick" />
<Button
android:id="@+id/btn_0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_8"
android:layout_toEndOf="@+id/btn_7"
android:layout_toRightOf="@+id/btn_7"
android:text="0"
android:textSize="18sp" />
<Button
android:id="@+id/btn_9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_6"
android:layout_toEndOf="@+id/btn_5"
android:layout_toRightOf="@+id/btn_5"
android:text="9"
android:textSize="18sp" />
<Button
android:id="@+id/btn_8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_5"
android:layout_toEndOf="@+id/btn_7"
android:layout_toRightOf="@+id/btn_7"
android:text="8"
android:textSize="18sp" />
<Button
android:id="@+id/btn_7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btn_4"
android:layout_alignStart="@+id/btn_4"
android:layout_below="@+id/btn_4"
android:text="7"
android:textSize="18sp" />
<Button
android:id="@+id/btn_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btn_5"
android:layout_alignBottom="@+id/btn_5"
android:layout_toEndOf="@+id/btn_5"
android:layout_toRightOf="@+id/btn_5"
android:text="6"
android:textSize="18sp" />
<Button
android:id="@+id/btn_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_2"
android:layout_toEndOf="@+id/btn_4"
android:layout_toRightOf="@+id/btn_4"
android:text="5"
android:textSize="18sp" />
<Button
android:id="@+id/btn_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btn_1"
android:layout_alignStart="@+id/btn_1"
android:layout_below="@+id/btn_1"
android:text="4"
android:textSize="18sp" />
<Button
android:id="@+id/btn_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btn_2"
android:layout_alignBottom="@+id/btn_2"
android:layout_toEndOf="@+id/btn_2"
android:layout_toRightOf="@+id/btn_2"
android:text="3"
android:textSize="18sp" />
<Button
android:id="@+id/btn_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btn_1"
android:layout_alignBottom="@+id/btn_1"
android:layout_toEndOf="@+id/btn_1"
android:layout_toRightOf="@+id/btn_1"
android:text="2"
android:textSize="18sp" />
<Button
android:id="@+id/btn_Add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/btn_6"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:backgroundTint="@android:color/darker_gray"
android:text="+"
android:textColor="@android:color/background_light"
android:textSize="18sp" />
<Button
android:id="@+id/btn_Sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btn_Add"
android:layout_alignStart="@+id/btn_Add"
android:layout_below="@+id/btn_Add"
android:backgroundTint="@android:color/darker_gray"
android:text="-"
android:textColor="@android:color/background_light"
android:textSize="18sp" />
<Button
android:id="@+id/btn_Mul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btn_Sub"
android:layout_alignStart="@+id/btn_Sub"
android:layout_below="@+id/btn_6"
android:backgroundTint="@android:color/darker_gray"
android:text="*"
android:textColor="@android:color/background_light"
android:textSize="18sp" />
<Button
android:id="@+id/btn_Div"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btn_Mul"
android:layout_alignStart="@+id/btn_Mul"
android:layout_below="@+id/btn_9"
android:backgroundTint="@android:color/darker_gray"
android:text="/"
android:textColor="@android:color/background_light"
android:textSize="18sp" />
<EditText
android:id="@+id/edText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="22dp"
android:ems="10"
android:inputType="textPersonName"
android:textAlignment="textEnd"
android:textSize="24sp"
android:layout_gravity="end"
tools:ignore="RtlCompat" />
<Button
android:id="@+id/btn_calc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/btn_0"
android:layout_toEndOf="@+id/btn_0"
android:backgroundTint="@android:color/holo_green_light"
android:text="="
android:textColor="@android:color/background_light"
android:textSize="18sp"
android:layout_toRightOf="@+id/btn_0"
tools:ignore="RtlCompat" />
<Button
android:id="@+id/btn_dec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_7"
android:layout_toLeftOf="@+id/btn_8"
android:layout_toStartOf="@+id/btn_8"
android:text="."
android:textSize="18sp" />
<Button
android:id="@+id/btn_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/btn_Div"
android:backgroundTint="@android:color/holo_blue_dark"
android:text="clear"
android:textColor="@android:color/background_light"
android:textSize="18sp" />
</RelativeLayout>
</[Link]>
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].R;
public class MainActivity extends AppCompatActivity {
Button btn_1, btn_2, btn_3, btn_4, btn_5, btn_6, btn_7, btn_8, btn_9, btn_0, btn_Add,
btn_Sub,
btn_Mul, btn_Div, btn_calc, btn_dec, btn_clear;
EditText ed1;
float Value1, Value2;
boolean mAddition, mSubtract, mMultiplication, mDivision ;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
btn_0 = (Button) findViewById([Link].btn_0);
btn_1 = (Button) findViewById([Link].btn_1);
btn_2 = (Button) findViewById([Link].btn_2);
btn_3 = (Button) findViewById([Link].btn_3);
btn_4 = (Button) findViewById([Link].btn_4);
btn_5 = (Button) findViewById([Link].btn_5);
btn_6 = (Button) findViewById([Link].btn_6);
btn_7 = (Button) findViewById([Link].btn_7);
btn_8 = (Button) findViewById([Link].btn_8);
btn_9 = (Button) findViewById([Link].btn_9);
btn_Add = (Button) findViewById([Link].btn_Add);
btn_Div = (Button) findViewById([Link].btn_Div);
btn_Sub = (Button) findViewById([Link].btn_Sub);
btn_Mul = (Button) findViewById([Link].btn_Mul);
btn_calc = (Button) findViewById([Link].btn_calc);
btn_dec = (Button) findViewById([Link].btn_dec);
btn_clear = (Button) findViewById([Link].btn_clear);
ed1 = (EditText) findViewById([Link].edText1);
btn_0.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+"0");}});
btn_1.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+"1");
}
});
btn_2.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+"2");
}
});
btn_3.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+"3");
}
});
btn_4.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+"4");
}
});
btn_5.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+"5");
}
});
btn_6.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+"6");
}
});
btn_7.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+"7");
}
});
btn_8.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+"8");
}
});
btn_9.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+"9");
}
});
btn_dec.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+".");
}
});
btn_Add.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
if (ed1 == null){
[Link]("");
}else {
Value1 = [Link]([Link]() + "");
mAddition = true;
[Link](null);
}
}
});
btn_Sub.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
Value1 = [Link]([Link]() + "");
mSubtract = true ;
[Link](null);
}
});
btn_Mul.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
Value1 = [Link]([Link]() + "");
mMultiplication = true ;
[Link](null);
}
});
btn_Div.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
Value1 = [Link]([Link]()+"");
mDivision = true ;
[Link](null);
}
});
btn_calc.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
Value2 = [Link]([Link]() + "");
if (mAddition == true){
[Link](Value1 + Value2 +"");
mAddition=false;
}
if (mSubtract == true){
[Link](Value1 - Value2 +"");
mSubtract=false;
}
if (mMultiplication == true){
[Link](Value1 * Value2 + "");
mMultiplication=false;
}
if (mDivision == true){
[Link](Value1 / Value2+"");
mDivision=false;
}
}
});
btn_clear.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]("");
}
});
}
}
Output:
Result:
Date:
Aim:
Procedure:
Step 2: Click on File -> New -> New project -> enter the Application name as “[Link].4″
and click Next and then select the Minimum SDK and click Next -> then select the
Empty Activity and click Next and Finish.
Step 3: Go to package explorer in the left hand side. Double click on the project name.
Step 4: Go to res folder and select layout. Double click the activity_main.xml file.
Step 7: Go to package explorer in the left hand side. Select the project name.
Step 9: In java file write the activities done by the application such as drawing the
graphical primitives.
Step 10: Run the android application.
Program:
Activity_main.xml:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView" />
</RelativeLayout>
[Link]:
package [Link].exno4;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
Thus a Simple Android Application that draws basic Graphical Primitives on the
screen is developed successfully.
Ex. No.: 5 Simple Android Application that makes use of Database
Date:
Aim:
Procedure:
Step 2: Click on File -> New -> New project -> enter the Application name as “[Link].5″
and click Next and then select the Minimum SDK and click Next -> then select the
Empty Activity and click Next and Finish.
Step 3: Go to package explorer in the left hand side. Double click on the project name.
Step 4: Go to res folder and select layout. Double click the activity_main.xml file.
Step 7: Go to package explorer in the left hand side. Select the project name.
Step 9: In java file write the activities done by the application such as actions of buttons.
Activity_main.xml:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"
android:layout_y="110dp"
android:text="Enter Rollno:"
android:textSize="20sp" />
<EditText
android:id="@+id/Rollno"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="175dp"
android:layout_y="100dp"
android:inputType="number"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"
android:layout_y="160dp"
android:text="Enter Name:"
android:textSize="20sp" />
<EditText
android:id="@+id/Name"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="175dp"
android:layout_y="150dp"
android:inputType="text"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"
android:layout_y="210dp"
android:text="Enter Marks:"
android:textSize="20sp" />
<EditText
android:id="@+id/Marks"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="175dp"
android:layout_y="200dp"
android:inputType="number"
android:textSize="20sp" />
<Button
android:id="@+id/Insert"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="25dp"
android:layout_y="300dp"
android:text="Insert"
android:textSize="30dp" />
<Button
android:id="@+id/Delete"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="200dp"
android:layout_y="300dp"
android:text="Delete"
android:textSize="30dp" />
<Button
android:id="@+id/Update"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="25dp"
android:layout_y="400dp"
android:text="Update"
android:textSize="30dp" />
<Button
android:id="@+id/View"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="200dp"
android:layout_y="400dp"
android:text="View"
android:textSize="30dp" />
<Button
android:id="@+id/ViewAll"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_x="100dp"
android:layout_y="500dp"
android:text="View All"
android:textSize="30dp" />
</AbsoluteLayout>
[Link]:
package [Link].exno5;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
Rollno=(EditText)findViewById([Link]);
Name=(EditText)findViewById([Link]);
Marks=(EditText)findViewById([Link]);
Insert=(Button)findViewById([Link]);
Delete=(Button)findViewById([Link]);
Update=(Button)findViewById([Link]);
View=(Button)findViewById([Link]);
ViewAll=(Button)findViewById([Link]);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
v
Result:
Date:
Aim:
Procedure:
Step 2: Click on File -> New -> New project -> enter the Application name as “[Link].6″
and click Next and then select the Minimum SDK and click Next -> then select the
Empty Activity and click Next and Finish.
Step 3: Go to package explorer in the left hand side. Double click on the project name.
Step 4: Go to res folder and select layout. Double click the activity_main.xml file.
Step 7: Go to package explorer in the left hand side. Select the project name.
Step 9: In java file write the activities done by the application such as different links.
[Link]:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="[Link]
package="[Link].exno6" >
<uses-permission android:name="[Link]"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="[Link]" />
</manifest>
[Link]:
package [Link].exno6;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
Date:
Aim:
Procedure:
Step 2: Click on File -> New -> New project -> enter the Application name as “[Link].7″
and click Next and then select the Minimum SDK and click Next -> then select the
EmptyActivity and click Next and Finish.
Step 3: Go to package explorer in the left hand side. Double click on the project name.
Step 4: Go to res folder and select layout. Double click the activity_main.xml file.
Step 7: Go to package explorer in the left hand side. Select the project name.
Step 9: In java file write the activities done by the application such as actions of button.
Activity_main.xml:
package [Link].exno7;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity
{
ImageView img;
Button bt1,bt2;
@Override
protected void onCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
setContentView([Link].activity_main);
bt1 = (Button)findViewById([Link]);
bt2= (Button) findViewById([Link].button2);
img = (ImageView)findViewById([Link]);
[Link](new [Link]()
{
@Override
public void onClick(View v)
{
new Thread(new Runnable()
{
@Override
public void run()
{
[Link](new Runnable()
{
@Override
public void run()
{
[Link]([Link].india1);
}
});
}
}).start();
}
});
[Link](new [Link]()
{
@Override
public void onClick(View v)
{
new Thread(new Runnable()
{
@Override
public void run()
{
[Link](new Runnable()
{
@Override
public void run()
{
[Link]([Link].india2);
}
});
}
}).start();
}
});
}}
Output:
Result:
Date:
Aim:
Procedure:
Step 2: Click on File -> New -> New project -> enter the Application name as “[Link].8″
and click Next and then select the Minimum SDK and click Next -> then select the
Empty Activity and click Next and Finish.
Step 3: Go to package explorer in the left hand side. Double click on the project name.
Step 4: Go to res folder and select layout. Double click the activity_main.xml file.
Step 7: Go to package explorer in the left hand side. Select the project name.
Step 9: In java file write the activities done by the application such as finding current
location and show them to user using Toast attribute.
Step 10: Get the following permission in [Link] file:
<uses-permission android:name="[Link].ACCESS_FINE_LOCATION"/>,
<uses-permission android:name="[Link].ACCESS_COARSE_LOCATION" />
Activity_main.xml:
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="[Link]">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn"
android:layout_centerInParent="true"
android:text="GET LOCATION" />
</RelativeLayout>
[Link]:
<uses-permission android:name="[Link].ACCESS_COARSE_LOCATION"
/>
<uses-permission android:name="[Link].ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="[Link]" />
[Link]
package [Link].exno8;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
LocationTrack locationTrack;
@Override
[Link](savedInstanceState);
setContentView([Link].activity_main);
[Link](ACCESS_FINE_LOCATION);
[Link](ACCESS_COARSE_LOCATION);
permissionsToRequest = findUnAskedPermissions(permissions);
//get the permissions we have asked for before but are not granted..
if ([Link]() > 0)
requestPermissions([Link](new
String[[Link]()]), ALL_PERMISSIONS_RESULT);
[Link](new [Link]() {
@Override
if ([Link]()) {
[Link](getApplicationContext(), "Longitude:" +
[Link](longitude) + "\nLatitude:" + [Link](latitude),
Toast.LENGTH_SHORT).show();
} else {
[Link]();
});
if (!hasPermission(perm)) {
[Link](perm);
return result;
if (canMakeSmores()) {
return (checkSelfPermission(permission) ==
PackageManager.PERMISSION_GRANTED);
return true;
@TargetApi(Build.VERSION_CODES.M)
@Override
grantResults) {
switch (requestCode) {
case ALL_PERMISSIONS_RESULT:
for (String perms : permissionsToRequest) {
if (!hasPermission(perms)) {
[Link](perms);
if ([Link]() > 0) {
if (shouldShowRequestPermissionRationale([Link](0)))
{
@Override
});
return;
}
}
break;
new [Link]([Link])
.setMessage(message)
.setPositiveButton("OK", okListener)
.setNegativeButton("Cancel", null)
.create()
.show();
@Override
[Link]();
[Link]();
[Link]
package [Link].exno8;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
Location loc;
double latitude;
double longitude;
[Link] = mContext;
getLocation();
try {
checkGPS = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
checkNetwork = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
} else {
[Link] = true;
if (checkGPS) {
if ([Link](mContext,
[Link].ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
[Link](mContext,
[Link].ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
// ActivityCompat#requestPermissions
// to handle the case where the user grants the permission. See the
documentation
[Link](
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (locationManager != null) {
loc = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (loc != null) {
latitude = [Link]();
longitude = [Link]();
/*if (checkNetwork) {
if ([Link](mContext,
[Link].ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
[Link](mContext,
[Link].ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
// ActivityCompat#requestPermissions
// to handle the case where the user grants the permission. See the
documentation
[Link](
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (locationManager != null) {
loc = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (loc != null) {
latitude = [Link]();
longitude = [Link]();
}*/
} catch (Exception e) {
[Link]();
return loc;
if (loc != null) {
longitude = [Link]();
return longitude;
}
public double getLatitude() {
if (loc != null) {
latitude = [Link]();
return latitude;
return [Link];
[Link](intent);
});
});
[Link]();
if (locationManager != null) {
if ([Link](mContext,
[Link].ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
[Link](mContext,
[Link].ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
// ActivityCompat#requestPermissions
// int[] grantResults)
// to handle the case where the user grants the permission. See the
documentation
return;
[Link]([Link]);
}
@Override
return null;
@Override
@Override
@Override
@Override
}
Output:
Result:
Aim:
Procedure:
Step 2: Click on File -> New -> New project -> enter the Application name as “[Link].9″
and click Next and then select the Minimum SDK and click Next -> then select the
Empty Activity and click Next and Finish.
Step 3: Go to package explorer in the left hand side. Double click on the project name.
Step 4: Go to res folder and select layout. Double click the activity_main.xml file.
Step 6: This application has no components, because this just generates a notification
alone.
Step 7: Go to package explorer in the left hand side. Select the project name.
Step 9: In java file write the activities done by the application such as receiving a
message and notifying it.
Step 10: Get the following permission in [Link] file:
<uses-permission android:name=”[Link].RECEIVE_SMS”/>
<uses-permission android:name=”[Link].READ_SMS”/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message"
android:textSize="30sp" />
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="30sp" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:layout_gravity="center"
android:text="Notify"
android:textSize="30sp"/>
</LinearLayout>
[Link]:
package [Link].exno9;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
[Link](new [Link]()
{
@Override
public void onClick(View v)
{
Intent intent = new Intent([Link], [Link]);
PendingIntent pending = [Link]([Link], 0, intent,
0);
Notification noti = new
[Link]([Link]).setContentTitle("New
Message").setContentText([Link]().toString())
.setSmallIcon([Link].ic_launcher).setContentIntent(pending).build();
NotificationManager manager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
[Link] |= Notification.FLAG_AUTO_CANCEL;
[Link](0, noti);
}
});
}
}
Output:
Result:
Date:
Aim:
Procedure:
Step 2: Click on File -> New -> New project -> enter the Application name as “[Link].10″
and click Next and then select the Minimum SDK and click Next -> then select the
Empty Activity and click Next and Finish.
Step 3: Go to package explorer in the left hand side. Double click on the project name.
Step 4: Go to res folder and select layout. Double click the activity_main.xml file.
Step 7: Go to package explorer in the left hand side. Select the project name.
Step 9: In java file write the activities done by the application such as finding current
location and show them to user using Toast attribute.
Step 10: Get the following permission in [Link] file:
<uses-permission android:name=”[Link].WAKE_LOCK”/>
Step 11: Add Alarm class as a receiver in [Link] file.
Program:
Activity_main.xml:
<TimePicker
android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="20dp"
android:checked="false"
android:onClick="OnToggleClicked" />
</LinearLayout>
[Link]:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="[Link]" />
[Link]:
package [Link].exno10;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
setContentView([Link].activity_main);
alarmTimePicker = (TimePicker) findViewById([Link]);
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
}
public void OnToggleClicked(View view)
{
long time;
if (((ToggleButton) view).isChecked())
{
[Link]([Link], "ALARM ON",
Toast.LENGTH_SHORT).show();
Calendar calendar = [Link]();
[Link](Calendar.HOUR_OF_DAY, [Link]());
[Link]([Link], [Link]());
Intent intent = new Intent(this, [Link]);
pendingIntent = [Link](this, 0, intent, 0);
time=([Link]()-([Link]()%60000));
if([Link]()>time)
{
if (calendar.AM_PM == 0)
time = time + (1000*60*60*12);
else
time = time + (1000*60*60*24);
}
[Link]:
package [Link].exno10;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];