这是我的代码,我无法获得cellid和Lac值的值。这是我的代码,
public class lac extends Activity {
private int mCid ;
private int mLac ;
GsmCellLocation location;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TelephonyManager tel=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
location = (GsmCellLocation) tel.getCellLocation();
mLac=location.getLac();
mCid=location.getCid();
Toast.makeText(getApplicationContext(),"LAC="+mLac+"CellId="+mCid+type,Toast.LENGTH_LONG).show();
}
}
当我运行模拟器时,它表示应用程序意外停止运行。我使用了权限(ACCESS_COARSE_LOCATION),(ACCESS_FINE_LOCATION)
。
答案 0 :(得分:0)
mLac=location.getLac();
我确定这会返回null(-1)而你得NullPointerException
,因为你的gsm location area code is unknown
,尝试在你的设备上运行它而不是模拟器。