MSE Lab Manual

Download as pdf or txt
Download as pdf or txt
You are on page 1of 79

MOBILE SYSTEM ENGINEERING

COMPONENT LAB
15Z703

LABORATORY MANUAL

Prepared by

Ms.Swetha.N.G.

Assistant Professor

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

PSG COLLEGE OF TECHNOLOGY


(Autonomous Institution)

COIMBATORE – 641 004

1 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


List of Lab Exercises:

1. Installation of Android Studio


2. Using Android Studio – Simple App design
3. Activity Life Cycle
4. Services
5. Broadcast Receiver
a. Custom Broadcast Receiver
b. System Generated Broadcast Receiver
6. Intent
a. Implicit Intent
b. Explicit Intent
7. Simple Calculator
8. Android input controls
9. Threads in Android
10. Alarm Manager
11. Persistent Storage - SQLite
12. Multimedia in Android
a. Media Player
b. Video Player
13. Location based services
14. Google Maps

Tutorial exercise for Wireless Communication (3G/4G) :

1. Worksheet 1 – Wireless communications


2. Worksheet 2 – 3G Technologies
3. Worksheet 3 – 4G Technologies
4. Worksheet 4 – IMS Architecture
5. Worksheet 5 – Software Define Radio, MVNO

2 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Ex:1 Installation of Android Studio

Aim:

To install the Android Studio.

Procedure:

1. Download Android Studio and unzip it.


2. Open the setup file (studio/studio64).
3. The following wizard appears,

3 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


4. Choose the installation type as Standard.

5. Choose the required UI theme.

4 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


6. In the SDK Component setup window choose HAMX and AVD for installation.

7. Once the installation is completed click on finish.

5 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


8. The following window appears on the screen.

6 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Result:

Thus the android studio is installed successfully.

7 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Ex:2 Using Android Studio – Simple App design

Aim:

To use the android studio to build a simple application which displays name and rollno.

Android Studio Basics:

Tool Bar

1. Sync Project with Gradle Files

2. AVD Manager

3. Android SDK manager

4. Project Structure / Settings

Sync Project with Gradle Files

• Gradle is an open-source build automation system that builds upon the concepts of Apache
Ant and Apache Maven.

• It takes the best features from other build systems and combines them into one.

• The build system automatically takes all the source files - applies the appropriate tool - APK.

8 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


AVD Manager

To create a new virtual device, select Create Virtual Device option. The following screen will appear.

Select the required hardware for emulation. Preferably select Nexus 4. Click on Next. The required
components are installed.

9 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Once the installation finishes, click on finish. The System image window appears on the screen.

Select the required system image to be displayed as app icon and click on next. The System image gets
downloaded. After successful installation of system image, the following screen appears.

10 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


In this screen, we can name our virtual device.

In the Emulated Performance Tab, Select the graphics as Software- GLES 1.1 and click on finish.

The virtual Device gets created and to launch it press on the run button.

11 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Android SDK manager

If new version of android has to be downloaded and installed, then SDK Manager comes in
handy.

12 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Project Structure / Settings

This displays the location of the project and SDK file.

Storage of Android Project

• Manifest file
• Java Files
• Resources
– Drawable
– Layout
– Mipmap
– Values
• Colors.xml
• Strings.xml
• Styles.xml

13 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


AndroidManifest.xml
• The manifest presents essential information about the application to the Android system
• The AndroidManifest.xml file contains information of your package, including components of
the application such as activities, services, broadcast receivers, content providers etc.
• It performs some other tasks also:
– It is responsible to protect the application to access any protected parts by providing
the permissions.
– It also declares the android api that the application is going to use.
– It lists the instrumentation classes

Resources in Android

• Drawable
– Image files like .png, .jpg, .gif or XML files that are compiled into bitmaps, state lists,
shapes, animation drawable.
• Layout
– XML files that define a user interface layout.
• Mipmap
– It is basically used for keeping all the icons that we would be using in your application.
• Values
– XML files that contain simple values, such as strings, integers, and colors, styles used.

14 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Activity_main.xml – Layouts

15 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Running a Simple Application

1. Open Android Studio and start a new Android studio project.

2. Name your Project. Do not include any support. Click next.

16 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


3. Select the target device as phone.

4. Add an empty activity

17 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


5. Click on Finish

6. The project screen looks like this,

18 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


7. Start the Virtual device. Tools -> AVD Manager or click on the AVD Manager icon in the tool
bar.

8. Either create a new VD or start an existing one.

19 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


9. Once Started Screen looks like this,

10. One Successful completion Emulator looks like this,

20 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


11. Run the sample Application

12. Output obtained is as follows,

21 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


13. Open Activity_main.xml. Change the default values present. Text – “Rollno - Name”. Change
font to any color. Change the font style
14. Once changed, the output is as follows,

Result:

Thus, using android studio a simple application which displays name and rollno is built and the
output is successfully observed.

22 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Ex:3 Activity

Aim:

