You are on page 1of 34

CS6611 MOBILE APPLICATION DEVELOPMENT

LABORATORY
INDEX
Ex No Experiment Name
1 Develop an application that uses GUI components, Font 
and Colours.
2 Develop an application that uses Layout Managers and 
event listeners.
3 Develop a native calculator application.

4 Write an application that draws basic graphical 


primitives on the screen.

5 Develop an application that makes use of database.

6 Develop an application that makes use of RSS Feed.

7 Implement an application that implements Multi 


threading.

8 Implement an application that writes data to the SD 


card

9 Implement an application that creates an alert upon 


receiving a message.
10 Develop a native application that uses GPS location 
information. 

11 Write a mobile application that creates alarm clock.


1.Develop an application that uses GUI components, Font and Colours

1.activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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">
<TableLayout
android:layout_width="395dp"
android:layout_height="715dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
tools:layout_editor_absoluteX="157dp"
tools:layout_editor_absoluteY="54dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Font"
tools:layout_editor_absoluteX="108dp"
tools:layout_editor_absoluteY="60dp"
android:onClick="change_font"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Color"
tools:layout_editor_absoluteX="149dp"
tools:layout_editor_absoluteY="112dp"
android:onClick="change_color"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
</TableLayout>
</android.support.constraint.ConstraintLayout>

2.MainActivity.java
package com.example.exno1_cseb_bi;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
int font_size=5;
int color_option=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void change_font(View view)
{
TextView tv=(TextView)findViewById(R.id.name);
tv.setTextSize(font_size);
font_size=font_size+1;
if(font_size==15)
{
font_size=5;
}
}
public void change_color(View view)
{
TextView tv=(TextView)findViewById(R.id.name);
if(color_option==0)
{
tv.setTextColor(Color.BLUE);
}
if(color_option==1)
{
tv.setTextColor(Color.YELLOW);
}
if(color_option==2)
{
tv.setTextColor(Color.GREEN);
}
if(color_option==3)
{
tv.setTextColor(Color.GRAY);
}
if(color_option==4)
{
tv.setTextColor(Color.MAGENTA);
}
color_option=color_option+1;
if(color_option==4)
{
color_option=0;
}
}
}
2.Develop an application that uses Layout Managers and event listeners

1.activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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">
<TableLayout
android:layout_width="395dp"
android:layout_height="715dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter the Name"
tools:layout_editor_absoluteX="176dp"
tools:layout_editor_absoluteY="34dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_editor_absoluteX="78dp"
tools:layout_editor_absoluteY="60dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click"
tools:layout_editor_absoluteX="161dp"
tools:layout_editor_absoluteY="102dp"
android:onClick="display"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
</TableLayout>
</android.support.constraint.ConstraintLayout>

2.activity_display.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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=".Display">
<TableLayout
android:layout_width="395dp"
android:layout_height="715dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
tools:layout_editor_absoluteX="176dp"
tools:layout_editor_absoluteY="30dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
</TableLayout> </android.support.constraint.ConstraintLayout>
3.MainActivity.java
package com.example.cse_b_i_ex_2;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {


public final static String msg=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void display(View view)
{
Intent intent=new Intent(this,Display.class);
EditText text=(EditText)findViewById(R.id.editText);
String msg_1=text.getText().toString();
intent.putExtra(msg,msg_1);
startActivity(intent);
}
}
4.Display.java
package com.example.cse_b_i_ex_2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class display extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display2);
}
}
3.Develop a native calculator application

1.activity_main.xml

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


