1.mainactivity
package com.npsmaster.phoneinfo;
import android.content.Context;
import android.os.Message;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.telephony.CellInfo;
import android.telephony.CellInfoGsm;
import android.telephony.CellInfoLte;
import android.telephony.CellInfoWcdma;
import android.telephony.PhoneStateListener;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import android.widget.TextView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class MainActivity extends AppCompatActivity
{
public static final int NP_CELL_INFO_UPDATE = 1001;
private PhoneInfoThread phoneInfoThread;
public Handler mMainHandler;
// for current
public PhoneGeneralInfo phoneGeneralInfo;
public CellGeneralInfo serverCellInfo;
//for history
private List<CellGeneralInfo> HistoryServerCellList;
private CellnfoRecycleViewAdapter historyRecycleViewAdapter;
private RecyclerView historyrecyclerView;
TelephonyManager phoneManager ;
private MyPhoneStateListener myPhoneStateListener;
void InitProcessThread()
{
mMainHandler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
if(msg.what == NP_CELL_INFO_UPDATE)
{
Bundle bundle = msg.getData();
TextView tvTime = (TextView)findViewById(R.id.tvTimeleaps);
Date now = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
tvTime.setText(formatter.format(now));
historyRecycleViewAdapter.notifyDataSetChanged();
TextView tvDeviceId = (TextView)findViewById(R.id.tvDeviceId);
tvDeviceId.setText("DeviceId:" + phoneGeneralInfo.deviceId);
TextView tvRatType = (TextView)findViewById(R.id.tvRatType);
tvRatType.setText("RatType:"+phoneGeneralInfo.ratType);
TextView tvMnc = (TextView)findViewById(R.id.tMnc);
tvMnc.setText("Mnc:"+phoneGeneralInfo.mnc);
TextView tvMcc = (TextView)findViewById(R.id.tvMcc);
tvMcc.setText("Mcc:"+phoneGeneralInfo.mcc);
TextView tvOperatorName = (TextView)findViewById(R.id.tvOperaterName);
tvOperatorName.setText("Operator:"+phoneGeneralInfo.operaterName);
TextView tvSdk = (TextView)findViewById(R.id.tvSdk);
tvSdk.setText("Sdk:"+phoneGeneralInfo.sdk);
TextView tvImsi = (TextView)findViewById(R.id.tvImsi);
tvImsi.setText("Imsi:"+phoneGeneralInfo.Imsi);
TextView tvSerialNum = (TextView)findViewById(R.id.tvSerialNum);
tvSerialNum.setText("SN:"+phoneGeneralInfo.serialNumber);
TextView tvModel = (TextView)findViewById(R.id.tvModel);
tvModel.setText("Model:" + phoneGeneralInfo.phoneModel);
TextView tvSoftwareVersion = (TextView)findViewById(R.id.tvSoftware);
tvSoftwareVersion.setText("Version:" + phoneGeneralInfo.deviceSoftwareVersion);
TextView tvAllCellInfo = (TextView)findViewById(R.id.tvStaticInfoLableHistory);
tvAllCellInfo.setText("History cells list("+HistoryServerCellList.size()+")");
}
super.handleMessage(msg);
}
};
phoneInfoThread = new PhoneInfoThread(MainActivity.this);
phoneInfoThread.start();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
serverCellInfo = new CellGeneralInfo();
phoneGeneralInfo = new PhoneGeneralInfo();
myPhoneStateListener = new MyPhoneStateListener();
phoneManager = (TelephonyManager)this.getSystemService(this.TELEPHONY_SERVICE);
phoneManager.listen(myPhoneStateListener,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
//
HistoryServerCellList = new ArrayList<CellGeneralInfo>();
historyrecyclerView = (RecyclerView)findViewById(R.id.historyrcv);
LinearLayoutManager historylayoutManager = new LinearLayoutManager(this);
historylayoutManager.setOrientation(OrientationHelper.VERTICAL);
historyrecyclerView.setLayoutManager(historylayoutManager);
historyRecycleViewAdapter = new CellnfoRecycleViewAdapter(MainActivity.this,HistoryServerCellList);
historyrecyclerView.setAdapter(historyRecycleViewAdapter);
historyrecyclerView.setItemAnimator(new DefaultItemAnimator());
InitProcessThread();
}
public void updateServerCellView()
{
TextView tvCellType = (TextView)findViewById(R.id.tvCellType);
tvCellType.setText("Rat:" + serverCellInfo.type);
TextView tvTac = (TextView)findViewById(R.id.tvTac);
tvTac.setText("Tac:" + serverCellInfo.tac);
TextView tvCellId = (TextView)findViewById(R.id.tvCellId);
tvCellId.setText("Ci:" + serverCellInfo.CId);
TextView tvPCI = (TextView)findViewById(R.id.tvPCI);
tvPCI.setText("Pci:" + serverCellInfo.pci);
TextView tvRsrp = (TextView)findViewById(R.id.tvRsrp);
tvRsrp.setText("Rsrp:" + serverCellInfo.rsrp);
TextView tvRsrq = (TextView)findViewById(R.id.tvRsrq);
tvRsrq.setText("Rsrp:" + serverCellInfo.rsrq);
TextView tvSINR = (TextView)findViewById(R.id.tvSINR);
tvSINR.setText("Sinr:" + serverCellInfo.sinr);
TextView tvCqi = (TextView)findViewById(R.id.tvCqi);
tvCqi.setText("cqi:" + serverCellInfo.cqi);
TextView tvGetCellType = (TextView)findViewById(R.id.tvGetCellType);
tvGetCellType.setText("type:" + serverCellInfo.getInfoType);
}
class PhoneGeneralInfo
{
public String serialNumber;
pub