这是我在安卓上的第一个'helloWorld‘类型的应用,也是在java中的,所以请耐心等待:)
我想在W-CDMA中获取小区ID,所以我制作了该应用程序:
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”。
如有任何帮助,请提前向您咨询
发布于 2014-10-18 00:17:47
您可以使用CellIdentityWcdma
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
for (CellInfo cellInfo : tm.getAllCellInfo()) {
if (cellInfo instanceof CellInfoWcdma)
cid = ((CellInfoWcdma) cellInfo).getCellIdentity().getCid();
}https://stackoverflow.com/questions/4822338
复制相似问题