i'm using the following function to get Allcellinfo of an device network and im getting the values as an string now i need to parse it in order to get the CellSignalStrengthLte data how can i achieve it
//code
TelephonyManager tm = (TelephonyManager) Context.getSystemService(mContext.TELEPHONY_SERVICE);
List<CellInfo> cellInfos = tm.getAllCellInfo();
String data = cellInfos.get(0).toString();
Log.d("Info ", " "+data);
Result is
CellInfoLte:{mRegistered=YES mTimeStampType=oem_ril mTimeStamp=207387894126206ns CellIdentityLte:{ mMcc=405 mMnc=869 mCi=2971664 mPci=123 mTac=56} CellSignalStrengthLte: ss=25 rsrp=-91 rsrq=-7 rssnr=2147483647 cqi=2147483647 ta=2147483647}
How can parse this string to get details regaridng CellinfoLte,CellIdentityLte
I also noticed that CellinfoLTE and CellIdentityLTE is not so great at the moment, so I just wrote my own parsing class. Only tested this a few times, and didn't have problems, but more testing should display if additional future tweaking will be necessary.
Here's the class:
public class LTEStruct
{
public static final int UNKNOWN = Integer.MAX_VALUE; //Default value for unknown fields
public boolean isRegistered;
public long timeStamp;
public int MCC;
public int MNC;
public int CID;
public int PCI;
public int TAC;
public int SS;
public int RSRP;
public int RSRQ;
public int RSSNR;
public int CQI;
public int tAdvance;
Context mContext;
//Public constructor
public LTEStruct(Context context)
{
mContext = context; //not used at the moment but possibly for future function
}
public void parse(String inTest)
{
//get isRegistered
int index = inTest.indexOf("mRegistered=") + ("mRegistered=").length();
if(inTest.substring(index,index + 3).contains("YES"))
isRegistered = true;
else
isRegistered = false;
//getTimestamp
timeStamp = getValue(inTest,"mTimeStamp=", "ns");
//get Cell Identity paramters
MCC = (int) getValue(inTest,"mMcc=", " "); //get Mcc
MNC = (int) getValue(inTest,"mMnc=", " "); //get MNC
CID = (int) getValue(inTest,"mCi=", " "); //get CID
PCI = (int) getValue(inTest,"mPci="," "); //get PCI
TAC = (int) getValue(inTest,"mTac=","}"); //get TAC
//get RF related parameters
SS = (int) getValue(inTest," ss="," "); //get SS
RSRP = (int)getValue(inTest,"rsrp=", " "); //get RSRP
RSRQ = (int)getValue(inTest,"rsrq=", " "); //get RSRQ
RSSNR = (int)getValue(inTest,"rssnr=", " "); //get RSSNR
CQI = (int)getValue(inTest," cqi=", " "); //get CQI
tAdvance = (int)getValue(inTest," ta=", "}"); //get timing advance
}
//internal function to help with parsing of raw LTE strings
private long getValue(String fullS, String startS, String stopS)
{
int index = fullS.indexOf(startS) + (startS).length();
int endIndex = fullS.indexOf(stopS,index);
return Long.parseLong(fullS.substring(index,endIndex).trim());
}
}
So if I implement this very basically with the input LTE string:
//permission check
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
ActivityCompat.requestPermissions((Activity)this,new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},1);
//get cell info
TelephonyManager tel = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
List<CellInfo> infos = tel.getAllCellInfo();
for (int i = 0; i<infos.size(); ++i)
{
try
{
CellInfo info = infos.get(i);
if (info instanceof CellInfoLte) {
LTEStruct lte = new LTEStruct(this);
lte.parse(info.toString());
//write out parsed results for what it's worth
Log.i("LTE parseOutput", "tAdvance: " + lte.tAdvance + "\r\nCQI: " + lte.CQI + "\r\nRSSNR: " + lte.RSSNR + "\r\nRSRP: " + lte.RSRP + "\r\nSS: " + lte.SS +
"\r\nCID: " + lte.CID + "\r\nTimestamp: " + lte.timeStamp + "\r\nTAC: " + lte.TAC + "\r\nPCI: " + lte.PCI + "\r\nMNC: " + lte.MNC + "\r\nMCC: " + lte.MCC + "\r\nRegistered: " + lte.isRegistered);
} else
Log.i("LTE testing", "not LTE cell info measured");
} catch (Exception ex) {
Log.i("neighboring error: ", ex.getMessage());
}
}
Hope it helps ;)
Related
I'm facing an issue with getAllCellInfo().
App has permissions needed :
here is my code :
1- listener
private PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
#TargetApi(Build.VERSION_CODES.M)
#Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
super.onSignalStrengthsChanged(signalStrength);
2- Info from SignalStrength
TextView comparisonText = (TextView) findViewById(R.id.textViewComparison);
Object ssFieldValueRsrp = null;
Object ssFieldValueRsrq = null;
Object ssFieldValueRssnr = null;
Object ssFieldValueCqi=null;
try {
Field privateStringSsFieldRSRQ = SignalStrength.class.getDeclaredField("mLteRsrq");
Field privateStringSsFieldRSRP = SignalStrength.class.getDeclaredField("mLteRsrp");
Field privateStringSsFieldRssnr = SignalStrength.class.getDeclaredField("mLteRssnr");
Field privateStringSsFieldCqi = SignalStrength.class.getDeclaredField("mLteCqi");
privateStringSsFieldRSRQ.setAccessible(true);
ssFieldValueRsrq = privateStringSsFieldRSRQ.get(signalStrength);
privateStringSsFieldRSRP.setAccessible(true);
ssFieldValueRsrp = privateStringSsFieldRSRP.get(signalStrength);
privateStringSsFieldRssnr.setAccessible(true);
ssFieldValueRssnr = privateStringSsFieldRssnr.get(signalStrength);
privateStringSsFieldCqi.setAccessible(true);
ssFieldValueCqi = privateStringSsFieldCqi.get(signalStrength);
} catch (NoSuchFieldException ex) {
} catch (IllegalAccessException x) {
}
String ssRsrp = Integer.toString((int) ssFieldValueRsrp);
String ssRsrq = Integer.toString((int) ssFieldValueRsrq);
String ssRssnr = Integer.toString((int) ssFieldValueRssnr);
String ssCqi = Integer.toString((int) ssFieldValueCqi);
String headerString = "Info from \"SignalStrength\":";
SpannableString spannableHeaderString = new SpannableString(headerString);
spannableHeaderString.setSpan(new UnderlineSpan(), 0, spannableHeaderString.length(), 0);
comparisonText.setText(spannableHeaderString);
comparisonText.append
(
"\nRSRP: " + ssRsrp
+ "\nRSRQ: " + ssRsrq
+"\nCQI: "+ ssCqi
+"\nRSSNR: "+ ssRssnr
);
3- Info from CellSignalStrengthLte
Location loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
List<android.telephony.CellInfo> infor = tm.getAllCellInfo();
for (android.telephony.CellInfo info : infor)
{
if (info instanceof CellInfoLte)
{
CellSignalStrengthLte ss = ((CellInfoLte) info).getCellSignalStrength();
//theButton.setText( ss.toString());
Object fieldValueRSRP = null;
Object fieldValueRSRQ = null;
Object fieldValueRssnr = null;
Object fieldValueCqi=null;
try
{
Field privateStringFieldRSRQ = CellSignalStrengthLte.class.getDeclaredField("mRsrq");
Field privateStringFieldRSRP = CellSignalStrengthLte.class.getDeclaredField("mRsrp");
Field privateStringFieldCqi = CellSignalStrengthLte.class.getDeclaredField("mCqi");
Field privateStringFieldRSSNR = CellSignalStrengthLte.class.getDeclaredField("mRssnr");
privateStringFieldRSRQ.setAccessible(true);
fieldValueRSRQ = privateStringFieldRSRQ.get(ss);
privateStringFieldRSRP.setAccessible(true);
fieldValueRSRP = privateStringFieldRSRP.get(ss);
privateStringFieldRSSNR.setAccessible(true);
fieldValueRssnr = privateStringFieldRSSNR.get(ss);
privateStringFieldCqi.setAccessible(true);
fieldValueCqi = privateStringFieldCqi.get(ss);
}
catch (NoSuchFieldException ex) {}
catch (IllegalAccessException x) {}
String rsrp = Integer.toString((int) fieldValueRSRP);
String rsrq = Integer.toString((int) fieldValueRSRQ);
String rssnr = Integer.toString((int) fieldValueRssnr);
String cqi = Integer.toString((int) fieldValueCqi);
headerString = "Info from \"CellSignalStrengthLte\":";
spannableHeaderString = new SpannableString(headerString);
spannableHeaderString.setSpan( new UnderlineSpan(), 0, spannableHeaderString.length(), 0);
theText.setText
(
"\nAltitude: " + loc.getAltitude() + "\n\n"+loc.getLongitude()+"\n\n"+loc.getLatitude()+"\n\n"
);
theText.append(spannableHeaderString);
theText.append
(
"\nRSRP: " + rsrp
+ "\nRSRQ: " + rsrq
+ "\nCQI: " + cqi
+ "\nRSSNR: " + rssnr
);
}
}
Huawei Y6II : marshmallow (android 6) :
App run smoothly but function skipped
Huawei Nova3i (android 9)
app crashes with null pointer on List<android.telephony.CellInfo> infor = tm.getAllCellInfo();
Samsun S10 (android 9)
app running perfectly
Resolved :
This issue is related to some dual SIM phones
How do i can read data from received mms.
I receive an mms but I can't take any data from it to save it
public class MmsReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
String type = intent.getType();
Utils.PrintInfo("Action : "+action+", Type : "+type);
Bundle bundle = intent.getExtras();
Utils.PrintDebug("bundle " + bundle);
if (bundle != null) {
for(String k:bundle.keySet()) {
Utils.PrintInfo(k);
}
byte[] buffer = bundle.getByteArray("data");
Utils.PrintDebug("buffer " + buffer);
String incomingNumber = new String(buffer);
int indx = incomingNumber.indexOf("/TYPE");
if (indx > 0 && (indx - 15) > 0) {
int newIndx = indx - 15;
incomingNumber = incomingNumber.substring(newIndx, indx);
indx = incomingNumber.indexOf("+");
if (indx > 0) {
incomingNumber = incomingNumber.substring(indx);
Utils.PrintDebug("Mobile Number: " + incomingNumber);
}
}
int transactionId = bundle.getInt("transactionId");
Utils.PrintDebug("transactionId " + transactionId);
int pduType = bundle.getInt("pduType");
Utils.PrintDebug("pduType " + pduType);
byte[] buffer2 = bundle.getByteArray("header");
String header = new String(buffer2);
Utils.PrintDebug("header " + header);
}
}
}
data from that mms looks like
data : ???1351504361#mms2??????+48668822862/TYPE=PLMN???????????????http://mmsc.play.pl/?id=1351504361B??
how can I get any image from it? - i have send image from other device to that one
I've been looking around and unfortunately the android ibeacon library has been deprecated, so I am attempting to do this native. I have implemented the BluetoothAdapter.LeScanCallback and the built in onLeScan() method that will fire when a device is picked up. I would like to read in that device's ProximityUUID, major and minor characteristics and identifier. I'm not sure how to get that information out of the Android object BluetoothDevice.
How do I extract that information (ProximityUUID, major, minor, & identifier characteristics) from the Android BluetoothDevice, or is there another way to do it?
Thanks!
you can refer this post to fully understand what those bytes means in LeScanCallback .
And this is my code to parse all information needed:
// an object with all information embedded from LeScanCallback data
public class ScannedBleDevice implements Serializable {
// public BluetoothDevice BLEDevice;
/**
* Returns the hardware address of this BluetoothDevice.
* <p>
* For example, "00:11:22:AA:BB:CC".
*
* #return Bluetooth hardware address as string
*/
public String MacAddress;
public String DeviceName;
public double RSSI;
public double Distance;
public byte[] CompanyId;
public byte[] IbeaconProximityUUID;
public byte[] Major;
public byte[] Minor;
public byte Tx;
public long ScannedTime;
}
// use this method to parse those bytes and turn to an object which defined proceeding.
// the uuidMatcher works as a UUID filter, put null if you want parse any BLE advertising data around.
private ScannedBleDevice ParseRawScanRecord(BluetoothDevice device,
int rssi, byte[] advertisedData, byte[] uuidMatcher) {
try {
ScannedBleDevice parsedObj = new ScannedBleDevice();
// parsedObj.BLEDevice = device;
parsedObj.DeviceName = device.getName();
parsedObj.MacAddress = device.getAddress();
parsedObj.RSSI = rssi;
List<UUID> uuids = new ArrayList<UUID>();
int skippedByteCount = advertisedData[0];
int magicStartIndex = skippedByteCount + 1;
int magicEndIndex = magicStartIndex
+ advertisedData[magicStartIndex] + 1;
ArrayList<Byte> magic = new ArrayList<Byte>();
for (int i = magicStartIndex; i < magicEndIndex; i++) {
magic.add(advertisedData[i]);
}
byte[] companyId = new byte[2];
companyId[0] = magic.get(2);
companyId[1] = magic.get(3);
parsedObj.CompanyId = companyId;
byte[] ibeaconProximityUUID = new byte[16];
for (int i = 0; i < 16; i++) {
ibeaconProximityUUID[i] = magic.get(i + 6);
}
if (uuidMatcher != null) {
if (ibeaconProximityUUID.length != uuidMatcher.length) {
Log.e(LOG_TAG,
"Scanned UUID: "
+ Util.BytesToHexString(
ibeaconProximityUUID, " ")
+ " filtered by UUID Matcher "
+ Util.BytesToHexString(uuidMatcher, " ")
+ " with length requirment.");
return null;
}
for (int i = 0; i < 16; i++) {
if (ibeaconProximityUUID[i] != uuidMatcher[i]) {
Log.e(LOG_TAG,
"Scanned UUID: "
+ Util.BytesToHexString(
ibeaconProximityUUID, " ")
+ " filtered by UUID Matcher "
+ Util.BytesToHexString(uuidMatcher,
" "));
return null;
}
}
}
parsedObj.IbeaconProximityUUID = ibeaconProximityUUID;
byte[] major = new byte[2];
major[0] = magic.get(22);
major[1] = magic.get(23);
parsedObj.Major = major;
byte[] minor = new byte[2];
minor[0] = magic.get(24);
minor[1] = magic.get(25);
parsedObj.Minor = minor;
byte tx = 0;
tx = magic.get(26);
parsedObj.Tx = tx;
parsedObj.ScannedTime = new Date().getTime();
return parsedObj;
} catch (Exception ex) {
Log.e(LOG_TAG, "skip one unknow format data...");
// Log.e(LOG_TAG,
// "Exception in ParseRawScanRecord with advertisedData: "
// + Util.BytesToHexString(advertisedData, " ")
// + ", detail: " + ex.getMessage());
return null;
}
}
Payloads of advertising packets should be parsed as a list of AD structures.
iBeacon is a kind of AD structures.
See "iBeacon as a kind of AD structures" for details. Also, see an answer to a similar question.
Does someone know how to get gsm information in android? Information like BCCH (Broadcast Control Channel) and BCIS (Base Station Identity Code). I already got the LAC (Location Area Code) and CID (Cell ID). I know that is a low level information but does someone know to get those information? I am having a hard time researching and i don't have an idea about cellular network. Please Help thanks :)
Here is function which gives you complete information of gsm network.
just Call with context from your activity
private void getNWInfo(Context context) {
/**
* <uses-permission android:name="android.permission.READ_PHONE_STATE"
* /> <uses-permission
* android:name="android.permission.ACCESS_NETWORK_STATE"/>
*/
TelephonyManager telephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
String networkOperator = telephonyManager.getNetworkOperator();
int mcc = 0, mnc = 0;
if (networkOperator != null) {
mcc = Integer.parseInt(networkOperator.substring(0, 3));
mnc = Integer.parseInt(networkOperator.substring(3));
}
String SimNumber = telephonyManager.getLine1Number();
String SimSerialNumber = telephonyManager.getSimSerialNumber();
String countryISO = telephonyManager.getSimCountryIso();
String operatorName = telephonyManager.getSimOperatorName();
String operator = telephonyManager.getSimOperator();
int simState = telephonyManager.getSimState();
String voicemailNumer = telephonyManager.getVoiceMailNumber();
String voicemailAlphaTag = telephonyManager.getVoiceMailAlphaTag();
// Getting connected network iso country code
String networkCountry = telephonyManager.getNetworkCountryIso();
// Getting the connected network operator ID
String networkOperatorId = telephonyManager.getNetworkOperator();
// Getting the connected network operator name
String networkName = telephonyManager.getNetworkOperatorName();
int networkType = telephonyManager.getNetworkType();
String network = "";
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
try {
if (cm.getActiveNetworkInfo().getTypeName().equals("MOBILE"))
network = "Cell Network/3G";
else if (cm.getActiveNetworkInfo().getTypeName().equals("WIFI"))
network = "WiFi";
else
network = "N/A";
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText("network :" + network +
"\n" + "countryISO : " + countryISO + "\n" + "operatorName : "
+ operatorName + "\n" + "operator : " + operator + "\n"
+ "simState :" + simState + "\n" + "Sim Serial Number : "
+ SimSerialNumber + "\n" + "Sim Number : " + SimNumber + "\n"
+ "Voice Mail Numer" + voicemailNumer + "\n"
+ "Voice Mail Alpha Tag" + voicemailAlphaTag + "\n"
+ "Sim State" + simState + "\n" + "Mobile Country Code MCC : "
+ mcc + "\n" + "Mobile Network Code MNC : " + mnc + "\n"
+ "Network Country : " + networkCountry + "\n"
+ "Network OperatorId : " + networkOperatorId + "\n"
+ "Network Name : " + networkName + "\n" + "Network Type : "
+ networkType);
}
you can find more details on this blog
http://khurramitdeveloper.blogspot.in/search?updated-max=2013-11-07T03:23:00-08:00&max-results=7
hope it will help you :)
Please visit here. It explains that no APIs are available to get the Radio Information.
You can try this:
public static JSONArray getCellInfo(Context ctx){
TelephonyManager tel = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
JSONArray cellList = new JSONArray();
int phoneTypeInt = tel.getPhoneType();
String phoneType = "unknown";
if (phoneTypeInt == TelephonyManager.PHONE_TYPE_GSM)
phoneType = "gsm";
else if (phoneTypeInt == TelephonyManager.PHONE_TYPE_CDMA)
phoneType = "cdma";
//from Android M up must use getAllCellInfo
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
List<NeighboringCellInfo> neighCells = tel.getNeighboringCellInfo();
for (int i = 0; i < neighCells.size(); i++) {
try {
JSONObject cellObj = new JSONObject();
NeighboringCellInfo thisCell = neighCells.get(i);
cellObj.put("cellId", thisCell.getCid());
cellObj.put("lac", thisCell.getLac());
cellObj.put("rssi", thisCell.getRssi());
cellList.put(cellObj);
} catch (Exception e) {
}
}
} else {
List<CellInfo> infos = tel.getAllCellInfo();
for (int i = 0; i < infos.size(); ++i) {
try {
JSONObject cellObj = new JSONObject();
CellInfo info = infos.get(i);
if (info instanceof CellInfoGsm) {
CellSignalStrengthGsm gsm = ((CellInfoGsm) info).getCellSignalStrength();
CellIdentityGsm identityGsm = ((CellInfoGsm) info).getCellIdentity();
cellObj.put("cellId", identityGsm.getCid());
cellObj.put("lac", identityGsm.getLac());
cellObj.put("dbm", gsm.getDbm());
cellList.put(cellObj);
} else if (info instanceof CellInfoLte) {
CellSignalStrengthLte lte = ((CellInfoLte) info).getCellSignalStrength();
CellIdentityLte identityLte = ((CellInfoLte) info).getCellIdentity();
cellObj.put("cellId", identityLte.getCi());
cellObj.put("tac", identityLte.getTac());
cellObj.put("dbm", lte.getDbm());
cellList.put(cellObj);
}
} catch (Exception ex) {
}
}
}
return cellList;
}
I'm currently working on project viewer application parameters 2G and 3G.
I want to show rxqual and rx level, and when the network is detected on the 3G network, and Rx Level rxQual will turn into Ec/N0 and RSSI, but I get the problem, I use
getnetworktype () combined with networktype = getNetworkTypeString (tm.getNetworkType () );
but do not want to change the network type corresponding tissue obtained, so RxQual and RxLev not turn into Ec/N0 and RSSI, please check my code if something is missing or wrong ..
This is my code:
public class MainActivity extends Activity
{
//private static final Logger logger = LoggerFactory.getLogger;
protected String APP_NAME;
LogWriter lw;
PhoneStateListener myPhoneStateListener;
int cid, lac, mcc, mnc,kuatlevel,kualitas,kw3g;
String operator, networktype, networkOperator, type, cellinfo;
GsmCellLocation location;
TelephonyManager tm;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//((Object) PropertyConfigurator.getConfigurator(this)).configure();
tm = (TelephonyManager)getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(phoneStateListener, PhoneStateListener.LISTEN_CELL_LOCATION
|PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
location =((GsmCellLocation)tm.getCellLocation());
operator = tm.getNetworkOperatorName();
networkOperator = tm.getNetworkOperator();
if (networkOperator !=null && networkOperator.length() > 0){
try {
mcc = Integer.parseInt(networkOperator.substring(0, 3));
mnc = Integer.parseInt(networkOperator.substring(3));
} catch (NumberFormatException e){`enter code here`
}
}
networktype = getNetworkTypeString(tm.getNetworkType());
List<NeighboringCellInfo> cellinfo = tm.getNeighboringCellInfo();
if (null != cellinfo){
for(NeighboringCellInfo info : cellinfo){
((TextView)findViewById(R.id.neighbor)).setText("CID:"+(info.getCid()& 0xffff) +
" LAC:"+(info.getLac()& 0xffff));
}
}
((TextView)findViewById(R.id.mnc)).setText("MNC: " + mnc);
((TextView)findViewById(R.id.mcc)).setText("MCC: " + mcc);
((TextView)findViewById(R.id.operatorname)).setText("Operator: " + operator);
//((TextView)findViewById(R.id.networkType)).setText("Network Type: " + networktype);
}
private final PhoneStateListener phoneStateListener = new PhoneStateListener()
{
public void onCellLocationChanged(CellLocation location) {
GsmCellLocation gsmLocation = (GsmCellLocation)location;
setTextViewText(R.id.lac,String.valueOf("LAC: " + (gsmLocation.getLac()& 0xffff)));
setTextViewText(R.id.cid,String.valueOf("CID: " + (gsmLocation.getCid()& 0xffff)));
setTextViewText(R.id.networkType,String.valueOf("Network Type: " + (networktype)));
}
public void onSignalStrengthsChanged(SignalStrength signalStrength){
kualitas = signalStrength.getGsmBitErrorRate();
kw3g = -1 * (signalStrength.getGsmBitErrorRate());
kuatlevel = -113 + 2 *(signalStrength.getGsmSignalStrength());
if (networktype == "2G"){
setTextViewText(R.id.rxq_ecno,String.valueOf("RxQ: " + (kualitas)));
setTextViewText(R.id.rxl_rssi,String.valueOf("RxL: " + (kuatlevel) + " dBm"));
} else {
setTextViewText(R.id.rxq_ecno,String.valueOf("EcNo: " + (kw3g) + " dB"));
setTextViewText(R.id.rxl_rssi,String.valueOf("RSSI: " + (kuatlevel) + " dBm"));
setTextViewText(R.id.arfcn_rscp,String.valueOf("RSCP: " + (kuatlevel + kw3g) + " dBm"));
}
}
};
private String getNetworkTypeString(int Ntype) {
type = "unknown";
switch (Ntype) {
case TelephonyManager.NETWORK_TYPE_EDGE:type = "2G"; break;
case TelephonyManager.NETWORK_TYPE_GPRS:type = "2G"; break;
case TelephonyManager.NETWORK_TYPE_UMTS:type = "3G"; break;
case TelephonyManager.NETWORK_TYPE_1xRTT:type = "2G"; break;
case TelephonyManager.NETWORK_TYPE_HSDPA:type = "3G"; break;
default:
type = "unknown"; break;
}
// TODO Auto-generated method stub
return type;
}
protected void setTextViewText(int id, String text) {
((TextView)findViewById(id)).setText(text);
// TODO Auto-generated method stub
}
//public static Logger getLogger() {
// return logger;
//}
}
Use PhoneStateListener.LISTEN_SERVICE_STATE flag and override onServiceStateChanged(ServiceState serviceState) like this:
#Override
public void onServiceStateChanged(ServiceState serviceState){
super.onServiceStateChanged(serviceState);
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
int networkType = tm.getNetworkType();
}
This function will fire every time network type changes.