<android.support.constraint.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">
<TableLayout
android:layout_width="395dp"
android:layout_height="715dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number1"
tools:layout_editor_absoluteX="149dp"
tools:layout_editor_absoluteY="28dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<EditText
android:id="@+id/no1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_editor_absoluteX="86dp"
tools:layout_editor_absoluteY="41dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number2"
tools:layout_editor_absoluteX="134dp"
tools:layout_editor_absoluteY="86dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<EditText
android:id="@+id/no2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_editor_absoluteX="75dp"
tools:layout_editor_absoluteY="119dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Result @android:string/defaultMsisdnAlphaTag"
tools:layout_editor_absoluteX="158dp"
tools:layout_editor_absoluteY="158dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<EditText
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_editor_absoluteX="98dp"
tools:layout_editor_absoluteY="167dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add"
tools:layout_editor_absoluteX="132dp"
tools:layout_editor_absoluteY="230dp"
android:onClick="add"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subtract"
tools:layout_editor_absoluteX="141dp"
tools:layout_editor_absoluteY="259dp"
android:onClick="subtract" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Divide"
tools:layout_editor_absoluteX="277dp"
tools:layout_editor_absoluteY="318dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
</TableLayout>
</android.support.constraint.ConstraintLayout>

2.MainActivity.java

package com.example.exno3_b_ii;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
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);
}
public void add(View view)
{
EditText tv1=(EditText)findViewById(R.id.no1);
EditText tv2=(EditText)findViewById(R.id.no2);
String number1=tv1.getText().toString();
String number2=tv2.getText().toString();
int result=Integer.parseInt(number1)+Integer.parseInt(number2);
TextView txt1=(TextView)findViewById(R.id.result);
txt1.setText(String.valueOf(result));

}
public void subtract(View view)
{
EditText tv1=(EditText)findViewById(R.id.no1);
EditText tv2=(EditText)findViewById(R.id.no2);
String number1=tv1.getText().toString();
String number2=tv2.getText().toString();
int result=Integer.parseInt(number1)-Integer.parseInt(number2);
TextView txt1=(TextView)findViewById(R.id.result);
txt1.setText(String.valueOf(result));
}
public void mul(View view)
{
EditText tv1=(EditText)findViewById(R.id.no1);
EditText tv2=(EditText)findViewById(R.id.no2);
String number1=tv1.getText().toString();
String number2=tv2.getText().toString();
int result=Integer.parseInt(number1)-Integer.parseInt(number2);
TextView txt1=(TextView)findViewById(R.id.result);
txt1.setText(String.valueOf(result));
}
public void div(View view)
{
EditText tv1=(EditText)findViewById(R.id.no1);
EditText tv2=(EditText)findViewById(R.id.no2);
String number1=tv1.getText().toString();
String number2=tv2.getText().toString();
int result=Integer.parseInt(number1)-Integer.parseInt(number2);
TextView txt1=(TextView)findViewById(R.id.result);
txt1.setText(String.valueOf(result));
}
}

4.Write an application that draws basic graphical primitives on the screen

1.activity_main.xml

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


<android.support.constraint.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="245dp"
android:layout_height="27dp"
android:layout_marginRight="104dp"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

2.MainActivity.java

package com.example.exno_4_b_i;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(new tss_view(this));
//setContentView();
}
}

3.tss_view.java

package com.example.exno_4_b_i;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
public class tss_view extends View
{

public tss_view(Context context) {


super(context);
}
public void onDraw(Canvas tss_canvas)
{
super.draw(tss_canvas);
Paint tss_paint=new Paint();
tss_paint.setColor(Color.BLACK);
tss_canvas.drawRect(10,20,30,40,tss_paint);
tss_paint.setColor(Color.YELLOW);
tss_canvas.drawCircle(460,460,80,tss_paint);
tss_paint.setColor(Color.GREEN);
tss_canvas.drawRect(500,600,700,800,tss_paint);
tss_paint.setColor(Color.RED);
tss_paint.setTextSize(40);
tss_canvas.drawText("S.Gavaskar",8,9,tss_paint);
tss_paint.setColor(Color.GREEN);
tss_canvas.drawLine(900,1100,900,900,tss_paint);
}
}
5.Develop an application that makes use of database