To write an android program to demonstrate the following,

 Lifecycle of an Activity
 Display a Toast message when a button is clicked.
 Navigate to second activity when a button is clicked.

Life Cycle of an activity

package com.example.psg.helloworld;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
public class MainActivity extends Activity
{
String msg = "Android : ";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(msg, "The onCreate() event");
}
@Override
protected void onStart() {
super.onStart();
Log.d(msg, "The onStart() event");
}
@Override
protected void onResume() {
super.onResume();
Log.d(msg, "The onResume() event");
}
@Override
protected void onPause() {
super.onPause();
Log.d(msg, "The onPause() event");
}
@Override
protected void onStop() {
super.onStop();
Log.d(msg, "The onStop() event");
}
@Override
public void onDestroy() {

23 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


super.onDestroy();
Log.d(msg, "The onDestroy() event");
}
}

Output:

Back Button Pressed

24 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


App Selected from recently used menu

App removed from recently used menu

Display a Toast message when a button is clicked

package com.example.psg.helloworld;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
public class MainActivity extends Activity
{
String msg = "Android : ";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

}
Public void OnClickButton(View v)
{
Toast.makeText(this,”Button Clicked”,Toast.LENGTH_LONG).show();
}
}

25 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Link the method with the button

Output:

26 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Navigate to second activity when a button is clicked:

Main Activity

package com.example.psg.helloworld;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
public class MainActivity extends Activity
{
String msg = "Android : ";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

}
Public void OnSelect(View v)
{
Intent i=new Intent(this,page2.class);
startActivity(i);
}
}

Page2 Activity

package com.example.psg.helloworld;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
public class page2 extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_page2);

27 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Output:

Result:

Thus the android program to demonstrate the following,

 Lifecycle of an Activity
 Display a Toast message when a button is clicked.
 Navigate to second activity when a button is clicked.

are executed successfully.

28 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Ex:4 Services

Aim:
To Develop an Android Application to demonstrate the working of service.
 When the first button is clicked
a. Service must be started
b. Toast Message must be displayed.
 When the second button is clicked
a. Service must be terminated.
b. Toast message has to be displayed.
Service:
Main activity
package com.example.psg.ssservice;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity


{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onStart(View v)
{
Intent i=new Intent(this,MyService.class);
startService(i);
}
public void onStop(View v)
{
Intent i=new Intent(this,MyService.class);
stopService(i);
}
}

MyService.java
import android.app.Service;
import android.content.Intent;

29 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


import android.os.IBinder;
import android.widget.Toast;

public class MyService extends Service {


public MyService()
{
}
@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();
}
}

Output:

Result:
Thus, the service demonstration is executed and the result is observed successfully.

30 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Ex:5a Custom Broadcast Receiver

Aim:
To design an android application to visualize the custom generated broadcast message.
Custom Broadcast Receiver
Main Activity
package com.example.psg.broadcast_receiver;
import android.content.Intent;
import android.content.IntentFilter;
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);
}
public void broadcast(View v)
{
Intent intent = new Intent();
intent.setAction("com.tutorialspoint.CUSTOM_INTENT");
sendBroadcast(intent);
}
}
MyReceiver
package com.example.psg.broadcast_receiver;
import android.content.*;
import android.widget.*;
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "Intent Detected.",
Toast.LENGTH_LONG).show();
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.psg.broadcast_receiver">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"

31 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

<receiver
android:name=".MyReceiver"
android:enabled="true"
android:exported="true">
<action android:name="com.tutorialspoint.CUSTOM_INTENT"/>

</receiver>
</application>

</manifest>

Output:

Result:
Thus, custom generated broadcast message is implemented and executed successfully.

32 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Ex:5b System Generated Broadcast Receiver

Aim:

To design an android application to visualize the system generated broadcast message for
AIRPLANE_MODE.

System Generated Broadcast Message

Main Activity
package com.example.psg.broadcast_receiver;
import android.content.Intent;
import android.content.IntentFilter;
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);
}
}
MyReceiver
package com.example.psg.broadcast_receiver;
import android.content.*;
import android.widget.*;
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "Airplane Mode Changed !!!",
Toast.LENGTH_LONG).show();
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.psg.broadcast_receiver">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"

33 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

<receiver
android:name=".MyReceiver"
android:enabled="true"
android:exported="true">
<action android:name="android.intent.action.AIRPLANE_MODE
"/>
</receiver>
</application>
</manifest>

Output:

Result:
Thus, System generated broadcast message is implemented and executed successfully.

34 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Ex: 6a Implicit Intent

Aim:
a) To design an android application to visit the url www.google.co.in using the concept of Implicit
intent.
b) To design an android application to open a dialer window with a given number 1234567890 using
the concept of Implicit intent.
Implicit Intent
Main Activity.java
package com.example.psg.iintent;

import android.content.Intent;
import android.net.Uri;
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);
}
public void onClickgoogle(View v)
{
Intent i = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://www.google.com"));
startActivity(i);
}
public void onClicktele(View v)
{
Intent i = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("tel:1234567890"));
startActivity(i);
}
}

