You are on page 1of 13

Assignment No A-02

Aim
Write a program to perform profile translation-based proactive adaptation using context
management in smartphones. Objective of this assignment is to automatically generates
users profile according to the scenarios using machine learning approaches. System should
allow to keep users full profile in user domain resulting into centralizing or exchanging
the profile information with increase in the consistency of profile information.

Pre-requisite
1. Android Studio
2. Programming language basics.
3. Smart-phone / AVD.

Objective
1. Study of building user profile creating user profile using smart mobile.
2. Approach to handle different approaches to manage continuous data.

Problem Statement
Program to build smart mobile application for user profiling.

Hardware / Software Used


1. Android Studio

Mathematical Model
M = { s, e, X, Y, DD, NDD, fme , M emshared , Fsuccess , Ff ailure , CP UCoreCount }

1. s : Start State - Install the .apk file on the android device and start the application.
2. e : End State - Location is displayed and users phone sound profile is changed.
3. X : Input -Latitude, Longitude.
4. Y : Output - Generated address and user profile is changed to Vibration or Ringer(General)
mode.
5. DD : Deterministic Data - Latitude and Longitude of location.
6. NDD : Non-Deterministic Data - Location of user, mode set by user.
7. Fme : setRingerMode(AudioManager.RINGER MODE VIBRATE) and setRingerMode(AudioManager.RINGER MODE NORMAL) used to change the sound profile
mode of the users phone.
8. Memshared : No shared Memory is used.
9. FSuccess : Generated address with Vibrant or Ringer (General) sound mode.
10. FFailure: If GPS is disable.
11. CPUCoreCount: 1.

Theory
User profile generation by context awareness
With the increasing use of web applications in the smart phones it has become very difficult
for users to give their user profile (which is maintained by the service providers) information
to the service providers. But this is actually not relevant because all the information of user
is not needed at everywhere. In actual context this is irrelevant. As if the website relates
to online shopping,then the profile would contain information like name, postal address and
contact ,email address and basic details or in online reservation require name, age, ID proof
etc. According to this different profiles are generated.
The abstract view of actual user profile are provided to the service provider not whole profile. To recognize what details of user profile is needed by service provider we use the concept of
context awareness. Context can be referred as, All the web applications in a smartphone also
all different kinds of websites that user visits through these Applications. Context awareness
can be referred as the various websites/web applications the user refers to. Context aware is
similar to the cache, i.e, providing the data to the user according to the abstract view. Only
required amount of data will be display in abstract view.
When user tries to open an application which requires profile then this will be recognized
and while that site loads, profile will be generated automatically. To generate the profile various
needed of website/application should be known. Generating the profile according to the context
determined is the main task of the application. The personalization of data is to be done at
user side and the profile database is to be stored in the smartphone .
Context Awareness Layer
Context is taken as main input to the system. The basic task of context handler is to recognize
the current context in which user is operating. Recognition of context can be done by checking
stored context. Assume a scenario, where an user is using an app for the first time or navigating
to the website for the first time. This new context is passed to the Context Predictor and if
required is passed to Context Storage Manager.
Context Storage Manager stores new context or updates previous data according to the
situation. This way, first layer recognizes the context that is nothing but the situation awareness
and suggests if current context is appropriate for profile translation. And finally forwards this
contextual information to the next layer.
Proactive Analyzer Layer
It takes the contextual information which is provided by upper layer. The Requirement Manager
in this layer will gather all the required information of the profile. This is done by extracting
the context proactively and without the users request and best results can be achieved by
properly examining the current context and gathering results accordingly. After this the data
is passed to the next layer.
Profile Translation
The layer takes the requirements from second layer via Retrieve Manager. It will check if those
user requirements are fulfilled by the database. If the user requirements are satisfied then
it creates the abstract view of profile. The layer will pass this abstract view to the Display
3

Manager from Proactive Analyzer Layer. It will display the view proactively. And if user
requirement are not fulfilled then it again try to generate new abstract view of profile.

