首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >htc Android2.2获取cellID wcdma

htc Android2.2获取cellID wcdma
EN

Stack Overflow用户
提问于 2011-01-28 05:52:31
回答 1查看 923关注 0票数 0

这是我在安卓上的第一个'helloWorld‘类型的应用,也是在java中的,所以请耐心等待:)

我想在W-CDMA中获取小区ID,所以我制作了该应用程序:

代码语言:javascript
复制
    package helloWorld.w;

//package com.eepyaj.cellID;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.telephony.cdma.CdmaCellLocation;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class w extends Activity {

   CdmaCellLocation location;
   int cellID, lac;
   private Context context;

   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      context = (Context) this;
      TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
      location = (CdmaCellLocation) tm.getCellLocation();
      cellID = location.getBaseStationId();

      String tx;
      tx = String.valueOf(cellID);
      TextView tv = new TextView(this);
      tv.setText("Cell ID " + tx);
      setContentView(tv);

   }
}

遗憾的是,应用程序退出时会显示以下消息:

“应用程序helloWorld (进程helloWorld.w)已意外停止。请重试”(在HTC和模拟器上)

我在eclpise下制作了这个应用程序,典型的“hello World”工作(在htc和模拟器上),所以我认为问题在于获得那个“cellID”。

如有任何帮助,请提前向您咨询

EN

回答 1

Stack Overflow用户

发布于 2014-10-18 00:17:47

您可以使用CellIdentityWcdma

代码语言:javascript
复制
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
for (CellInfo cellInfo : tm.getAllCellInfo()) {
    if (cellInfo instanceof CellInfoWcdma) 
        cid = ((CellInfoWcdma) cellInfo).getCellIdentity().getCid();
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4822338

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档