2013-07-23 28 views
9

我發現了太多的代碼來獲取cell-id和位置區域代碼,我使用下面的代碼來獲取cell-id和location區域代碼。如何在Android中獲取正確的單元格ID和位置區域代碼?

TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); 
GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation(); 

int cid = cellLocation.getCid(); 
int lac = cellLocation.getLac(); 

的問題是,當我使用Airtel的SIM卡能正常工作並給小區id = 4331和LOC-610。但是當我使用relience-sim卡時,它給出錯誤的結果cell-id = 11541和loc = 18823。我該如何解決這個問題?

+0

嗨,我使用的網址http://sunil-android.blogspot.in/2013/01/convert-celllocation-to-real-location.html的代碼來獲取位置,它對Airtel工作正常,但如果可靠,它不起作用。正如我所知,這意味着我在獲得可靠信息時所獲得的位置區域代碼和單元ID不正確。任何幫助? – User10001

+0

有很多應用程序顯示正確的單元格編號,但我的代碼不適用於3g simcard。 – User10001

+0

通過使用'cid = cellLocation.getCid()&0xffff;',您的relience-sim的結果如何? – sschrass

回答

0

解決方案都強調了以下主題:Android: CellID not available on all carriers?

總之你需要從getCid()0xffff屏蔽在3G網絡中,當你得到的數量。以下是一個片段:

GsmCellLocation cellLocation = (GsmCellLocation)telm.getCellLocation(); 

new_cid = cellLocation.getCid() & 0xffff; 
new_lac = cellLocation.getLac() & 0xffff; 

希望幫助

+0

我已經試過了。 – User10001

0

小區標識和LAC IDS基於網絡是不同的,正如你剛纔提到你正在使用不同網絡的兩個不同的SIM卡,所以你會得到不同的細胞和lacid這些將不會相同。因爲一個運營商的小區ID將與其他網絡不同,因爲兩個不同的塔用於不同的網絡,並且他們已經相應地分配了兩個ID。

相關問題