This is my code:
@Override
public void onCreate() {
super.onCreate();
//Log.i("TAG", "ovdje smo");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("alo", "bre");
telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
cellLocation = (GsmCellLocation) telephonyManager.getCellLocation();
oldCellID = cellLocation.getCid();
while( true ){
Log.i("jesmo li tu",""+oldCellID);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
Toast.makeText(this, "Kupimo cell ID OLD" + oldCellID, Toast.LENGTH_SHORT).show();
telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
cellLocation = (GsmCellLocation) telephonyManager.getCellLocation();
newCellID = cellLocation.getCid();
if(oldCellID != newCellID){
//TODO uzmi lokaciju + spremi u bazu
Log.i("usli u petlju", "DA"+newCellID + oldCellID);
Toast.makeText(this, "Stari id ->" + oldCellID + " noviCellID -> " + newCellID, Toast.LENGTH_SHORT).show();
oldCellID = newCellID;
telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
cellLocation = (GsmCellLocation) telephonyManager.getCellLocation();
newCellID = cellLocation.getCid();
}
}
It looks good in Log, but app doesn't response. It looks like this: App doesn't respond I'm new at android, Can I use something else, listener ?? I want to track when my CellID change value and then get current location.