Tuesday, February 24, 2009

How to track a GPhone

Project name : Tracker

Tracker application resides in the android phone to be tracked (B). If A sends an SMS starting with pin code (1234) to B, B replies back with the location in geo-coordinate (Longitude/Latitude) format using GPS capability of GPhone.

AndroidManifest.xml
--------------------------------------------------------------------------------------------------------------------
< ?xml version="1.0" encoding="utf-8"?>
< manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sentinelbd.stealth"
android: versionCode="1"
android: versionName="1.0.0">
< name="android.permission.SEND_SMS">
< name="android.permission.RECEIVE_SMS">
< name="android.permission.INTERNET">
< name="android.permission.ACCESS_FINE_LOCATION">
< name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS">
< icon="@drawable/icon" label="@string/app_name">
< activity android: name=".TrackerActivity"
android: label="@string/app_name">
<>
< name="android.intent.action.MAIN">
< name="android.intent.category.LAUNCHER">
< /intent-filter>
< /activity>
< enabled="true" name=".MyService">
< enabled="true" name=".LaunchIntentReceiver">
<>
< name="android.intent.action.BOOT_COMPLETED">
< name="android.intent.category.HOME">
< /intent-filter>
< /receiver>
< /application>
< /manifest>

--------------------------------------------------------------------------------------------------------------------

TrackerActivity.java
--------------------------------------------------------------------------------------------------------------------
package com.sentinelbd.stealth;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class TrackerActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
startService(new Intent(TrackerActivity.this, MyService.class));
finish();
}
}
--------------------------------------------------------------------------------------------------------------------

MyService.java
--------------------------------------------------------------------------------------------------------------------
package com.sentinelbd.stealth;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.Location;
import android.location.LocationManager;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

/**
* @author xencare1
*
*/
public class MyService extends Service
{
LocationManager locman = null;
Location loc;
String location="";
public static final String TAG = "LOQUERIO";
private MyLocationListener locationListener;
private final IBinder binder=new MyBinder();
public static final String SMS_RECEIVED ="android.provider.Telephony.SMS_RECEIVED";

@Override
public void onCreate()
{
Log.d("service","***********service creation*******************");



}

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

@Override
public void onStart(Intent intent, int startId)
{
locman = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener(this);
locman.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
Log.d("service","###############service start##################");
Receiver responder=new Receiver(locman, locationListener);;
registerReceiver(responder, new IntentFilter(SMS_RECEIVED));

//Toast.makeText(getBaseContext(), "Location changed : Lat: " + loc.getLatitude()+ " Lng: " + loc.getLongitude(), Toast.LENGTH_SHORT).show();
//SmsManager mng = SmsManager.getDefault();
//mng.sendTextMessage("5556", null, location, null, null);
}



public class MyBinder extends Binder
{
MyService getService()
{
return MyService.this;
}
}


}
--------------------------------------------------------------------------------------------------------------------
MyLocationListener.java
--------------------------------------------------------------------------------------------------------------------
package com.sentinelbd.stealth;

import android.app.Service;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class MyLocationListener implements LocationListener
{
Service s;
public static final String TAG = "SENTINEL";

public MyLocationListener(Service s)
{
this.s=s;
}

public void onLocationChanged(Location loc) {
// Called when the location has changed.
Log.d(TAG, "===>>> MinhaLocalizacaoListener onLocationChanged");
if (loc != null) {
Toast.makeText(this.s.getBaseContext(),
"Location changed : Lat: " + loc.getLatitude()
+ " Lng: " + loc.getLongitude(),
Toast.LENGTH_SHORT).show();

}
}

public void onProviderDisabled(String provider) {
// Called when the provider is disabled by the user.
Log.d(TAG, "===>>> MyLocationListener onProviderDisabled PROVIDER:"
+ provider);
// Mapa.ehPraAtualizar = false;
}

public void onProviderEnabled(String provider) {
Log.d(TAG, "===>>> MyLocationListener onProviderEnabled PROVIDER:"
+ provider);
// Called when the provider is enabled by the user.
}

public void onStatusChanged(String provider, int status, Bundle
extras) {
Log.d(TAG, "===>>> MyLocationListener onStatusChanged STATUS:"
+ status + " PROVIDER:" + provider);
// Called when the provider status changes.
}
}
--------------------------------------------------------------------------------------------------------------------

LaunchIntentReceiver.java
--------------------------------------------------------------------------------------------------------------------
package com.sentinelbd.stealth;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class LaunchIntentReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Intent launch=new Intent(context,TrackerActivity.class);
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(launch);
}

}
--------------------------------------------------------------------------------------------------------------------