1.activity_main.xml

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


<android.support.constraint.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">
<TableLayout
android:layout_width="395dp"
android:layout_height="715dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/textView"
android:layout_width="48dp"
android:layout_height="16dp"
android:text="RollNo"
tools:layout_editor_absoluteX="176dp"
tools:layout_editor_absoluteY="29dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<EditText
android:id="@+id/rollno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_editor_absoluteX="81dp"
tools:layout_editor_absoluteY="42dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="enter your @string/app_name"
tools:layout_editor_absoluteX="159dp"
tools:layout_editor_absoluteY="87dp"
tools:text="enter your @string/app_name" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<EditText
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_editor_absoluteX="108dp"
tools:layout_editor_absoluteY="100dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Insert"
tools:layout_editor_absoluteX="144dp"
tools:layout_editor_absoluteY="164dp"
android:onClick="insert_data"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete"
tools:layout_editor_absoluteX="138dp"
tools:layout_editor_absoluteY="205dp"
android:onClick="delete_data"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="update"
tools:layout_editor_absoluteX="138dp"
tools:layout_editor_absoluteY="205dp"
android:onClick="update_data"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
tools:layout_editor_absoluteX="165dp"
tools:layout_editor_absoluteY="249dp" />
</TableLayout>
</android.support.constraint.ConstraintLayout>

2.MainActivity.java

package com.example.cse_bii_exno5;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
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);
}
public void insert_data(View view)
{
SQLiteDatabase db=this.openOrCreateDatabase("student",MODE_PRIVATE,null);
db.execSQL("CREATE TABLE IF NOT EXISTS biodata(rollno VARCHAR,name
VARCHAR)");
EditText rollno1=(EditText)findViewById(R.id.rollno);
EditText name1=(EditText)findViewById(R.id.name);
TextView tv=(TextView)findViewById(R.id.result);
String txt_rollno;
String txt_name;
txt_rollno=rollno1.getText().toString();
txt_name=name1.getText().toString();
db.execSQL("INSERT INTO biodata(rollno,name) values('"+ txt_rollno +"','"+ txt_name
+"')");
Cursor c=db.rawQuery("select * from biodata",null);
tv.setText("\n DETAILS AFTER INSERTING :\n");
while(c.moveToNext())
{
tv.append("RollNO: "+c.getString(0) + " Name: " + c.getString(1) + "\n");
tv.append("-------------------------\n");
}
}
public void delete_data(View view)
{
SQLiteDatabase db=this.openOrCreateDatabase("student",MODE_PRIVATE,null);
db.execSQL("CREATE TABLE IF NOT EXISTS biodata(rollno VARCHAR,name
VARCHAR)");
EditText rollno1=(EditText)findViewById(R.id.rollno);
EditText name1=(EditText)findViewById(R.id.name);
TextView tv=(TextView)findViewById(R.id.result);
String txt_rollno;
String txt_name;
txt_rollno=rollno1.getText().toString();
txt_name=name1.getText().toString();
db.execSQL("delete from biodata where rollno='"+ txt_rollno +"'");
Cursor c=db.rawQuery("select * from biodata",null);
tv.setText("\n DETAILS AFTER DELETING :\n");
while(c.moveToNext())
{
tv.append("RollNO: "+c.getString(0) + " Name: " + c.getString(1) + "\n");
tv.append("-------------------------\n");
}
}
public void update_data(View view)
{
SQLiteDatabase db=this.openOrCreateDatabase("student",MODE_PRIVATE,null);
db.execSQL("CREATE TABLE IF NOT EXISTS biodata(rollno VARCHAR,name
VARCHAR)");
EditText rollno1=(EditText)findViewById(R.id.rollno);
EditText name1=(EditText)findViewById(R.id.name);
TextView tv=(TextView)findViewById(R.id.result);
String txt_rollno;
String txt_name;
txt_rollno=rollno1.getText().toString();
txt_name=name1.getText().toString();
db.execSQL("update biodata set name='"+ txt_name + "' where rollno='"+ txt_rollno +"'");
Cursor c=db.rawQuery("select * from biodata",null);
tv.setText("\n DETAILS AFTER DELETING :\n");
while(c.moveToNext())
{
tv.append("RollNO: "+c.getString(0) + " Name: " + c.getString(1) + "\n");
tv.append("-------------------------\n");
}
}
}
6.Develop an application that makes use of RSS Feed

