Created
July 25, 2013 13:44
-
-
Save hj91/6079767 to your computer and use it in GitHub Desktop.
Code for printing Cell Tower information for non GPS phones.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* @author=harshad joshi */ | |
package com.harshad.cellinfo2; | |
import android.os.Bundle; | |
import android.app.Activity; | |
import android.view.Menu; | |
import java.util.List; | |
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.content.Intent; | |
import android.net.Uri; | |
import android.os.Bundle; | |
import android.telephony.NeighboringCellInfo; | |
import android.telephony.TelephonyManager; | |
import android.telephony.gsm.GsmCellLocation; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.SeekBar; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
public class AndroidTelephonyManager extends Activity { | |
/** 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); | |
//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)); | |
TextView Neighboring = (TextView)findViewById(R.id.neighboring); | |
List<NeighboringCellInfo> NeighboringList = telephonyManager.getNeighboringCellInfo(); | |
String stringNeighboring = "Neighboring List- Lac : Cid : RSSI\n"; | |
for(int i=0; i < NeighboringList.size(); i++){ | |
String dBm; | |
int rssi = NeighboringList.get(i).getRssi(); | |
if(rssi == NeighboringCellInfo.UNKNOWN_RSSI){ | |
dBm = "Unknown RSSI"; | |
}else{ | |
dBm = String.valueOf(-113 + 2 * rssi) + " dBm"; | |
} | |
stringNeighboring = stringNeighboring | |
+ String.valueOf(NeighboringList.get(i).getLac()) +" : " | |
+ String.valueOf(NeighboringList.get(i).getCid()) +" : " | |
+ dBm +"\n"; | |
} | |
Neighboring.setText(stringNeighboring); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.android_telephony_manager, menu); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment