4

For a while I was trying to get CellID and LAC of near base stations. Unfortunately I did not manage to do that. First option was to use:

GsmCellLocation xXx = new GsmCellLocation();  
    CID = xXx.getCid();  
    LAC = xXx.getLac();  
    Toast output = Toast.makeText(getApplicationContext(), "Base station LAC is "+LAC+"\n" 
      +"Base station CID is " +CID, Toast.LENGTH_SHORT);  
    output.show();

But in this case I receive -1 value (as I understand that means it is not a GSM, but when i check with isGSM it shows "true"). Another way I have found surfing the net (i updated it a bit)

public void GetID(){  
 List<NeighboringCellInfo>  neighCell = null; 
 TelephonyManager telManager = ( TelephonyManager )getSystemService(Context.TELEPHONY_SERVICE); 
 neighCell = telManager.getNeighboringCellInfo();  
 for (int i = 0; i < neighCell.size(); i++) {  
 try {  
   NeighboringCellInfo thisCell = neighCell.get(i);  
   int thisNeighCID = thisCell.getCid();  
   int thisNeighRSSI = thisCell.getRssi();  
   log(" "+thisNeighCID+" - "+thisNeighRSSI);  
 } catch (NumberFormatException e) {  
   e.printStackTrace();
   NeighboringCellInfo thisCell = neighCell.get(i);  
   log(neighCell.toString());  
 }  
}  
}

But in this case the application just crashes right after I press the execute button. Eclipse shows no errors. May be someone have any ideas how to fix my problems?

Logcat says: 10-05 22:53:27.923: ERROR/dalvikvm(231): Unable to open stack trace file '/data/anr/traces.txt': Permission denied

Used permissions:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" />

May be the problem is that i forgot to include:

TelephonyManager telManager = ( TelephonyManager )getSystemService(Context.TELEPHONY_SERVICE);

Update. I included row from above, crash is gone but now after I press the button nothing happens. Updated source code.

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
StalkerRus
  • 411
  • 1
  • 10
  • 20
  • Use logcat to get a stack trace for the crash. In eclipse open the logcat view, or select the DDMS perspective. – Cheryl Simon Oct 05 '10 at 22:38
  • I have a similar problem. If i have a 3G connection everything works fine, but on a 2G connection there is sometimes no cid and there are no neighbor cells. Maybe it has something to do with your connection type. – dbrettschneider Oct 06 '10 at 12:12
  • I bet this should work at least on emulator, but I receive multiple crashes (Unable to open stack trace file '/data/anr/traces.txt': Permission denied) if i try to use any methods to get CID – StalkerRus Oct 06 '10 at 12:20
  • Interesting situation, seems like i get empty neighCell list... – StalkerRus Oct 06 '10 at 13:17

3 Answers3

3

Have you verified that you have the correct permissions set in your manifest file?

The TelephonyManager requires a number of permissions depending on the API you use. You need READ_PHONE_STATE for most of the API's, in addition the documentation for getNeighboringCellInfo mentions ACCESS_COARSE_UPDATES, however I think this may be a doc mistake and you actually need ACCESS_COARSE_LOCATION which is documented as "Allows an application to access coarse (e.g., Cell-ID, WiFi) location"

Bishan
  • 15,211
  • 52
  • 164
  • 258
cistearns
  • 2,488
  • 21
  • 24
  • Just a side note. I had a similar problem with all needed permissions included. Only a device hard reset solved the problem. – Drejc Feb 22 '12 at 20:25
1

The cellid implementation varies from mobile device to mobile device since these features are considered to be optional. for example:

Samsung (all devices): getNeigbouringCells () is not supported at all and always returns an empty list.

according to this: http://wiki.opencellid.org/wiki/Android_library

Milad Faridnia
  • 9,113
  • 13
  • 65
  • 78
1

Had the same problem. Try to run the query for neighboring cells on a forked thread (non-UI). At least where I had the problem was that hammerhead android check for that and would return null immediately leaving a log in logcat:

@PhoneInterfaceManager: getNeighboringCellInfo RuntimeException - This method will deadlock if called from the main thread.
foo
  • 574
  • 8
  • 13