1.activity_main.xml

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


<android.support.constraint.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">
<ListView
android:id="@+id/listview"
android:layout_width="395dp"
android:layout_height="715dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp" />
</android.support.constraint.ConstraintLayout>

2.arrays.xml

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


<resources>
<string-array name="rssfeed">
<item>No of comments:100</item>
<item>No of Views:150</item>
<item>No of Pages:150</item>
</string-array>
</resources>

3.MainActivity.java

package com.example.cse_bii_exno_6;
import android.content.res.Resources;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources res=getResources();
String[] rssfeed=res.getStringArray(R.array.rssfeed);
ListView list=(ListView)findViewById(R.id.listview);
list.setAdapter(new
ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,rssfeed));
}
}
7.Implement an application that implements Multi threading

1.activity_main.xml

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


<android.support.constraint.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">
<TableLayout
android:layout_width="395dp"
android:layout_height="715dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Multithreading Application"
tools:layout_editor_absoluteX="176dp"
tools:layout_editor_absoluteY="16dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="value from thread1:"
tools:layout_editor_absoluteX="158dp"
tools:layout_editor_absoluteY="41dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<EditText
android:id="@+id/no1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="0"
tools:layout_editor_absoluteX="98dp"
tools:layout_editor_absoluteY="49dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Value from thread2"
tools:layout_editor_absoluteX="156dp"
tools:layout_editor_absoluteY="108dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<EditText
android:id="@+id/no2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="0"
tools:layout_editor_absoluteX="78dp"
tools:layout_editor_absoluteY="124dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start"
tools:layout_editor_absoluteX="161dp"
tools:layout_editor_absoluteY="182dp"
android:onClick="start"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
</TableLayout>
</android.support.constraint.ConstraintLayout>

2.MainActivity.java

package com.example.bii_exno_7;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
Handler tss_handler=new Handler();
EditText tss_tv1,tss_tv2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tss_tv1=(EditText)findViewById(R.id.no1);
tss_tv2=(EditText)findViewById(R.id.no2);
}
public void thread1()
{
tss_tv1.setText(String.valueOf(Integer.parseInt(tss_tv1.getText().toString())+1));
tss_handler.postDelayed(run,500);
}
public void thread2()
{
tss_tv2.setText(String.valueOf(Integer.parseInt(tss_tv2.getText().toString())+1));
tss_handler.postDelayed(run,500);
}
public void start(View view)
{
tss_handler.postDelayed(run,500);
}
Runnable run=new Runnable() {
@Override
public void run() {
thread1();
thread2();
}
};
}
8.Implement an application that writes data to the SD card

1.activity_main.xml

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


<android.support.constraint.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">
<TableLayout
android:layout_width="395dp"
android:layout_height="715dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
tools:layout_editor_absoluteX="162dp"
tools:layout_editor_absoluteY="32dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<EditText
android:id="@+id/write"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_editor_absoluteX="98dp"
tools:layout_editor_absoluteY="49dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Write"
tools:layout_editor_absoluteX="130dp"
tools:layout_editor_absoluteY="99dp"
android:onClick="write"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:layout_editor_absoluteX="146dp"
tools:layout_editor_absoluteY="147dp"
android:onClick="read"/>
</TableLayout>
</android.support.constraint.ConstraintLayout>

2.MainActivity.java

