问题描述
有一段时间我试图让附近基站的CellID和LAC。遗憾的是我没能做到这一点。第一种选择是使用:
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();
但在这种情况下,我收到值-1(据我所知,这意味着它不是GSM,但是当我检查与isGSM显示真)。另一种方式,我发现网上冲浪(我更新了一点)
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());
}
}
}
但是,在这种情况下,应用程序只是崩溃之后我preSS执行按钮。蚀示出没有错误。可能有人有任何想法如何解决我的问题呢?
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中说: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" />
可能的问题是,我忘了,包括:
May be the problem is that i forgot to include:
TelephonyManager telManager = ( TelephonyManager )getSystemService(Context.TELEPHONY_SERVICE);
更新。我包括从上面排,撞车走了,但现在经过我preSS按钮没有任何反应。更新的源$ C $ C。
Update. I included row from above, crash is gone but now after I press the button nothing happens.Updated source code.
推荐答案
您是否已经验证,你必须在你的清单文件设置正确的权限?
Have you verified that you have the correct permissions set in your manifest file?
在 TelephonyManager
需要许多具体取决于所使用的API的权限。您需要 READ_PHONE_STATE
对于大多数的API,除了为文档 getNeighboringCellInfo
提到 ACCESS_COARSE_UPDATES
,但是我觉得这可能是一个文档的错误,你真正需要 ACCESS_COARSE_LOCATION
被记录为允许应用程序访问粗(例如,小区ID,无线网络)的位置
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"
这篇关于空问题NeighboringCellInfo,CID和LAC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!