如何从移动网络运营商获取Android手机的当前基站位置

6
我想获取当前的基站位置地址,就像诺基亚手机在主屏幕上显示运营商名称和基站地址一样。我希望如下所示: SIM运营商名称 当前基站地址 我想在安卓设备上离线获取这些详细信息!是否有人能够给予帮助,将不胜感激!

请查看这个问题获取手机基站位置信息-Android - BBdev
@BBdev 感谢您阅读我的问题,我已经尝试过了,但它没有返回当前的塔地址! - Stack Overflow User
2个回答

0
获取Android手机当前连接的当前网络运营商名称最简单的方法是获得android.telephony.TelephonyManager并从其中获取:
TelephonyManager telephonyManager =((TelephonyManager) Context.getSystemService(Context.TELEPHONY_SERVICE));
String operatorName = telephonyManager.getNetworkOperatorName();

String simName = telephonyManager.getSimOperatorName();

字符串simName = telephonyManager.getSimOperatorName();


0

试试这个 获取单元格ID

希望对你有所帮助。

以下是从原始网址中获取的内容,以防原始页面不可用。


使用HttpGet()获取opencellid.org的Cell ID位置。 创建了一个名为OpenCellID的类来处理与opencellid.org的http通信。为了简化工作,发送了带有“fmt=txt”的请求,这样我们就可以简单地分割结果以检索我们的纬度和经度。

To know more about the project OpenCellID, refer to last post.

Get location of Cell ID, from opencellid.org using HttpGet()

We need the following permission in this example:
android.permission.ACCESS_COARSE_LOCATION
android.permission.ACCESS_FINE_LOCATION
android.permission.READ_PHONE_STATE
android.permission.INTERNET


package com.AndroidTelephonyManager;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import android.widget.TextView;

public class AndroidTelephonyManager extends Activity {

 public class OpenCellID {
  String mcc;  //Mobile Country Code
  String mnc;  //mobile network code
  String cellid; //Cell ID
  String lac;  //Location Area Code

  Boolean error;
  String strURLSent;
  String GetOpenCellID_fullresult;

  String latitude;
  String longitude;

  public Boolean isError(){
   return error;
  }

  public void setMcc(String value){
   mcc = value;
  }

  public void setMnc(String value){
   mnc = value;
  }

  public void setCallID(int value){
   cellid = String.valueOf(value);
  }

  public void setCallLac(int value){
   lac = String.valueOf(value);
  }

  public String getLocation(){
   return(latitude + " : " + longitude);
  }

  public void groupURLSent(){
   strURLSent =
    "http://www.opencellid.org/cell/get?mcc=" + mcc
    +"&mnc=" + mnc
    +"&cellid=" + cellid
    +"&lac=" + lac
    +"&fmt=txt";
  }

  public String getstrURLSent(){
   return strURLSent;
  }

  public String getGetOpenCellID_fullresult(){
   return GetOpenCellID_fullresult;
  }

  public void GetOpenCellID() throws Exception {
   groupURLSent();
   HttpClient client = new DefaultHttpClient();
   HttpGet request = new HttpGet(strURLSent);
   HttpResponse response = client.execute(request);
   GetOpenCellID_fullresult = EntityUtils.toString(response.getEntity()); 
   spliteResult();
  }

  private void spliteResult(){
   if(GetOpenCellID_fullresult.equalsIgnoreCase("err")){
    error = true;
   }else{
    error = false;
    String[] tResult = GetOpenCellID_fullresult.split(",");
    latitude = tResult[0];
    longitude = tResult[1];
   }


  }
 }

 int myLatitude, myLongitude;
 OpenCellID openCellID;


   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       TextView textGsmCellLocation = (TextView)findViewById(R.id.gsmcelllocation);
       TextView textMCC = (TextView)findViewById(R.id.mcc);
       TextView textMNC = (TextView)findViewById(R.id.mnc);
       TextView textCID = (TextView)findViewById(R.id.cid);
       TextView textLAC = (TextView)findViewById(R.id.lac);
       TextView textGeo = (TextView)findViewById(R.id.geo);
       TextView textRemark = (TextView)findViewById(R.id.remark);

       //retrieve a reference to an instance of TelephonyManager
       TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
       GsmCellLocation cellLocation = (GsmCellLocation)telephonyManager.getCellLocation();

       String networkOperator = telephonyManager.getNetworkOperator();
       String mcc = networkOperator.substring(0, 3);
       String mnc = networkOperator.substring(3);
       textMCC.setText("mcc: " + mcc);
       textMNC.setText("mnc: " + mnc);

       int cid = cellLocation.getCid();
       int lac = cellLocation.getLac();
       textGsmCellLocation.setText(cellLocation.toString());
       textCID.setText("gsm cell id: " + String.valueOf(cid));
       textLAC.setText("gsm location area code: " + String.valueOf(lac));

       openCellID = new OpenCellID();

       openCellID.setMcc(mcc);
       openCellID.setMnc(mnc);
       openCellID.setCallID(cid);
       openCellID.setCallLac(lac);
       try {
   openCellID.GetOpenCellID();

   if(!openCellID.isError()){
    textGeo.setText(openCellID.getLocation());
    textRemark.setText( "\n\n"
      + "URL sent: \n" + openCellID.getstrURLSent() + "\n\n"
      + "response: \n" + openCellID.GetOpenCellID_fullresult);
   }else{
    textGeo.setText("Error");
   }
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
   textGeo.setText("Exception: " + e.toString());
  }
   }   
}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   >
<TextView 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="@string/hello"
   />
<TextView 
   android:id="@+id/gsmcelllocation"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   />
<TextView 
   android:id="@+id/mcc"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   />
<TextView 
   android:id="@+id/mnc"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   />
<TextView 
   android:id="@+id/cid"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   />
<TextView 
   android:id="@+id/lac"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   />
<TextView 
   android:id="@+id/geo"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   />
<TextView 
   android:id="@+id/remark"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   />
</LinearLayout>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接