35 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Output:

Result:
Thus, the concept of implicit intent is implemented successfully.

36 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Ex:6b Explicit Intent

Aim:

To design an android application to send and receive user defined messages between main
activity and another activity like follows:
• Text message to be sent from main activity to second activity
• Text message should get displayed on second activity
• Return message from second activity should be sent to main activity
• Return text message should get displayed on main activity
Explicit Intent:
MainActivity
package com.example.psg.user_interface;

import android.content.Intent;
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


{
public static final int TEXT_REQUEST = 1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void send_message(View v)
{
EditText e1=(EditText)findViewById(R.id.p1_e);
String s=e1.getText().toString();

Intent i=new Intent(this,page2.class);


i.putExtra("msg",s);
startActivityForResult(i,TEXT_REQUEST);
}
public void onActivityResult(int requestCode, int
resultCode,Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
TextView t1=(TextView)findViewById(R.id.p1_msg);
TextView t2=(TextView)findViewById(R.id.p1_msg_display);

37 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


EditText e1=(EditText)findViewById(R.id.p1_e);
if (requestCode == TEXT_REQUEST)
{
if (resultCode == RESULT_OK)
{
String reply = data.getStringExtra(page2.EXTRA_REPLY);
e1.setText("");
t1.setVisibility(View.VISIBLE);
t2.setText(reply);
t2.setVisibility(View.VISIBLE);
}
}
}
}
Page2 Activity
package com.example.psg.user_interface;

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

public class page2 extends AppCompatActivity {


public static final String EXTRA_REPLY
="com.example.psg.user_interface.extra.REPLY";
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_page2);

TextView t1=(TextView)findViewById(R.id.p2_msg_display);
String s=getIntent().getExtras().getString("msg");
t1.setText(s);

}
public void send_reply(View v)
{
EditText e2=(EditText)findViewById(R.id.p2_e);
String ss=e2.getText().toString();
Intent i=new Intent();
i.putExtra(EXTRA_REPLY,ss);
setResult(RESULT_OK,i);
finish();
}
}

38 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Output:

Result:
Thus, the explicit intent is implemented successfully.

39 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Ex:7 Simple Calculator

Aim:
To design a simple calculator using Android.
Simple Calculator:
Main Activity:
package com.example.swethang.calculator;

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

public class MainActivity extends AppCompatActivity


