I've foud a better solution!!!
in my mainActivity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TelephonyManager telm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
int events = PhoneStateListener.LISTEN_CELL_LOCATION;
telm.listen(phoneStateListener, events);
.....
}
private final PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onCellLocationChanged(CellLocation location) {
super.onCellLocationChanged(location);
int cid = 0;
int lac = 0;
if (location != null) {
if (location instanceof GsmCellLocation) {
cid = ((GsmCellLocation) location).getCid();
lac = ((GsmCellLocation) location).getLac();
}
else if (location instanceof CdmaCellLocation) {
cid = ((CdmaCellLocation) location).getBaseStationId();
lac = ((CdmaCellLocation) location).getSystemId();
}
}
String cellBase = Integer.toString(lac)+"-"+Integer.toString(cid);
Toast.makeText(getBaseContext(), cellBase, Toast.LENGTH_LONG).show();
Log.v("logg", "cell:"+cellBase);
final MediaPlayer mp = MediaPlayer.create(getBaseContext(), R.raw.beep);
mp.start();
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.stop();
mp.release();
}
});
}
};