2010-10-05 25 views
4

有一段時間我試圖獲得CellID和LAC的近基站。不幸的是,我沒有設法做到這一點。第一個選項是使用:Null問題與NeighboringCellInfo,CID和LAC

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(); 

但在這種情況下,我收到-1值(按照我的理解,這意味着它不是GSM,但是當我用isGSM檢查顯示「真」)。 我發現在網上衝浪的另一種方法(我更新了一點)

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()); 
} 
} 
} 

但在這種情況下,應用程序只是崩潰之後我按執行按鈕。 Eclipse顯示沒有錯誤。可能有人有任何想法如何解決我的問題?

logcat的說:10-05 22:53:27.923:ERROR/dalvikvm(231):無法打開 堆棧跟蹤文件 '/data/anr/traces.txt':權限被拒絕

二手權限:

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

可能的問題是,我忘了,包括:

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

更新。我包括上面的行,崩潰消失了,但現在按下按鈕後沒有任何反應。 更新的源代碼。

+0

使用的logcat以獲取崩潰堆棧跟蹤。在eclipse中打開logcat視圖,或選擇DDMS透視圖。 – 2010-10-05 22:38:13

+0

我有類似的問題。如果我有3G連接一切正常,但在2G連接有時沒有cid,並且沒有鄰居單元。也許它與你的連接類型有關。 – dbrettschneider 2010-10-06 12:12:14

+0

我敢打賭,這應該至少在模擬器上工作,但我收到多個崩潰(無法打開堆棧跟蹤文件'/data/anr/traces.txt':權限被拒絕)如果我嘗試使用任何方法獲取CID – StalkerRus 2010-10-06 12:20:59

回答

3

您是否驗證過您在清單文件中設置了正確的權限?

根據您使用的API,TelephonyManager需要許多權限。你需要READ_PHONE_STATE大部分的API,另外getNeighboringCellInfo提到的文檔ACCESS_COARSE_UPDATES,但我認爲這可能是一個文檔錯誤,你實際上需要ACCESS_COARSE_LOCATION,它被記錄爲「允許應用程序粗略訪問(例如,小區ID, WiFi)位置「

+0

我檢查了我的清單,一切都包含在內 – StalkerRus 2010-10-06 08:39:41

+0

只是一個側面說明。我有一個類似的問題,包括所有需要的權限。只有設備硬重置才能解決問題。 – Drejc 2012-02-22 20:25:57

1

cellid的實現因移動設備而異,因爲這些功能被認爲是可選的。例如:

Samsung(所有設備):getNeigbouringCells()根本不被支持,並且總是返回一個空列表。

根據該: http://wiki.opencellid.org/wiki/Android_library

1

有同樣的問題。嘗試在分叉線程(非UI)上運行相鄰單元的查詢。 至少在我的問題是,Android的雙髻鯊檢查爲,並會返回null立即離開日誌中的logcat:

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