Machine Learning
Machine learning is a type of artificial intelligence (AI) that provides computers with the ability to learn without being explicitly programmed and to make computer more smart. Machine
learning focuses on the development of computer programs that can teach themselves to grow
and change when exposed to new data and perform various task accordingly.
The process of machine learning is similar to that of data mining. Both systems search
through data to look for patterns. However, instead of extracting data for human comprehension as is the case in data mining applications machine learning uses that data to improve the
programs own understanding. Machine learning programs detect patterns in data and adjust
program actions accordingly.

Procedure
Install Android Studio/ Eclipse ADT
Create new project
Add Main Activity
Add function GPS Tracker and Location Address
In GPS tracker class we need to obtain latitude,longitude,network address and GPS location to obtain the users location
Get location address from server in Location address class file
Run the Main Activity and generate apk file
Install apk file on smartphone and start the application
Confirm that your phones sound profile is General
Enable GPS
Location is retrieved

Conclusion
Here,we study the smart mobile application for student profile, and approach to handle Continuous values of student using app.

Program
=================================================
GROUP A
Assignment No : A2
Title : Write a program to perform profile translation-based proactive adaptation using
context management in smartphones. Objective of this assignment is to automatically
generates users profile according to the scenarios using machine learning approaches.
System should allow to keep users full profile in user domain resulting into centralizing or
exchanging the profile information with increase in the consistency of profile information.
Roll No :
Batch :
Class : BE ( Computer )
=================================================
//Gps Tracker
package com.gescoe.showlocationmap;
import android.app.AlertDialog;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
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.util.Log;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
public class GPSTracker extends Service implements LocationListener
{
private final Context mContext;
// flag for GPS Status
boolean isGPSEnabled = false;
// flag for network status
boolean isNetworkEnabled = false;
boolean canGetLocation = false;
Location location;
public static double latitude;
public static double longitude;
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10;
private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1;
protected LocationManager locationManager;
public GPSTracker(Context context) {
this.mContext = context.getApplicationContext();
getLocation();
5

}
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) {
// showSettingsAlert();
} else {
this.canGetLocation = true;
if (isNetworkEnabled) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("Network", "Network");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
updateGPSCoordinates();
}
}
if (isGPSEnabled) {
if (location == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
updateGPSCoordinates();
}
}
}
}
} catch (Exception e) {
Log.e("Error : Location",
"Impossible to connect to LocationManager", e);
}
return location;
}
public void updateGPSCoordinates() {
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
6

}
}
public void stopUsingGPS() {
if (locationManager != null) {
locationManager.removeUpdates(GPSTracker.this);
}
}
public double getLatitude() {
if (location != null) {
latitude = location.getLatitude();
}
return latitude;
}
public double getLongitude() {
if (location != null) {
longitude = location.getLongitude();
}
return longitude;
}
public boolean canGetLocation() {
return this.canGetLocation;
}
public List<Address> getGeocoderAddress(Context context) {
if (location != null) {
Geocoder geocoder = new Geocoder(context, Locale.ENGLISH);
try {
List<Address> addresses = geocoder.getFromLocation(latitude,
longitude, 1);
return addresses;
} catch (IOException e) {
// e.printStackTrace();
Log.e("Error : Geocoder", "Impossible to connect to Geocoder",
e);
}
}
return null;
}
public String getAddressLine(Context context) {
List<Address> addresses = getGeocoderAddress(context);
if (addresses != null && addresses.size() > 0) {
Address address = addresses.get(0);
String addressLine = address.getAddressLine(0);
return addressLine;
} else {
return null;
}
}
public String getLocality(Context context) {
7

List<Address> addresses = getGeocoderAddress(context);


if (addresses != null && addresses.size() > 0) {
Address address = addresses.get(0);
String locality = address.getLocality();
return locality;
} else {
return null;
}
}
public String getPostalCode(Context context) {
List<Address> addresses = getGeocoderAddress(context);
if (addresses != null && addresses.size() > 0) {
Address address = addresses.get(0);
String postalCode = address.getPostalCode();
return postalCode;
} else {
return null;
}
}
public String getCountryName(Context context) {
List<Address> addresses = getGeocoderAddress(context);
if (addresses != null && addresses.size() > 0) {
Address address = addresses.get(0);
String countryName = address.getCountryName();
return countryName;
} else {
return null;
}
}
@Override
public void onLocationChanged(Location location) {
this.location = location;
getLatitude();
getLongitude();
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
8

// TODO Auto-generated method stub


}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}

}
----------------------------------------------------------------------------------//Location Address
package com.gescoe.showlocationmap;
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
public class LocationAddress {
private static final String TAG = "LocationAddress";
public static void getAddressFromLocation(final double latitude,
final double longitude, final Context context, final Handler handler) {
Thread thread = new Thread() {
@Override
public void run() {
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
String result = null;
try {
List<Address> addressList = geocoder.getFromLocation(
latitude, longitude, 1);
if (addressList != null && addressList.size() > 0) {
Address address = addressList.get(0);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < address.getMaxAddressLineIndex(); i++) {
sb.append(address.getAddressLine(i)).append("\n");
}
sb.append(address.getLocality()).append("\n");
sb.append(address.getPostalCode()).append("\n");
sb.append(address.getCountryName());
result = sb.toString();
}
} catch (IOException e) {
Log.e(TAG, "Unable connect to Geocoder", e);
} finally {
Message message = Message.obtain();
9

message.setTarget(handler);
if (result != null) {
message.what = 1;
Bundle bundle = new Bundle();
result = "Latitude: " + latitude + " Longitude: " + longitude +
"\n\nAddress:\n" + result;
bundle.putString("address", result);
message.setData(bundle);
} else {
message.what = 1;
Bundle bundle = new Bundle();
result = "Latitude: " + latitude + " Longitude: " + longitude +
"\n Unable to get address for this lat-long.";
bundle.putString("address", result);
message.setData(bundle);
}
message.sendToTarget();
}
}
};
thread.start();

}
}
----------------------------------------------------------------------------------//Main Activity
package com.gescoe.showlocationmap;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
import android.media.AudioManager;
import android.provider.Settings;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
import java.io.IOException;
import java.util.List;
public class MainActivity extends Activity {
Double lat,longi;
TextView txtLoction;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtLoction = (TextView)findViewById(R.id.txtLoc);
10

GPSTracker gpsTracker=new GPSTracker(MainActivity.this);


if(gpsTracker.canGetLocation())
{
lat =gpsTracker.getLatitude();
longi=gpsTracker.getLongitude();
//txtLoction.setText("Lat :"+lat +" Longi "+longi);
Geocoder geocoder= new Geocoder(getApplicationContext());
List<Address> addressList;
try {
addressList=geocoder.getFromLocation(lat,longi,1);
if (addressList != null && addressList.size() > 0) {
Address address = addressList.get(0);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < address.getMaxAddressLineIndex(); i++) {
sb.append(address.getAddressLine(i)).append("\n");
}
sb.append(address.getLocality()).append("\n");
sb.append(address.getPostalCode()).append("\n");
sb.append(address.getCountryName());
txtLoction.setText(sb.toString());
}
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
if(lat>20 && lat<22 && longi>73 && longi<75) {
audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
}
else {
audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
}
} catch (IOException e) {
e.printStackTrace();
}
}
else
{
// Toast.makeText(getApplicationContext(),"Enable GPS",Toast.LENGTH_LONG)
.show();
AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);
dialog.setMessage("Enable GPS");
dialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface paramDialogInterface, int paramInt) {
// TODO Auto-generated method stub
Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(myIntent);
//get gps
}
});
dialog.setNegativeButton("No", new DialogInterface.OnClickListener() {

11

@Override
public void onClick(DialogInterface paramDialogInterface, int paramInt) {
// TODO Auto-generated method stub
}
});
dialog.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);
}
}

Output

12

Plagiarism Score

13

You might also like