{

int a;
int flaga;
int b;
int flagb;
char c;
int ans;
MainActivity()
{
ans=0;
a=0;
b=0;
c='a';
flaga=99;
flagb=99;
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void seta(int data)
{
a=(a*10)+data;
flaga=1;
}
public void setb(int data)
{
b=(b*10)+data;
flagb=1;
}
public int checkposition()

40 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


{
if(c=='a')
{
return 1;
}
else
{
return 2;
}
}
public int checkvalidity()
{
if(flaga==99)
{
Toast.makeText(this,"Enter the first operand
!!!",Toast.LENGTH_LONG).show();
return -1;
}
else if(c=='a')
{
Toast.makeText(this,"Enter the Operation to be performed
!!!",Toast.LENGTH_LONG).show();
return -1;
}
else if(flagb==99)
{
Toast.makeText(this,"Enter the second operand
!!!",Toast.LENGTH_LONG).show();
return -1;
}
else
{
return 1;
}
}
public void press1(View v)
{
int data=1;
TextView t=(TextView)findViewById(R.id.display);
String s=t.getText().toString();
s=s+""+data+"";
t.setText(s);
int i=checkposition();
if(i==1)
{
seta(data);
}
else if(i==2)
{
setb(data);
}
}
public void press2(View v)
{
int data=2;
TextView t=(TextView)findViewById(R.id.display);
String s=t.getText().toString();

41 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


s=s+""+data+"";
t.setText(s);
int i=checkposition();
if(i==1)
{
seta(data);
}
else if(i==2)
{
setb(data);
}
}
public void press3(View v)
{
int data=3;
TextView t=(TextView)findViewById(R.id.display);
String s=t.getText().toString();
s=s+""+data+"";
t.setText(s);
int i=checkposition();
if(i==1)
{
seta(data);
}
else if(i==2)
{
setb(data);
}
}
public void press4(View v)
{
int data=4;
TextView t=(TextView)findViewById(R.id.display);
String s=t.getText().toString();
s=s+""+data+"";
t.setText(s);
int i=checkposition();
if(i==1)
{
seta(data);
}
else if(i==2)
{
setb(data);
}
}
public void press5(View v)
{
int data=5;
TextView t=(TextView)findViewById(R.id.display);
String s=t.getText().toString();
s=s+""+data+"";
t.setText(s);
int i=checkposition();
if(i==1)
{
seta(data);

42 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


}
else if(i==2)
{
setb(data);
}
}
public void press6(View v)
{
int data=6;
TextView t=(TextView)findViewById(R.id.display);
String s=t.getText().toString();
s=s+""+data+"";
t.setText(s);
int i=checkposition();
if(i==1)
{
seta(data);
}
else if(i==2)
{
setb(data);
}
}
public void press7(View v)
{
int data=7;
TextView t=(TextView)findViewById(R.id.display);
String s=t.getText().toString();
s=s+""+data+"";
t.setText(s);
int i=checkposition();
if(i==1)
{
seta(data);
}
else if(i==2)
{
setb(data);
}
}
public void press8(View v)
{
int data=8;
TextView t=(TextView)findViewById(R.id.display);
String s=t.getText().toString();
s=s+""+data+"";
t.setText(s);
int i=checkposition();
if(i==1)
{
seta(data);
}
else if(i==2)
{
setb(data);
}
}

43 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


public void press9(View v)
{
int data=1;
TextView t=(TextView)findViewById(R.id.display);
String s=t.getText().toString();
s=s+""+data+"";
t.setText(s);
int i=checkposition();
if(i==1)
{
seta(data);
}
else if(i==2)
{
setb(data);
}
}
public void press0(View v)
{
int data=0;
TextView t=(TextView)findViewById(R.id.display);
String s=t.getText().toString();
s=s+""+data+"";
t.setText(s);
int i=checkposition();
if(i==1)
{
seta(data);
}
else if(i==2)
{
setb(data);
}
}
public void pressC(View v)
{
int data=0;
TextView t=(TextView)findViewById(R.id.display);
t.setText("");
a=0;
flaga=99;
b=0;
flagb=99;
c='a';
}
public void press_add(View v)
{
c='+';
TextView t=(TextView)findViewById(R.id.display);
String s=t.getText().toString();
s=s+""+c+"";
t.setText(s);
}
public void press_sub(View v)
{
c='-';
TextView t=(TextView)findViewById(R.id.display);

44 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


String s=t.getText().toString();
s=s+""+c+"";
t.setText(s);
}
public void press_mul(View v)
{
c='*';
TextView t=(TextView)findViewById(R.id.display);
String s=t.getText().toString();
s=s+""+c+"";
t.setText(s);
}
public void press_div(View v)
{
c='/';
TextView t=(TextView)findViewById(R.id.display);
String s=t.getText().toString();
s=s+""+c+"";
t.setText(s);
}
public void press_eq(View v)
{
int check=checkvalidity();
if(check==1)
{
switch(c)
{
case '+':ans=a+b; break;
case '-':ans=a-b; break;
case '*':ans=a*b; break;
case '/':ans=a/b; break;
}
TextView t=(TextView)findViewById(R.id.display);
String s=t.getText().toString();
s=""+ans+"";
t.setText(s);
int i=0;
while(i<100)
{
i++;
}
t.setText("");
a=0;flaga=99;b=0;flagb=99;c='a';
}
}

45 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Layout Design:

Output:

Result:
Thus, the simple calculator is implemented successfully.

46 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Ex:8 Android input controls

Aim:
 To Design an android application to demonstrate the concept of spinner.
 To Design an android application to obtain a feedback regarding a person’s programming
knowledge. (Use appropriate input controls)

Spinner:

MainActivity:
package com.example.psg.spinner;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity
{
Spinner s1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

s1=(Spinner)findViewById(R.id.spinner1);

String[] c = {"C","C++","C#","Java","Python"};

ArrayAdapter adapter = new ArrayAdapter(this,


android.R.layout.simple_spinner_item, c);

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdo
wn_item);
s1.setAdapter(adapter);
}
public void display(View v)
{
s1=(Spinner)findViewById(R.id.spinner1);
String item=s1.getSelectedItem().toString();

Toast.makeText(getApplicationContext(),"Selected:"+item,Toast.LENGTH_L
ONG).show();

} }

47 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Output:

Feedback:
Main Activity
package com.example.psg.feedback;
import android.support.v7.app.AppCompatActivity;
import android.widget.*;
public class MainActivity extends AppCompatActivity {
Spinner s1;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
s1=(Spinner)findViewById(R.id.gender);
String[] c = {"Male","Female"};
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_spinner_item, c);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdo
wn_item);
s1.setAdapter(adapter);}
public void onsubmit(View v)
{
EditText name=(EditText)findViewById(R.id.name);
String display=name.getText().toString();

48 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


s1=(Spinner)findViewById(R.id.gender);
String item=s1.getSelectedItem().toString();
display+=item;
RadioButton r1=(RadioButton)findViewById(R.id.r1);
RadioButton r2=(RadioButton)findViewById(R.id.r2);
RadioButton r3=(RadioButton)findViewById(R.id.r3);
if(r1.isChecked())
{
display+=r1.getText().toString();
}
if(r2.isChecked())
{
display+=r2.getText().toString();
}
if(r3.isChecked())
{
display+=r3.getText().toString();
}
RatingBar rr=(RatingBar)findViewById(R.id.r);
display+=rr.getRating()+"";
Toast.makeText(this,display,Toast.LENGTH_LONG).show();
}}
Output:

Result:

