Android的API列表< cellinfo> [英] Android API List<cellinfo>

查看:400
本文介绍了Android的API列表< cellinfo>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得的CellInfo数据,但cellinfo.size()总是会发生  该NullPointerException异常的模拟器。

CellInfo链接

我不知道该异常的情况下,任何人都知道的原因?

无论我写了错误的code?或任何人遇到了同样的异常?

  TelephonyManager TM =(TelephonyManager)本
            .getSystemService(Context.TELEPHONY_SERVICE);
    名单< CellInfo> cellinfo = TM.getAllCellInfo();
    Log.d(AA,Integer.toString(cellinfo.size()));
 

解决方案

TelephonyManager.getAllCellInfo()在API级别17加入,这样你就可以在API级别使用17 +。

此外,您必须添加 ACCESS_COARSE_LOCATION 许可,您的清单文件:

  

返回 CellInfo的
列表或NULL,如果信息不可用。   
要求   许可:ACCESS_COARSE_LOCATION

<一个href="http://developer.android.com/reference/android/telephony/TelephonyManager.html#getAllCellInfo%28%29"相对=nofollow>请参见文档

I would like to get the CellInfo data, but the cellinfo.size() always occur the NullPointerException in Emulator.

CellInfo Link

I am not sure the exception situation, anyone know the reason?

Whether I wrote the wrong code? or anyone met the same exception?

    TelephonyManager TM = (TelephonyManager) this
            .getSystemService(Context.TELEPHONY_SERVICE);
    List<CellInfo> cellinfo = TM.getAllCellInfo();
    Log.d("AA",Integer.toString(cellinfo.size()));

解决方案

TelephonyManager.getAllCellInfo() is added in API level 17, so you can use it on Api Level 17 and +.

Also you must add ACCESS_COARSE_LOCATION permission to your manifest file:

Returns
List of CellInfo or null if info unavailable.
Requires Permission: ACCESS_COARSE_LOCATION

See Docs

这篇关于Android的API列表&LT; cellinfo&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