Null Issue with NeighboringCellInfo, CID and LAC

For a while I tried to get CellID and LAC of nearby base stations. Unfortunately, I did not succeed. First option:

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 get a -1 value (as I understand it, this means that it is not GSM, but when I check with isGSM, it shows "true"). Another way I 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 simply crashes immediately after clicking the execute button. Eclipse does not show errors. Maybe someone has ideas on how to fix my problems?

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

Permissions Used:

 <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" /> 

Perhaps the problem is that I forgot to include:

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

Update I turned on the line above, the accident disappeared, but now when I press the button, nothing happens. Updated source code.

+4
java android
source share
3 answers

Have you confirmed that the correct permissions are set in your manifest file?

TelephonyManager requires a number of permissions depending on the API you are using. You need READ_PHONE_STATE for most of the APIs, in addition, the documentation for getNeighboringCellInfo mentions ACCESS_COARSE_UPDATES , however I think it might be a document error, and you really need ACCESS_COARSE_LOCATION , which is documented as "Allows the application to access rough (for example, Cell-ID, WiFi) location "

+3
source share

The implementation of Cellid varies from mobile device to mobile device, as these features are considered optional. eg:

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

+1
source share

There was the same problem. Try running a query for neighboring cells on a forked stream (non-UI). At least where I had the problem, this is checking hammerhead android for this and will return null, leaving log logat immediately:

 @PhoneInterfaceManager: getNeighboringCellInfo RuntimeException - This method will deadlock if called from the main thread. 
+1
source share

All Articles