Thus, the android input controls are implemented successfully.

49 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Ex:9 Threads in Android

Aim:
To implement the concepts of threads in android.
Threads:
Main Activity:
package com.example.swetha.threads;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity


{

ProgressBar p;
TextView t;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
p=(ProgressBar) findViewById(R.id.p1);
t=(TextView) findViewById(R.id.display);
}

public void start_progress(View v)


{
Runnable r=new Runnable()
{
@Override
public void run()
{
for(int i=1;i<=100;i++)
{
final int temp=i;
try
{
Thread.sleep(100);
}
catch (Exception e)
{

50 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Log.d("Exception",e.toString());
}
p.post(new Runnable()
{
@Override
public void run()
{
p.setProgress(temp);
t.setText(temp+"%");
}
});
}//for
}//run
};//runnable
Thread tt=new Thread(r);
tt.start();
}

Output:

Result:
Thus, the concept of threads in android is implemented successfully.

51 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Ex:10 Alarm Manager

Aim:
To implement the Alarm manager service in android.
Alarm Manager:
Main Activity:
package com.example.swetha.alarm;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

import java.util.Calendar;

public class MainActivity extends AppCompatActivity {

//Pending intent instance


private PendingIntent pendingIntent;
private RadioButton secondsRadioButton, minutesRadioButton,
hoursRadioButton;
//Alarm Request Code
private static final int ALARM_REQUEST_CODE = 133;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Find id of all radio buttons
secondsRadioButton = (RadioButton)
findViewById(R.id.seconds_radio_button);
minutesRadioButton = (RadioButton)
findViewById(R.id.minutes_radio_button);
hoursRadioButton = (RadioButton)
findViewById(R.id.hours_radio_button);
/* Retrieve a PendingIntent that will perform a broadcast */
Intent alarmIntent = new Intent(MainActivity.this,
AlarmReceiver.class);

52 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


pendingIntent = PendingIntent.getBroadcast(MainActivity.this,
ALARM_REQUEST_CODE, alarmIntent, 0);

//Find id of Edit Text


final EditText editText = (EditText)
findViewById(R.id.input_interval_time);
//Set On CLick over start alarm button
findViewById(R.id.start_alarm_button).setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
String getInterval =
editText.getText().toString().trim();//get interval from edittext
//check interval should not be empty and 0
if (!getInterval.equals("") &&
!getInterval.equals("0"))
//finally trigger alarm manager
triggerAlarmManager(getTimeInterval(getInterval));

}
});

//set on click over stop alarm button


findViewById(R.id.stop_alarm_button).setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
//Stop alarm manager
stopAlarmManager();
}
});

//get time interval to trigger alarm manager


private int getTimeInterval(String getInterval) {
int interval = Integer.parseInt(getInterval);//convert string
interval into integer

//Return interval on basis of radio button selection


if (secondsRadioButton.isChecked())
return interval;
if (minutesRadioButton.isChecked())
return interval * 60;//convert minute into seconds
if (hoursRadioButton.isChecked()) return interval * 60 *
60;//convert hours into seconds

//else return 0
return 0;
}

53 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


//Trigger alarm manager with entered time interval
public void triggerAlarmManager(int alarmTriggerTime)
{
// get a Calendar object with current time
Calendar cal = Calendar.getInstance();
// add alarmTriggerTime seconds to the calendar object
cal.add(Calendar.SECOND, alarmTriggerTime);
AlarmManager manager = (AlarmManager)
getSystemService(Context.ALARM_SERVICE);//get instance of alarm
manager
manager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
pendingIntent);//set alarm manager with entered timer by converting
into milliseconds
Toast.makeText(this, "Alarm Set for " + alarmTriggerTime + "
seconds.", Toast.LENGTH_SHORT).show();
}

//Stop/Cancel alarm manager


public void stopAlarmManager() {

AlarmManager manager = (AlarmManager)


getSystemService(Context.ALARM_SERVICE);
manager.cancel(pendingIntent);//cancel the alarm manager of
the pending intent
//Stop the Media Player Service to stop sound
stopService(new Intent(MainActivity.this,
AlarmSoundService.class));
Toast.makeText(this, "Alarm Canceled/Stop by User.",
Toast.LENGTH_SHORT).show();
}
}
Alarm Receiver
package com.example.swetha.alarm;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class AlarmReceiver extends BroadcastReceiver


{
@Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "ALARM!! ALARM!!",
Toast.LENGTH_SHORT).show();
//Stop sound service to play sound for alarm
context.startService(new Intent(context,
AlarmSoundService.class));
}

54 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


}
Alarm Service
package com.example.swetha.alarm;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.support.annotation.Nullable;