package com.example.bii_exno_8;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText text=(EditText) findViewById(R.id.write);
}
public void write(View view)
{
try
{
FileOutputStream fout=openFileOutput("CSE-B.txt",MODE_PRIVATE);
OutputStreamWriter writer1=new OutputStreamWriter(fout);
EditText text=(EditText) findViewById(R.id.write);
writer1.write(text.getText().toString());
writer1.close();
Toast.makeText(getBaseContext(),"File saved
sucessfully",Toast.LENGTH_LONG).show();
}
catch (Exception e)
{

}
}
public void read(View view)
{
try {
FileInputStream filein = openFileInput("CSE-B.txt");
InputStreamReader reader=new InputStreamReader(filein);
char[] inputbuffer=new char[1000];
String txt="";
int charread;
while((charread=reader.read(inputbuffer))>0)
{
String read=String.copyValueOf(inputbuffer,0,charread);
txt+=read;
}
reader.close();
Toast.makeText(getBaseContext(),txt,Toast.LENGTH_LONG).show();
}
catch (Exception e)
{

}
}
}
9.Implement an application that creates an alert upon receiving a message

1.activity_main.xml

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


<android.support.constraint.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">
<TableLayout
android:layout_width="395dp"
android:layout_height="715dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="show mesage"
tools:layout_editor_absoluteX="177dp"
tools:layout_editor_absoluteY="120dp"
android:onClick="addNotification"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
</TableLayout>
</android.support.constraint.ConstraintLayout>
2.MainActivity.java

package com.example.bii_exno_9;

import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.app.Notification;
import android.app.NotificationManager;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {


Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button)findViewById(R.id.button);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addNotification();
}
});
}
private void addNotification() {
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.header) //set icon for notification
.setContentTitle("Messsage") //set title of notification
.setContentText("This is a notification message");//this is notification message
// Add as notification
NotificationManager manager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, builder.build());
}
}

10.Develop a native application that uses GPS location information

1.activity_main.xml

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


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical">
<TextView
android:id="@+id/lat"
android:textSize="20sp"
android:text="Latitude :"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/lon"
android:textSize="20sp"
android:text="Longitude :"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

2.MainActivity.java

package com.example.student.maps;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
LocationManager locationManager;
LocationListener locationListener;
TextView latitude;
TextView longitude;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
latitude = (TextView) findViewById(R.id.lat);
longitude = (TextView) findViewById(R.id.lon);
locationManager = (LocationManager)
this.getSystemService(Context.LOCATION_SERVICE);
locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
latitude.setText("Latitude :"+location.getLatitude());
longitude.setText("Longitude :"+location.getLongitude());
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
};

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {


if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
return;
}
}
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
locationListener);
}
}
11.Write a mobile application that creates alarm clock

1.activity_main.xml

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


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main" tools:context=".MainActivity">

<TextView android:text="Creating Alarm Clock" android:layout_width="wrap_content"


android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:id="@+id/textView2" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set the time"
android:id="@+id/textView"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/alarm_time"
android:layout_below="@+id/textView"
android:layout_marginTop="33dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:id="@+id/button"
android:layout_marginTop="38dp"
android:layout_below="@+id/alarm_time"
android:layout_alignStart="@+id/textView"
android:onClick="start_alarm"/>
</RelativeLayout>

2.Broadcast_receiver.java

package com.example.student.alarm_iiicse_b_ii;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class Broadcast_receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context,"alarm is on",Toast.LENGTH_LONG).show();
}
}

3.MainActivity.java

package com.example.student.alarm_iiicse_b_ii;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);


fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
public void start_alarm(View v)
{
EditText text = (EditText) findViewById(R.id.alarm_time);
int i = Integer.parseInt(text.getText().toString());
Intent intent = new Intent(this, Broadcast_receiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(),
234324243, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (i * 1000),
pendingIntent);
Toast.makeText(this, "Alarm after " + i + " seconds", Toast.LENGTH_LONG).show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

You might also like