Wednesday 27 June 2012

Services in andriod


public class Myserviceclass extends Service {
private static final String TAG = "MyService";

double d;
public String mPhoneNumber, loc, unicode, datalatitute, datalognitute,
dataunicode, datatiming, timming, ourNumber, sDeviceID, phnno,
mint, hr, sec, Answer_id;
int Dataid, countQuestion = 1, second = 0, minute = 0, hours = 0,
delay = 0, quesno = 2;
double latitude, longitude, datalognitute1, datalatitute1;
// ParsingN pn;
Timer t;

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

@Override
public void onCreate() {

Log.d(TAG, "onCreate");
}
// Start method is call.................Every time when service is run in back ground
@Override
public void onDestroy() {
Log.d(TAG, "onDestroy");
}

@Override
public void onStart(Intent intent, int startid) {

Log.d(TAG, "onStart");



LocationManager locationmanager = (LocationManager)                     getSystemService(Context.LOCATION_SERVICE);
Location location2 = locationmanager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
Log.i("ccc", "" + location2);
Location location1 = locationmanager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location1 != null) {
latitude = location1.getLatitude();
longitude = location1.getLongitude();
Log.d("testing1111", "" + latitude + "kkk" + longitude);
loc = "" + longitude + "+" + "" + latitude;
} else {
Log.d("testing1111", "testing fail");
}

Toast.makeText(getApplicationContext(), "" + loc, 20000).show();
// //////// GETTING UNIQUE CODE AND PHONE NO FROM WEBSERVICE
if (Geocoder.isPresent()) {
/*Getparsing obj = new Getparsing(
"http://192.168.3.24/phpnewebservice/phonewebservice.php?user=1");*/
Getparsing obj = new Getparsing(
"http://192.168.3.24/phpnewebservice/phonewebservice.php?user=1");
Log.i("kkkk", "" + Geocoder.isPresent());
} else {
Toast.makeText(getApplicationContext(), "wait......",
Toast.LENGTH_LONG).show();
}
Log.i("karan11", "soni");
Log.i("karan222", "soni");
SitesList sitesList = new SitesList();
sitesList = MyXMLHandler.sitesList;
Log.i("size", "" + sitesList.getPhn_ID().size());
for (int i = 0; i < sitesList.getPhn_no().size(); i++) {
Log.i("getting no", "" + sitesList.getPhn_no().get(i));
}
for (int i = 0; i < sitesList.getPhn_ID().size(); i++) {
Log.i("getting id", "" + sitesList.getPhn_ID().get(i));
}
for (int i = 0; i < sitesList.getCode().size(); i++) {
Log.i("getting c", "" + sitesList.getCode().get(i));
}
TelephonyManager mTelephonyMgr = (TelephonyManager) this
.getSystemService(Context.TELEPHONY_SERVICE);
ourNumber = mTelephonyMgr.getLine1Number();
sDeviceID = mTelephonyMgr.getDeviceId();
int N = sitesList.getPhn_no().indexOf(ourNumber);
int PID = sitesList.getPhn_ID().indexOf(sDeviceID);
unicode = sitesList.getCode().get(PID);
Log.i("NN", "" + N);
Log.i("unicode", "" + unicode);
if (Geocoder.isPresent()) {

Log.i("kkkk", "" + Geocoder.isPresent());
}
if (!Geocoder.isPresent()) {

Log.i("kkkk", "" + Geocoder.isPresent());

}
}


}

No comments:

Post a Comment