public class AlarmSoundService extends Service {


private MediaPlayer mediaPlayer;

@Nullable
@Override
public IBinder onBind(Intent intent)
{
return null;
}

@Override
public void onCreate() {
super.onCreate();

//Start media player


mediaPlayer = MediaPlayer.create(this, R.raw.alarm_sound);
mediaPlayer.start();
mediaPlayer.setLooping(true);//set looping true to run it
infinitely
}

@Override
public void onDestroy() {
super.onDestroy();

//On destory stop and release the media player


if (mediaPlayer != null && mediaPlayer.isPlaying()) {
mediaPlayer.stop();
mediaPlayer.reset();
mediaPlayer.release();
}
}
}

55 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Output:

Result:
Thus, the Alarm Manager is implemented successfully.

56 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Ex:11 Persistent Storage - SQLite

Aim:
To design an android application to demonstrate the concept of persistent storage using SQLite.
SQLite:
Main Activity:
package com.example.swetha.sqlite;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

public String DB_Name="Student";


SQLiteDatabase db;
String roll_no;
String name;
int rank;
@Override
protected void onCreate(Bundle savedInstanceState)
{

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//database creation
db=openOrCreateDatabase("Student",Context.MODE_PRIVATE,null);
create_table();
}
public void add_data(View v)
{
getdata();
if(roll_no!="" && name!="" && rank>0)
{
String insert="Insert into details
values('"+roll_no+"','"+name+"',"+rank+")";
db.execSQL(insert);
showmessage("Insertion Success !!!");
}

57 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


clear_data();
}
public void update_data(View v)
{
getdata();
if(roll_no!="" && name!="" && rank>0)
{
String update="update details set
name='"+name+"',rank="+rank+" where roll_no='"+roll_no+"'";
db.execSQL(update);
showmessage("Updation Success !!!");
}
clear_data();
}
public void delete_data(View v)
{

EditText e1=(EditText) findViewById(R.id.roll_no);


roll_no=e1.getText().toString();
if(roll_no!="")
{
String delete="delete from details where
roll_no='"+roll_no+"'";
db.execSQL(delete);
showmessage("Deletion Success !!!");
}
e1.setText("");
}
public void view_data(View v)
{
String display="";
String select="select * from details";
Cursor c=db.rawQuery(select,null);
if(c.moveToFirst())
{

do {

display+=c.getString(0);
display+=c.getString(1);
display+=c.getInt(2)+"\n";

}while(c.moveToNext());
}
showmessage(display);
clear_data();
}
public void showmessage(String msg)
{
AlertDialog.Builder b=new AlertDialog.Builder(this);
b.setTitle("Message");
b.setMessage(msg);

58 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


b.show();
}
public void getdata()
{
EditText e1=(EditText) findViewById(R.id.roll_no);
roll_no=e1.getText().toString();

EditText e2=(EditText) findViewById(R.id.name);


name=e2.getText().toString();

EditText e3=(EditText) findViewById(R.id.rank);


rank=Integer.parseInt(e3.getText().toString());

}
public void create_table()
{
String table="Create table if not exists details(roll_no
Varchar(50) primary key,name varchar(50),rank int);";
db.execSQL(table);
}
public void clear_data()
{
EditText e1=(EditText) findViewById(R.id.roll_no);
EditText e2=(EditText) findViewById(R.id.name);
EditText e3=(EditText) findViewById(R.id.rank);

e1.setText("");
e2.setText("");
e3.setText("");
}
}
Output:

Result:
Thus the android application is designed and implemented successfully.

59 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Ex:12a) Multimedia in Android – Media Player

Aim:
To design a Media player application using android.
Media Player:
Main Activity:
package com.example.swetha.audio;

import android.media.MediaPlayer;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.SeekBar;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity


{
double end_time,start_time;
int flag;
SeekBar s;
MediaPlayer mp;
private Handler myHandler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
flag=0;
mp=MediaPlayer.create(this, R.raw.song1);
s=(SeekBar)findViewById(R.id.s1);
s.setClickable(false);

}
private Runnable UpdateSongTime = new Runnable()
{
public void run() {
start_time = mp.getCurrentPosition();
s.setProgress((int)start_time);
myHandler.postDelayed(this, 100);
}
};
public void play_song(View v)
{
try
{

60 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


mp.start();
Toast.makeText(this,"Song is Playing
!!!",Toast.LENGTH_LONG).show();

end_time = mp.getDuration();
start_time = mp.getCurrentPosition();

if (flag== 0)
{
s.setMax((int) end_time);
flag=1;
}

s.setProgress((int)start_time);
myHandler.postDelayed(UpdateSongTime,100);

}
catch(Exception e)
{
e.printStackTrace();
}
}
public void pause_song(View v)
{
Toast.makeText(getApplicationContext(),
"Pausing sound",Toast.LENGTH_SHORT).show();
mp.pause();
}
public void forward(View v)
{
int temp = (int)start_time;

if((temp+10)<=end_time)
{
start_time = start_time+10;
mp.seekTo((int) start_time);
Toast.makeText(this,
"You have Jumped forward 10
seconds",Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(this,
"Cannot jump forward 10
seconds",Toast.LENGTH_SHORT).show();
}
}
public void rewind(View v)
{
int temp = (int)start_time;

if((temp-10)<=end_time)
{

61 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


start_time = start_time-10;
mp.seekTo((int) start_time);
Toast.makeText(this,
"You have Jumped back 10
seconds",Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(getApplicationContext(),
"Cannot jump back 10
seconds",Toast.LENGTH_SHORT).show();
}
}

}
Output:

Result:
Thus, the media player application is executed successfully.

62 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Ex:12b) Multimedia in Android – Video Player

Aim:
To design a video player application in android.
Video Player:
Main Activity:

package com.example.swetha.video;

import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView videoView =(VideoView)findViewById(R.id.vdVw);
//Set MediaController to enable play, pause, forward, etc
options.
MediaController mediaController= new MediaController(this);
mediaController.setAnchorView(videoView);
//Location of Media File
Uri uri = Uri.parse("android.resource://" + getPackageName() +
"/" + R.raw.video1);
//Starting VideView By Setting MediaController and URI
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
}
}

