package com.ghj.pciex;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.CellInfo;
import android.telephony.CellInfoLte;
import android.telephony.PhoneStateListener;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.ToggleButton;
import java.util.List;
public class MainActivity extends AppCompatActivity {
TextView txtPci;
//manager
TelephonyManager telephonyManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtPci = (TextView)findViewById(R.id.txtPci);
//manager
telephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
if(telephonyManager.getNetworkType()==TelephonyManager.NETWORK_TYPE_LTE){
//리스너 등록
telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
}
//리스너
PhoneStateListener mPhoneStateListener = new PhoneStateListener(){
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
super.onSignalStrengthsChanged(signalStrength);
//PCI
List<CellInfo> cellinfos = telephonyManager.getAllCellInfo();
for(CellInfo info : cellinfos){
if(info instanceof CellInfoLte){
int cellci = ((CellInfoLte)info).getCellIdentity().getCi();
Log.d("pci", cellci+"");
if(cellci!=0 && cellci!=Integer.MAX_VALUE){
int pci = ((CellInfoLte)info).getCellIdentity().getPci(); //Physical Cell Id 0..503, Integer.MAX_VALUE if unknown
txtPci.setText("PCI : "+pci);
break;
}
}
}
}
};
@Override
protected void onDestroy() {
telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
super.onDestroy();
}
}