Android 对于2G SIM卡,getAllCellInfo返回null
如果我在包含2G sim卡的设备中使用,它将返回null(注意:API级别:21)。我甚至尝试过它返回一个空的Android 对于2G SIM卡,getAllCellInfo返回null,android,telephonymanager,Android,Telephonymanager,如果我在包含2G sim卡的设备中使用,它将返回null(注意:API级别:21)。我甚至尝试过它返回一个空的列表 TelephonyManager TelephonyManager=(TelephonyManager)mContext.getSystemService(Context.TELEPHONY_服务); if(Build.VERSION.SDK\u INT>=Build.VERSION\u code.JELLY\u BEAN\u MR2){ List cellInfos=teleph
列表
TelephonyManager TelephonyManager=(TelephonyManager)mContext.getSystemService(Context.TELEPHONY_服务);
if(Build.VERSION.SDK\u INT>=Build.VERSION\u code.JELLY\u BEAN\u MR2){
List cellInfos=telephonyManager.getAllCellInfo();
if(cellInfos==null){
List neightringcellinfos=telephonyManager.getneightringcellinfo();
CellLocation CellLocation=telephonyManager.getCellLocation();
}
}
注意:我对清单文件中的
getAllCellInfo
具有android.permission.ACCESS\u rough\u位置所需的权限很抱歉发布了这个不合适的问题。我发现,我上面提到的问题不是因为我使用的是2G sim卡,而是因为SIM1插槽中没有sim卡。当我在3G sim卡(插槽1)和2G(插槽2)上使用此代码时,它按照我的预期工作,然后我禁用了插槽1以检查2G,我遇到了上述问题
经过一段时间的测试,我启用了SIM1并将其更改为2G,现在我得到了预期的结果。我写作是为了帮助别人。对不起我的英语 通常,我们需要查看一些代码来了解发生了什么。请准备一份报告,并将其编辑到您的问题中。
TelephonyManager telephonyManager = (TelephonyManager)mContext.getSystemService( Context.TELEPHONY_SERVICE );
if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.JELLY_BEAN_MR2) {
List<CellInfo> cellInfos = telephonyManager.getAllCellInfo();
if(cellInfos==null){
List<NeighboringCellInfo> neighboringCellInfos = telephonyManager.getNeighboringCellInfo();
CellLocation cellLocation = telephonyManager.getCellLocation();
}
}