63 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Output:

Result:
Thus, the Video player application is implemented successfully.

64 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Ex:13 Location based services

Aim:
To implement location based services in android.
Location based Services:
Main Activity:
package com.example.swetha.location;

import android.Manifest;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.example.swetha.location.GPSTracker;

public class MainActivity extends AppCompatActivity


{
// GPSTracker class
GPSTracker gps;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View a)
{
gps = new GPSTracker(MainActivity.this);
if(gps.canGetLocation())
{

double latitude = gps.getLatitude();


double longitude = gps.getLongitude();

TextView t1=(TextView)findViewById(R.id.display1);
TextView t2=(TextView)findViewById(R.id.display2);

t1.setText(latitude+"");
t2.setText(longitude+"");
}
else {
Toast.makeText(getApplicationContext(),

65 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


"Problem in getting GPS
Location",Toast.LENGTH_LONG).show();
}
}
}
Service:
package com.example.swetha.location;

import android.Manifest;
import android.app.AlertDialog;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.util.Log;

public class GPSTracker extends Service implements LocationListener {

private final Context mContext;

boolean isGPSEnabled = false;


boolean isNetworkEnabled = false;
boolean canGetLocation = false;
Location location; // location
double latitude; // latitude
double longitude; // longitude
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; //
10 meters
private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1; //
1 minute
protected LocationManager locationManager;

public GPSTracker(Context context)


{
this.mContext = context;
getLocation();
}
public double getLatitude()
{
if(location != null){
latitude = location.getLatitude();
}
return latitude;

66 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


}
public double getLongitude()
{
if(location != null){
longitude = location.getLongitude();
}
return longitude;
}
public boolean canGetLocation()
{
return this.canGetLocation;
}
public Location getLocation()
{
try
{
locationManager = (LocationManager)
mContext.getSystemService(LOCATION_SERVICE);
isGPSEnabled =
locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
isNetworkEnabled =
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled)
{ }
else {
this.canGetLocation = true;
if (isNetworkEnabled)
{
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION)
!=
PackageManager.PERMISSION_GRANTED)
{

locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDE
R,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (locationManager != null)
{
location =
locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)
;
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}

67 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


}
}

if (isGPSEnabled) {
if (location == null) {

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (locationManager != null)
{
location =
locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
}

}
catch (Exception e) {
e.printStackTrace();
}

return location;
}

@Override
public void onLocationChanged(Location location) {
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle
extras) {
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

68 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


package="com.example.swetha.location">

<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission
android:name="android.permission.ACCESS_FINE_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/AppTheme">
<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=".GPSTracker"
android:enabled="true"
android:exported="true"></service>
</application>

</manifest>

Output:

Result:
Thus the location based services is implemented successfully.

69 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Ex:14 Google Maps

Aim:
To design an android application that will that adds a marker on Coimbatore city in google maps.
Google Map:
Map Activity:
package com.example.swetha.google_map;

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;

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;

public class MapsActivity extends FragmentActivity implements


OnMapReadyCallback {

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map
is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng coimbatore = new LatLng(11.0168, 76.9558);
mMap.addMarker(new
MarkerOptions().position(coimbatore).title("Marker in Coimbatore"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(coimbatore));
}
}

70 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Output:

Result:
Thus, the marker is displayed on Coimbatore city in the google map successfully.

71 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
PSG COLLEGE OF TECHNOLOGY, COIMBATORE.
15Z703 – MOBILE SYSTEM ENGINEERING
Unit 1 – Work Sheet 1
Name: Date:

Roll No:

Answer the following questions:

1. Consider a system with initial value 1010 (4 bit), find all possible states in 4 block Linear
Feedback Shift Register. Also explain why 0000 state is not possible. What is the formula to find
all possible states for n bit?
2. Consider a system with initial value 111 (3 bit), find all possible states in 4 block Linear
Feedback Shift Register.

Solve the below given cross word puzzle:

Vertical

1. Wireless communication
used in 150BC
2. Key feature of 1G
3. Future generation with
almost no limitations?
4. 3G Started with?
6. 4G is refered as?

Horizontal

5. Key Feature of 2G
7. Wireless communication
used in 1974

72 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Answers:
Vertical

1. Wireless communication used in 150BC (Smoke Signal)


2. Key feature of 1G (Voice call)
3. Future generation with almost no limitations? (5G)
4. 3G Started with? (Smart phones)
6. 4G is refered as? (MAGIC)

Horizontal

5. Key Feature of 2G (Text Message)


7. Wireless communication used in 1974 (Optical Telegraph)

73 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
PSG COLLEGE OF TECHNOLOGY, COIMBATORE.
15Z703 – MOBILE SYSTEM ENGINEERING
Unit 1 – Work Sheet 2
Name: Date:

Roll No:

Find the secret code:

In the below given word cloud, components of 3G technology are hidden. Find them out and
based on these components find out the secret message.

W C D M A Y G H R T Q H Z E O
N A K B W Z I Q N G R T U Q H
N X L U T X L E H C H E S G E
X S A S N C G A J F U V T G N
F A D A H A I V Y A W Z O I U
A S C P E C U P E K W M E M R
C N D M X B O V U H D M T A J
S M O T S F I D N W S I E A A
L H Z J D Y H M E V X T G E G
R Q R X M F J B Q K H W O N F
L G Q N T Q V O H J S W O B H
D Y P W Z X P K D L H X C N R
I O E R M P O Z K U K O U Q L
Z S F R S W I C M N M K L H N
M Y U E I C P E E E R I Y O T

Secret Message:

74 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


Answers:

AAA
HOMEAGENT
PDSN
WALSHCODE

Secret Message: CDMA 2000

75 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
PSG COLLEGE OF TECHNOLOGY, COIMBATORE
15Z703 - MOBILE SYSTEM ENGINEERING
Unit 2 – Worksheet 3
Name: Date:

Roll No:

Complete the Cross Word below:

Clues:

Across
Down
2. IEEE 802.16, Operating Frequency 10 GHz to
66 GHz. 1. Signal before modulation.
5. Signal after Modulation. 2. IEEE 802.11, Operating Frequency 2.4 GHz.
7. No Antenna in Chip, No Restriction in operating 3. One of the 4G Applications.
frequency. 4. What is the primary application of WiFi?
8. High Speed Data Access, High Quality 6. First Responder during Communication failure.
Streaming Video.
9. Started in 2004 by 3GPP, Evolved from UMTS.
76 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.
Answers:
Across

2. IEEE 802.16, Operating Frequency 10 GHz to 66 GHz. (WiMax)


5. Signal after Modulation. (Pass Band Signal)
7. No Antenna in Chip, No Restriction in operating frequency. (USR)
8. High Speed Data Access, High Quality Streaming Video. (4G)
9. Started in 2004 by 3GPP, Evolved from UMTS. (LTE)

Down

1. Signal before modulation. (Base Band Signal)


2. IEEE 802.11, Operating Frequency 2.4 GHz. (Wifi)
3. One of the 4G Applications. (Education)
4. What is the primary application of WiFi? (WLAN)
6. First Responder during Communication failure. (SDR)

77 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
PSG COLLEGE OF TECHNOLOGY, COIMBATORE
15Z703 - MOBILE SYSTEM ENGINEERING
Unit 2 – Worksheet 4
Name: Date:

Roll No:

Solve the Word Puzzle

In the below given puzzle, the important components of IMS Architecture are hidden. Find them
if you can.

Q T M M U L Y N I F R J T D M
K Q I W P A U P I S Q L F K U
M S P X Q E E Q J J O S N E V
C D U V M K N A X J C E C F S
G K W C J T T N G T C D O S C
O Y O B C P E H G N S R I V Q
T F A T H I B H X I C M O B Z
J C X M V D U U B W F B H B M
Q O L V F D Y U Y E L W H W P
C T E T P Y X M Z Y V Q S D H
L D Q G T K F I Q K P T S T G
I S I M D V V S T U U C L R S
C L E Y P P P U A W S Y R B V
X O E Z F I Q G N G T Q L F P
Q Q Z S F B D Y T E X P F T L

Answers:

CSCF , CSIM, EPC, ISIM, PCRF, PDG, SIM, SIPUA, UICC, USIM

78 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
PSG COLLEGE OF TECHNOLOGY, COIMBATORE
15Z703 - MOBILE SYSTEM ENGINEERING
Unit 2 – Worksheet 5
Name:
Date:

Roll No:

Solve the Double Word Puzzle

Unscramble each of the clue words.


Take the letters that appear in boxes and unscramble them for the final message.

Answers:
 Channel Occupancy
 Free Channel
 Cooperating Spectrum Sensing
 Improved Coverage
 Continuous Spectrum Sensing
 Branded Reseller
 Service provider
 Full MVNO
 Software Controlled Radio
 Ideal Software Radio
 Final: IMS

79 of 79 Prepared By: Ms.Swetha.N.G., Asst Professor, Dept CSE, PSCT Coimbatore.

You might also like