android-获取手机信号强度

来源:互联网 发布:mac系统更新失败 编辑:程序博客网 时间:2024/06/02 22:56

1.mainactivity

[java] view plain copy
  1. package com.npsmaster.phoneinfo;  
  2.   
  3. import android.content.Context;  
  4. import android.os.Message;  
  5. import android.os.Handler;  
  6. import android.support.v7.app.AppCompatActivity;  
  7. import android.os.Bundle;  
  8. import android.support.v7.widget.DefaultItemAnimator;  
  9. import android.telephony.CellInfo;  
  10. import android.telephony.CellInfoGsm;  
  11. import android.telephony.CellInfoLte;  
  12. import android.telephony.CellInfoWcdma;  
  13. import android.telephony.PhoneStateListener;  
  14. import android.telephony.SignalStrength;  
  15. import android.telephony.TelephonyManager;  
  16. import android.telephony.gsm.GsmCellLocation;  
  17. import android.widget.TextView;  
  18. import android.support.v7.widget.LinearLayoutManager;  
  19. import android.support.v7.widget.OrientationHelper;  
  20. import android.support.v7.widget.RecyclerView;  
  21.   
  22. import java.sql.Time;  
  23. import java.text.SimpleDateFormat;  
  24. import java.util.ArrayList;  
  25. import java.util.Date;  
  26. import java.util.List;  
  27.   
  28. public class MainActivity extends AppCompatActivity  
  29. {  
  30.     public static final int NP_CELL_INFO_UPDATE = 1001;  
  31.     private PhoneInfoThread phoneInfoThread;  
  32.     public Handler mMainHandler;  
  33.     // for current  
  34.     public  PhoneGeneralInfo phoneGeneralInfo;  
  35.     public  CellGeneralInfo serverCellInfo;  
  36.     //for history  
  37.     private List<CellGeneralInfo> HistoryServerCellList;  
  38.     private CellnfoRecycleViewAdapter historyRecycleViewAdapter;  
  39.     private RecyclerView historyrecyclerView;  
  40.     TelephonyManager phoneManager ;  
  41.     private MyPhoneStateListener myPhoneStateListener;  
  42.   
  43.     void InitProcessThread()  
  44.     {  
  45.         mMainHandler = new Handler()  
  46.         {  
  47.             @Override  
  48.             public void handleMessage(Message msg)  
  49.             {  
  50.                 if(msg.what == NP_CELL_INFO_UPDATE)  
  51.                 {  
  52.                     Bundle bundle = msg.getData();  
  53.                     TextView tvTime = (TextView)findViewById(R.id.tvTimeleaps);  
  54.                     Date now = new Date();  
  55.                     SimpleDateFormat formatter =   new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");  
  56.                     tvTime.setText(formatter.format(now));  
  57.                     historyRecycleViewAdapter.notifyDataSetChanged();  
  58.   
  59.                     TextView tvDeviceId = (TextView)findViewById(R.id.tvDeviceId);  
  60.                     tvDeviceId.setText("DeviceId:" + phoneGeneralInfo.deviceId);  
  61.   
  62.                     TextView tvRatType = (TextView)findViewById(R.id.tvRatType);  
  63.                     tvRatType.setText("RatType:"+phoneGeneralInfo.ratType);  
  64.   
  65.                     TextView tvMnc = (TextView)findViewById(R.id.tMnc);  
  66.                     tvMnc.setText("Mnc:"+phoneGeneralInfo.mnc);  
  67.   
  68.                     TextView tvMcc = (TextView)findViewById(R.id.tvMcc);  
  69.                     tvMcc.setText("Mcc:"+phoneGeneralInfo.mcc);  
  70.   
  71.                     TextView tvOperatorName = (TextView)findViewById(R.id.tvOperaterName);  
  72.                     tvOperatorName.setText("Operator:"+phoneGeneralInfo.operaterName);  
  73.   
  74.                     TextView tvSdk = (TextView)findViewById(R.id.tvSdk);  
  75.                     tvSdk.setText("Sdk:"+phoneGeneralInfo.sdk);  
  76.   
  77.                     TextView tvImsi = (TextView)findViewById(R.id.tvImsi);  
  78.                     tvImsi.setText("Imsi:"+phoneGeneralInfo.Imsi);  
  79.   
  80.                     TextView tvSerialNum = (TextView)findViewById(R.id.tvSerialNum);  
  81.                     tvSerialNum.setText("SN:"+phoneGeneralInfo.serialNumber);  
  82.   
  83.                     TextView tvModel = (TextView)findViewById(R.id.tvModel);  
  84.                     tvModel.setText("Model:" + phoneGeneralInfo.phoneModel);  
  85.   
  86.                     TextView tvSoftwareVersion = (TextView)findViewById(R.id.tvSoftware);  
  87.                     tvSoftwareVersion.setText("Version:" + phoneGeneralInfo.deviceSoftwareVersion);  
  88.   
  89.                     TextView tvAllCellInfo = (TextView)findViewById(R.id.tvStaticInfoLableHistory);  
  90.                     tvAllCellInfo.setText("History cells list("+HistoryServerCellList.size()+")");  
  91.   
  92.                 }  
  93.                 super.handleMessage(msg);  
  94.             }  
  95.         };  
  96.   
  97.         phoneInfoThread = new PhoneInfoThread(MainActivity.this);  
  98.         phoneInfoThread.start();  
  99.     }  
  100.   
  101.     @Override  
  102.     protected void onCreate(Bundle savedInstanceState) {  
  103.         super.onCreate(savedInstanceState);  
  104.         setContentView(R.layout.activity_main);  
  105.         serverCellInfo = new CellGeneralInfo();  
  106.         phoneGeneralInfo = new PhoneGeneralInfo();  
  107.         myPhoneStateListener = new MyPhoneStateListener();  
  108.         phoneManager = (TelephonyManager)this.getSystemService(this.TELEPHONY_SERVICE);  
  109.         phoneManager.listen(myPhoneStateListener,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);  
  110.         //  
  111.         HistoryServerCellList = new ArrayList<CellGeneralInfo>();  
  112.         historyrecyclerView = (RecyclerView)findViewById(R.id.historyrcv);  
  113.         LinearLayoutManager historylayoutManager = new LinearLayoutManager(this);  
  114.         historylayoutManager.setOrientation(OrientationHelper.VERTICAL);  
  115.         historyrecyclerView.setLayoutManager(historylayoutManager);  
  116.         historyRecycleViewAdapter  = new CellnfoRecycleViewAdapter(MainActivity.this,HistoryServerCellList);  
  117.         historyrecyclerView.setAdapter(historyRecycleViewAdapter);  
  118.         historyrecyclerView.setItemAnimator(new DefaultItemAnimator());  
  119.   
  120.         InitProcessThread();  
  121.   
  122.     }  
  123.   
  124.     public void updateServerCellView()  
  125.     {  
  126.         TextView tvCellType = (TextView)findViewById(R.id.tvCellType);  
  127.         tvCellType.setText("Rat:" + serverCellInfo.type);  
  128.   
  129.         TextView tvTac = (TextView)findViewById(R.id.tvTac);  
  130.         tvTac.setText("Tac:" + serverCellInfo.tac);  
  131.   
  132.         TextView tvCellId = (TextView)findViewById(R.id.tvCellId);  
  133.         tvCellId.setText("Ci:" + serverCellInfo.CId);  
  134.   
  135.         TextView tvPCI = (TextView)findViewById(R.id.tvPCI);  
  136.         tvPCI.setText("Pci:" + serverCellInfo.pci);  
  137.   
  138.         TextView tvRsrp = (TextView)findViewById(R.id.tvRsrp);  
  139.         tvRsrp.setText("Rsrp:" + serverCellInfo.rsrp);  
  140.   
  141.         TextView tvRsrq = (TextView)findViewById(R.id.tvRsrq);  
  142.         tvRsrq.setText("Rsrp:" + serverCellInfo.rsrq);  
  143.   
  144.         TextView tvSINR = (TextView)findViewById(R.id.tvSINR);  
  145.         tvSINR.setText("Sinr:" + serverCellInfo.sinr);  
  146.   
  147.         TextView tvCqi = (TextView)findViewById(R.id.tvCqi);  
  148.         tvCqi.setText("cqi:" + serverCellInfo.cqi);  
  149.   
  150.         TextView tvGetCellType = (TextView)findViewById(R.id.tvGetCellType);  
  151.         tvGetCellType.setText("type:" + serverCellInfo.getInfoType);  
  152.     }  
  153.   
  154.     class PhoneGeneralInfo  
  155.     {  
  156.         public String serialNumber;  
  157.         public String operaterName;  
  158.         public String operaterId;  
  159.         public String deviceId;  
  160.         public String deviceSoftwareVersion;  
  161.         public String Imsi;  
  162.         public String Imei;  
  163.         public int mnc;  
  164.         public int mcc;  
  165.         public int ratType= TelephonyManager.NETWORK_TYPE_UNKNOWN;  
  166.         public int phoneDatastate;  
  167.         public String phoneModel;  
  168.         public int sdk;  
  169.     }  
  170.     class CellGeneralInfo implements Cloneable  
  171.     {  
  172.         public int type;  
  173.         public int CId;  
  174.         public int lac;  
  175.         public int tac;  
  176.         public int psc;  
  177.         public int pci;  
  178.         public int RatType= TelephonyManager.NETWORK_TYPE_UNKNOWN;  
  179.         public int rsrp;  
  180.         public int rsrq;  
  181.         public int sinr;  
  182.         public int rssi;  
  183.         public int cqi;  
  184.         public int asulevel;  
  185.         public int getInfoType;  
  186.         public String time;  
  187.   
  188.         @Override  
  189.   
  190.         public Object clone()  
  191.         {  
  192.             CellGeneralInfo cellinfo = null;  
  193.             try  
  194.             {  
  195.                 cellinfo = (CellGeneralInfo)super.clone();  
  196.             }  
  197.             catch(CloneNotSupportedException e)  
  198.             {  
  199.                 e.printStackTrace();  
  200.             }  
  201.             return cellinfo;  
  202.         }  
  203.     }  
  204.   
  205.     class MyPhoneStateListener extends PhoneStateListener  
  206.     {  
  207.         @Override  
  208.         public void  onSignalStrengthsChanged(SignalStrength signalStrength)  
  209.         {  
  210.             super.onSignalStrengthsChanged(signalStrength);  
  211.             getPhoneGeneralInfo();  
  212.             getServerCellInfo();  
  213.             if (phoneGeneralInfo.ratType == TelephonyManager.NETWORK_TYPE_LTE)  
  214.             {  
  215.                 try {  
  216.                     serverCellInfo.rssi = (Integer) signalStrength.getClass().getMethod("getLteSignalStrength").invoke(signalStrength);  
  217.                     serverCellInfo.rsrp = (Integer) signalStrength.getClass().getMethod("getLteRsrp").invoke(signalStrength);  
  218.                     serverCellInfo.rsrq = (Integer) signalStrength.getClass().getMethod("getLteRsrq").invoke(signalStrength);  
  219.                     serverCellInfo.sinr = (Integer) signalStrength.getClass().getMethod("getLteRssnr").invoke(signalStrength);  
  220.                     serverCellInfo.cqi = (Integer) signalStrength.getClass().getMethod("getLteCqi").invoke(signalStrength);  
  221.                 } catch (Exception e) {  
  222.                     e.printStackTrace();  
  223.                     return;  
  224.                 }  
  225.             }  
  226.             else if (phoneGeneralInfo.ratType == TelephonyManager.NETWORK_TYPE_GSM)  
  227.             {  
  228.                 try {  
  229.                     serverCellInfo.rssi = signalStrength.getGsmSignalStrength();  
  230.                     serverCellInfo.rsrp = (Integer) signalStrength.getClass().getMethod("getGsmDbm").invoke(signalStrength);  
  231.                     serverCellInfo.asulevel =(Integer) signalStrength.getClass().getMethod("getAsuLevel").invoke(signalStrength);  
  232.                 } catch (Exception e) {  
  233.                     e.printStackTrace();  
  234.                     return;  
  235.                 }  
  236.             }  
  237.             else if (phoneGeneralInfo.ratType == TelephonyManager.NETWORK_TYPE_TD_SCDMA)  
  238.             {  
  239.                 try {  
  240.                     serverCellInfo.rssi = (Integer) signalStrength.getClass().getMethod("getTdScdmaLevel").invoke(signalStrength);  
  241.                     serverCellInfo.rsrp = (Integer) signalStrength.getClass().getMethod("getTdScdmaDbm").invoke(signalStrength);  
  242.                     serverCellInfo.asulevel =(Integer) signalStrength.getClass().getMethod("getAsuLevel").invoke(signalStrength);  
  243.                 } catch (Exception e) {  
  244.                     e.printStackTrace();  
  245.                     return;  
  246.                 }  
  247.             }  
  248.             Date now = new Date();  
  249.             SimpleDateFormat formatter =   new SimpleDateFormat("hh:mm:ss");  
  250.             serverCellInfo.time = formatter.format(now);  
  251.             updateHistoryCellList(serverCellInfo);  
  252.             updateServerCellView();  
  253.         }  
  254.   
  255.         public void getPhoneGeneralInfo()  
  256.         {  
  257.             phoneGeneralInfo.operaterName = phoneManager.getNetworkOperatorName();  
  258.             phoneGeneralInfo.operaterId = phoneManager.getNetworkOperator();  
  259.             phoneGeneralInfo.mnc = Integer.parseInt(phoneGeneralInfo.operaterId.substring(03));  
  260.             phoneGeneralInfo.mcc = Integer.parseInt(phoneGeneralInfo.operaterId.substring(3));  
  261.             phoneGeneralInfo.phoneDatastate = phoneManager.getDataState();  
  262.             phoneGeneralInfo.deviceId = phoneManager.getDeviceId();  
  263.             phoneGeneralInfo.Imei = phoneManager.getSimSerialNumber();  
  264.             phoneGeneralInfo.Imsi = phoneManager.getSubscriberId();  
  265.             phoneGeneralInfo.serialNumber = phoneManager.getSimSerialNumber();  
  266.             phoneGeneralInfo.deviceSoftwareVersion = android.os.Build.VERSION.RELEASE;  
  267.             phoneGeneralInfo.phoneModel = android.os.Build.MODEL;  
  268.             phoneGeneralInfo.ratType = phoneManager.getNetworkType();  
  269.             phoneGeneralInfo.sdk = android.os.Build.VERSION.SDK_INT;  
  270.         }  
  271.   
  272.         public void getServerCellInfo()  
  273.         {  
  274.             try  
  275.             {  
  276.                 List<CellInfo> allCellinfo;  
  277.                 allCellinfo = phoneManager.getAllCellInfo();  
  278.                 if (allCellinfo != null)  
  279.                 {  
  280.                     CellInfo cellInfo = allCellinfo.get(0);  
  281.                     serverCellInfo.getInfoType = 1;  
  282.                     if (cellInfo instanceof CellInfoGsm)  
  283.                     {  
  284.                         CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo;  
  285.                         serverCellInfo.CId = cellInfoGsm.getCellIdentity().getCid();  
  286.                         serverCellInfo.rsrp = cellInfoGsm.getCellSignalStrength().getDbm();  
  287.                         serverCellInfo.asulevel = cellInfoGsm.getCellSignalStrength().getAsuLevel();  
  288.                         serverCellInfo.lac = cellInfoGsm.getCellIdentity().getLac();  
  289.                         serverCellInfo.RatType = TelephonyManager.NETWORK_TYPE_GSM;  
  290.                     } else if (cellInfo instanceof CellInfoWcdma)  
  291.                     {  
  292.                         CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) cellInfo;  
  293.                         serverCellInfo.CId = cellInfoWcdma.getCellIdentity().getCid();  
  294.                         serverCellInfo.psc = cellInfoWcdma.getCellIdentity().getPsc();  
  295.                         serverCellInfo.lac = cellInfoWcdma.getCellIdentity().getLac();  
  296.                         serverCellInfo.rsrp = cellInfoWcdma.getCellSignalStrength().getDbm();  
  297.                         serverCellInfo.asulevel = cellInfoWcdma.getCellSignalStrength().getAsuLevel();  
  298.                         serverCellInfo.RatType = TelephonyManager.NETWORK_TYPE_UMTS;  
  299.                     } else if (cellInfo instanceof CellInfoLte)  
  300.                     {  
  301.                         CellInfoLte cellInfoLte = (CellInfoLte) cellInfo;  
  302.                         serverCellInfo.CId = cellInfoLte.getCellIdentity().getCi();  
  303.                         serverCellInfo.pci = cellInfoLte.getCellIdentity().getPci();  
  304.                         serverCellInfo.tac = cellInfoLte.getCellIdentity().getTac();  
  305.                         serverCellInfo.rsrp = cellInfoLte.getCellSignalStrength().getDbm();  
  306.                         serverCellInfo.asulevel = cellInfoLte.getCellSignalStrength().getAsuLevel();  
  307.                         serverCellInfo.RatType = TelephonyManager.NETWORK_TYPE_LTE;  
  308.                     }  
  309.                 }  
  310.                 else  
  311.                 //for older devices  
  312.                 {  
  313.                     getServerCellInfoOnOlderDevices();  
  314.                 }  
  315.             }  
  316.             catch(Exception e)  
  317.             {  
  318.                 getServerCellInfoOnOlderDevices();  
  319.             }  
  320.   
  321.         }  
  322.         void getServerCellInfoOnOlderDevices()  
  323.         {  
  324.             GsmCellLocation location = (GsmCellLocation) phoneManager.getCellLocation();  
  325.             serverCellInfo.getInfoType = 0;  
  326.             serverCellInfo.CId = location.getCid();  
  327.             serverCellInfo.tac = location.getLac();  
  328.             serverCellInfo.psc = location.getPsc();  
  329.             serverCellInfo.type = phoneGeneralInfo.ratType;  
  330.         }  
  331.   
  332.         void updateHistoryCellList(CellGeneralInfo serverinfo)  
  333.         {  
  334.             CellGeneralInfo newcellInfo = (CellGeneralInfo)serverinfo.clone();  
  335.             HistoryServerCellList.add(newcellInfo);  
  336.         }  
  337.     }  
  338.      class PhoneInfoThread extends  Thread  
  339.     {  
  340.         private Context context;  
  341.         public int timecount;  
  342.         public PhoneInfoThread(Context context)  
  343.         {  
  344.             this.context = context;  
  345.             timecount = 0;  
  346.         }  
  347.   
  348.         public void run()  
  349.         {  
  350.            while (true) {  
  351.                 try {  
  352.                     timecount++;  
  353.                     Message message = new Message();  
  354.                     message.what = NP_CELL_INFO_UPDATE;  
  355.                     Bundle bundle = new Bundle();  
  356.                     bundle.putString("UPDATE""UPDATE_TIME");  
  357.                     message.setData(bundle);  
  358.                     mMainHandler.sendMessage(message);  
  359.                     Thread.sleep(1000);  
  360.                 } catch (InterruptedException e) {  
  361.                     e.printStackTrace();  
  362.                 }  
  363.             }  
  364.         }  
  365.     }  
  366. }  


2. main layout

[html] view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:tools="http://schemas.android.com/tools"  
  4.     android:id="@+id/activity_main"  
  5.     android:layout_width="match_parent"  
  6.     android:layout_height="match_parent"  
  7.     android:paddingBottom="@dimen/activity_vertical_margin"  
  8.     android:paddingLeft="@dimen/activity_horizontal_margin"  
  9.     android:paddingRight="@dimen/activity_horizontal_margin"  
  10.     android:paddingTop="@dimen/activity_vertical_margin"  
  11.     tools:context="com.npsmaster.phoneinfo.MainActivity">  
  12. <!--start-->  
  13.     <LinearLayout  
  14.         android:orientation="vertical"  
  15.         android:layout_width="match_parent"  
  16.         android:layout_height="match_parent"  
  17.         android:id="@+id/childlayout"  
  18.         android:layout_alignParentTop="true"  
  19.         android:layout_alignParentLeft="true"  
  20.         android:layout_alignParentStart="true">  
  21.         <TableLayout  
  22.             android:layout_width="match_parent"  
  23.             android:layout_height="wrap_content"  
  24.             android:background="#ffcccccc"  
  25.             android:layout_margin="1dp">  
  26.             <!-- line1 -->  
  27.             <TableRow  
  28.                 android:layout_width="match_parent"  
  29.                 android:layout_height="20dp"  
  30.                 android:background="#ffcccccc"  
  31.                 android:layout_margin="0.5dp">  
  32.   
  33.                 <TextView  
  34.                     android:text="General Information"  
  35.                     android:layout_marginTop="5dp"  
  36.                     android:layout_width="0.0dp"  
  37.                     android:layout_height="20dp"  
  38.                     android:layout_weight="1"  
  39.                     android:id="@+id/tvStaticInfoLable">  
  40.                 </TextView>  
  41.                 <TextView  
  42.                     android:text="Time:"  
  43.                     android:layout_marginTop="5dp"  
  44.                     android:layout_width="0.0dp"  
  45.                     android:layout_height="20dp"  
  46.                     android:layout_weight="1"  
  47.                     android:id="@+id/tvTimeleaps">  
  48.                 </TextView>  
  49.             </TableRow>  
  50.             <!--line2-->  
  51.             <TableRow  
  52.                 android:layout_width="fill_parent"  
  53.                 android:layout_height="wrap_content"  
  54.                 android:background="#ffffcc99"  
  55.                 android:layout_margin="0.5dp">  
  56.                 <TextView  
  57.                     android:text="Operater:"  
  58.                     android:layout_width="0.0dp"  
  59.                     android:layout_height="match_parent"  
  60.                     android:id="@+id/tvOperaterName"  
  61.                     android:textSize="12dp"  
  62.                     android:layout_weight="1"/>  
  63.   
  64.                 <TextView  
  65.                     android:text="RatType:"  
  66.                     android:layout_width="0.0dp"  
  67.                     android:layout_height="match_parent"  
  68.                     android:id="@+id/tvRatType"  
  69.                     android:textSize="12dp"  
  70.                     android:layout_weight="1"/>  
  71.             </TableRow>  
  72.             <!-- line3 -->  
  73.             <TableRow  
  74.                 android:layout_width="fill_parent"  
  75.                 android:layout_height="match_parent"  
  76.                 android:background="#ffffcc99"  
  77.                 android:layout_margin="0.5dp">  
  78.                 <TextView  
  79.                     android:text="mnc"  
  80.                     android:layout_width="0.0dp"  
  81.                     android:layout_height="match_parent"  
  82.                     android:textSize="12dp"  
  83.                     android:layout_weight="1"  
  84.                     android:id="@+id/tMnc" />  
  85.                 <TextView  
  86.                     android:text="mcc:"  
  87.                     android:layout_width="0.0dp"  
  88.                     android:layout_height="match_parent"  
  89.                     android:layout_weight="1"  
  90.                     android:id="@+id/tvMcc"  
  91.                     android:textSize="12dp">  
  92.                 </TextView>  
  93.             </TableRow>  
  94.             <!--line4-->  
  95.             <TableRow  
  96.                 android:layout_width="fill_parent"  
  97.                 android:layout_height="wrap_content"  
  98.                 android:background="#ffffcc99"  
  99.                 android:layout_margin="0.5dp">  
  100.                 <TextView  
  101.                     android:text="Imsi"  
  102.                     android:layout_width="0.0dp"  
  103.                     android:layout_height="match_parent"  
  104.                     android:layout_weight="1"  
  105.                     android:textSize="12dp"  
  106.                     android:id="@+id/tvImsi" />  
  107.                 <TextView  
  108.                     android:text="SDK:"  
  109.                     android:layout_width="0.0dp"  
  110.                     android:layout_height="match_parent"  
  111.                     android:id="@+id/tvSdk"  
  112.                     android:layout_weight="1"  
  113.                     android:textSize="12dp"/>  
  114.             </TableRow>  
  115.             <!--line5-->  
  116.             <TableRow  
  117.                 android:layout_width="fill_parent"  
  118.                 android:layout_height="wrap_content"  
  119.                 android:background="#ffffcc99"  
  120.                 android:layout_margin="0.5dp">  
  121.                 <TextView  
  122.                     android:text="DeviceId"  
  123.                     android:layout_width="0.0dp"  
  124.                     android:layout_height="match_parent"  
  125.                     android:layout_weight="1"  
  126.                     android:textSize="12dp"  
  127.                     android:id="@+id/tvDeviceId" />  
  128.                 <TextView  
  129.                     android:text="SN:"  
  130.                     android:layout_width="0.0dp"  
  131.                     android:layout_height="match_parent"  
  132.                     android:layout_weight="1"  
  133.                     android:textSize="12dp"  
  134.                     android:id="@+id/tvSerialNum"  
  135.                     android:layout_margin="0.5dp" />  
  136.             </TableRow>  
  137.             <!--line6-->  
  138.             <TableRow  
  139.                 android:layout_width="fill_parent"  
  140.                 android:layout_height="wrap_content"  
  141.                 android:background="#ffffcc99"  
  142.                 android:layout_margin="0.5dp">  
  143.                 <TextView  
  144.                     android:text="software:"  
  145.                     android:layout_width="0.0dp"  
  146.                     android:layout_height="match_parent"  
  147.                     android:layout_weight="1"  
  148.                     android:textSize="12dp"  
  149.                     android:id="@+id/tvSoftware" />  
  150.                 <TextView  
  151.                     android:text="Model:"  
  152.                     android:layout_width="0.0dp"  
  153.                     android:layout_height="match_parent"  
  154.                     android:layout_weight="1"  
  155.                     android:textSize="12dp"  
  156.                     android:id="@+id/tvModel"  
  157.                     android:layout_margin="0.5dp" />  
  158.             </TableRow>  
  159.             </TableLayout>  
  160.         <TableLayout  
  161.             android:layout_width="match_parent"  
  162.             android:layout_height="wrap_content"  
  163.             android:background="#ffcccccc"  
  164.             android:layout_margin="0dp">  
  165.             <!--line6-->  
  166.             <TableRow  
  167.                 android:layout_width="fill_parent"  
  168.                 android:layout_height="wrap_content"  
  169.                 android:background="#ffcccccc"  
  170.                 android:layout_margin="0.5dp">  
  171.                 <TextView  
  172.                     android:text="Serving cell information"  
  173.                     android:layout_marginTop="5dp"  
  174.                     android:layout_width="match_parent"  
  175.                     android:layout_height="20dp"  
  176.                     android:id="@+id/tvStaticInfoLable">  
  177.                 </TextView>  
  178.             </TableRow>  
  179.             <!-- title -->  
  180.             <TableRow  
  181.                 android:layout_width="fill_parent"  
  182.                 android:layout_height="wrap_content"  
  183.                 android:background="#ffffcc99"  
  184.                 android:layout_margin="0.5dp">  
  185.                 <TextView  
  186.                     android:text="Rat:"  
  187.                     android:layout_width="0.0dp"  
  188.                     android:layout_height="match_parent"  
  189.                     android:layout_weight="1"  
  190.                     android:textSize="12dp"  
  191.                     android:id="@+id/tvCellType" />  
  192.                 <TextView  
  193.                     android:text="Tac:"  
  194.                     android:layout_width="0.0dp"  
  195.                     android:layout_height="match_parent"  
  196.                     android:layout_weight="1"  
  197.                     android:textSize="12dp"  
  198.                     android:id="@+id/tvTac" />  
  199.                 <TextView  
  200.                     android:text="CI:"  
  201.                     android:layout_width="0.0dp"  
  202.                     android:layout_height="match_parent"  
  203.                     android:layout_weight="1"  
  204.                     android:textSize="12dp"  
  205.                     android:id="@+id/tvCellId" />  
  206.                 </TableRow>  
  207.             <TableRow  
  208.                 android:layout_width="fill_parent"  
  209.                 android:layout_height="wrap_content"  
  210.                 android:background="#ffffcc99"  
  211.                 android:layout_margin="0.5dp">  
  212.                 <TextView  
  213.                     android:text="Rsrp:"  
  214.                     android:layout_width="0.0dp"  
  215.                     android:layout_height="match_parent"  
  216.                     android:layout_weight="1"  
  217.                     android:textSize="12dp"  
  218.                     android:id="@+id/tvRsrp" />  
  219.                 <TextView  
  220.                     android:text="Rsrq:"  
  221.                     android:layout_width="0.0dp"  
  222.                     android:layout_height="match_parent"  
  223.                     android:layout_weight="1"  
  224.                     android:textSize="12dp"  
  225.                     android:id="@+id/tvRsrq" />  
  226.                 <TextView  
  227.                     android:text="SINR:"  
  228.                     android:layout_width="0.0dp"  
  229.                     android:layout_height="match_parent"  
  230.                     android:layout_weight="1"  
  231.                     android:textSize="12dp"  
  232.                     android:id="@+id/tvSINR" />  
  233.   
  234.             </TableRow>  
  235.             <TableRow  
  236.                 android:layout_width="fill_parent"  
  237.                 android:layout_height="wrap_content"  
  238.                 android:background="#ffffcc99"  
  239.                 android:layout_margin="0.5dp">  
  240.                 <TextView  
  241.                     android:text="PCI/PSC:"  
  242.                     android:layout_width="0.0dp"  
  243.                     android:layout_height="match_parent"  
  244.                     android:layout_weight="1"  
  245.                     android:textSize="12dp"  
  246.                     android:id="@+id/tvPCI" />  
  247.                 <TextView  
  248.                     android:text="CQI:"  
  249.                     android:layout_width="0.0dp"  
  250.                     android:layout_height="match_parent"  
  251.                     android:layout_weight="1"  
  252.                     android:textSize="12dp"  
  253.                     android:id="@+id/tvCqi" />  
  254.                 <TextView  
  255.                     android:text="type:"  
  256.                     android:layout_width="0.0dp"  
  257.                     android:layout_height="match_parent"  
  258.                     android:layout_weight="1"  
  259.                     android:textSize="12dp"  
  260.                     android:id="@+id/tvGetCellType"/>  
  261.                 </TableRow>  
  262.         </TableLayout>  
  263.         <!-- history services cell info -->  
  264.         <TableLayout  
  265.             android:layout_width="match_parent"  
  266.             android:layout_height="wrap_content"  
  267.             android:background="#ffcccccc"  
  268.             android:layout_margin="1dp">  
  269.             <TextView  
  270.                 android:text="History cells information:"  
  271.                 android:layout_marginTop="5dp"  
  272.                 android:layout_width="match_parent"  
  273.                 android:layout_height="20dp"  
  274.                 android:id="@+id/tvStaticInfoLableHistory">  
  275.             </TextView>  
  276.             <TableRow  
  277.                 android:layout_width="fill_parent"  
  278.                 android:layout_height="wrap_content"  
  279.                 android:background="#ffffcc99"  
  280.                 android:layout_margin="0.5dp">  
  281.                 <TextView  
  282.                     android:text="Type:"  
  283.                     android:layout_width="0.0dp"  
  284.                     android:layout_height="match_parent"  
  285.                     android:layout_weight="1"  
  286.                     android:textSize="12dp"  
  287.                     android:id="@+id/tvhistoryCellType" />  
  288.                 <TextView  
  289.                     android:text="Tac:"  
  290.                     android:layout_width="0.0dp"  
  291.                     android:layout_height="match_parent"  
  292.                     android:layout_weight="1"  
  293.                     android:textSize="12dp"  
  294.                     android:id="@+id/tvhistoryTac" />  
  295.                 <TextView  
  296.                     android:text="CI:"  
  297.                     android:layout_width="0.0dp"  
  298.                     android:layout_height="match_parent"  
  299.                     android:layout_weight="1"  
  300.                     android:textSize="12dp"  
  301.                     android:id="@+id/tvhistoryCellId" />  
  302.                 <TextView  
  303.                     android:text="PCI/PSC:"  
  304.                     android:layout_width="0.0dp"  
  305.                     android:layout_height="match_parent"  
  306.                     android:layout_weight="1"  
  307.                     android:textSize="12dp"  
  308.                     android:id="@+id/tvhistoryPCI" />  
  309.                 <TextView  
  310.                     android:text="dBm:"  
  311.                     android:layout_width="0.0dp"  
  312.                     android:layout_height="match_parent"  
  313.                     android:layout_weight="1"  
  314.                     android:textSize="12dp"  
  315.                     android:id="@+id/tvhistorydBm" />  
  316.                 <TextView  
  317.                     android:text="asulevel:"  
  318.                     android:layout_width="0.0dp"  
  319.                     android:layout_height="match_parent"  
  320.                     android:layout_weight="1"  
  321.                     android:textSize="12dp"  
  322.                     android:id="@+id/tvhistoryasuLevel " />  
  323.             </TableRow>  
  324.         </TableLayout>  
  325.   
  326.   
  327.         <android.support.v7.widget.RecyclerView  
  328.             android:scrollbars="vertical"  
  329.             android:layout_width="match_parent"  
  330.             android:layout_height="wrap_content"  
  331.             android:divider="#ffff0000"  
  332.             android:dividerHeight="10dp"  
  333.             android:id="@+id/historyrcv"/>  
  334.     </LinearLayout>  
  335. </RelativeLayout>  


1. manifests

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.npsmaster.phoneinfo">    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:supportsRtl="true"        android:theme="@style/AppTheme">        <activity android:name=".MainActivity">            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application>    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" >    </uses-permission>    <uses-permission android:name="android.permission.READ_PHONE_STATE" />    <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" >    </uses-permission></manifest>
2.main
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/activity_main"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context="com.npsmaster.phoneinfo.MainActivity"><!--start-->    <LinearLayout        android:orientation="vertical"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:id="@+id/childlayout"        android:layout_alignParentTop="true"        android:layout_alignParentLeft="true"        android:layout_alignParentStart="true">        <TableLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:background="#ffcccccc"            android:layout_margin="1dp">            <!-- line1 -->            <TableRow                android:layout_width="match_parent"                android:layout_height="20dp"                android:background="#ffcccccc"                android:layout_margin="0.5dp">                <TextView                    android:text="General Information"                    android:layout_marginTop="5dp"                    android:layout_width="0.0dp"                    android:layout_height="20dp"                    android:layout_weight="1"                    android:id="@+id/tvStaticInfoLable">                </TextView>                <TextView                    android:text="Time:"                    android:layout_marginTop="5dp"                    android:layout_width="0.0dp"                    android:layout_height="20dp"                    android:layout_weight="1"                    android:id="@+id/tvTimeleaps">                </TextView>            </TableRow>            <!--line2-->            <TableRow                android:layout_width="fill_parent"                android:layout_height="wrap_content"                android:background="#ffffcc99"                android:layout_margin="0.5dp">                <TextView                    android:text="Operater:"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:id="@+id/tvOperaterName"                    android:textSize="12dp"                    android:layout_weight="1"/>                <TextView                    android:text="RatType:"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:id="@+id/tvRatType"                    android:textSize="12dp"                    android:layout_weight="1"/>            </TableRow>            <!-- line3 -->            <TableRow                android:layout_width="fill_parent"                android:layout_height="match_parent"                android:background="#ffffcc99"                android:layout_margin="0.5dp">                <TextView                    android:text="mnc"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:textSize="12dp"                    android:layout_weight="1"                    android:id="@+id/tMnc" />                <TextView                    android:text="mcc:"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:layout_weight="1"                    android:id="@+id/tvMcc"                    android:textSize="12dp">                </TextView>            </TableRow>            <!--line4-->            <TableRow                android:layout_width="fill_parent"                android:layout_height="wrap_content"                android:background="#ffffcc99"                android:layout_margin="0.5dp">                <TextView                    android:text="Imsi"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:layout_weight="1"                    android:textSize="12dp"                    android:id="@+id/tvImsi" />                <TextView                    android:text="Number:"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:id="@+id/tvLine1Number"                    android:layout_weight="1"                    android:textSize="12dp"/>            </TableRow>            <!--line5-->            <TableRow                android:layout_width="fill_parent"                android:layout_height="wrap_content"                android:background="#ffffcc99"                android:layout_margin="0.5dp">                <TextView                    android:text="DeviceId"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:layout_weight="1"                    android:textSize="12dp"                    android:id="@+id/tvDeviceId" />                <TextView                    android:text="SN:"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:layout_weight="1"                    android:textSize="12dp"                    android:id="@+id/tvSerialNum"                    android:layout_margin="0.5dp" />            </TableRow>            <!--line6-->            <TableRow                android:layout_width="fill_parent"                android:layout_height="wrap_content"                android:background="#ffffcc99"                android:layout_margin="0.5dp">                <TextView                    android:text="software:"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:layout_weight="1"                    android:textSize="12dp"                    android:id="@+id/tvSoftware" />                <TextView                    android:text="Model:"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:layout_weight="1"                    android:textSize="12dp"                    android:id="@+id/tvModel"                    android:layout_margin="0.5dp" />            </TableRow>            </TableLayout>        <TableLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:background="#ffcccccc"            android:layout_margin="0dp">            <!--line6-->            <TableRow                android:layout_width="fill_parent"                android:layout_height="wrap_content"                android:background="#ffcccccc"                android:layout_margin="0.5dp">                <TextView                    android:text="Serving and Neighboring Cells"                    android:layout_marginTop="5dp"                    android:layout_width="match_parent"                    android:layout_height="20dp"                    android:id="@+id/tvStaticInfoLable">                </TextView>                <TextView                    android:text="CellCount:"                    android:layout_marginTop="5dp"                    android:layout_width="match_parent"                    android:layout_height="20dp"                    android:id="@+id/tvCellCount">                </TextView>            </TableRow>            <!-- title -->            <TableRow                android:layout_width="fill_parent"                android:layout_height="wrap_content"                android:background="#ffffcc99"                android:layout_margin="0.5dp">                <TextView                    android:text="Type:"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:layout_weight="1"                    android:textSize="12dp"                    android:id="@+id/tvCellType" />                <TextView                    android:text="Tac:"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:layout_weight="1"                    android:textSize="12dp"                    android:id="@+id/tvTac" />                <TextView                    android:text="CI:"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:layout_weight="1"                    android:textSize="12dp"                    android:id="@+id/tvCellId" />                <TextView                    android:text="PCI/PSC:"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:layout_weight="1"                    android:textSize="12dp"                    android:id="@+id/tvPCI" />                <TextView                    android:text="dBm:"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:layout_weight="1"                    android:textSize="12dp"                    android:id="@+id/tvSign" />                <TextView                    android:text="asulevel:"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:layout_weight="1"                    android:textSize="12dp"                    android:id="@+id/tvasulevel " />            </TableRow>        </TableLayout>            android:layout_width="match_parent"            android:layout_height="wrap_content">            <android.support.v7.widget.RecyclerView                android:scrollbars="vertical"                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:divider="#ffff0000"                android:dividerHeight="10dp"                android:id="@+id/myrcv" />        <!-- history services cell info -->        <TableLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:background="#ffcccccc"            android:layout_margin="1dp">            <TextView                android:text="History Services Cell Information"                android:layout_marginTop="5dp"                android:layout_width="match_parent"                android:layout_height="20dp"                android:id="@+id/tvStaticInfoLable">            </TextView>            <TableRow                android:layout_width="fill_parent"                android:layout_height="wrap_content"                android:background="#ffffcc99"                android:layout_margin="0.5dp">                <TextView                    android:text="Type:"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:layout_weight="1"                    android:textSize="12dp"                    android:id="@+id/tvhistoryCellType" />                <TextView                    android:text="Tac:"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:layout_weight="1"                    android:textSize="12dp"                    android:id="@+id/tvhistoryTac" />                <TextView                    android:text="CI:"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:layout_weight="1"                    android:textSize="12dp"                    android:id="@+id/tvhistoryCellId" />                <TextView                    android:text="PCI/PSC:"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:layout_weight="1"                    android:textSize="12dp"                    android:id="@+id/tvhistoryPCI" />                <TextView                    android:text="dBm:"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:layout_weight="1"                    android:textSize="12dp"                    android:id="@+id/tvhistorydBm" />                <TextView                    android:text="asulevel:"                    android:layout_width="0.0dp"                    android:layout_height="match_parent"                    android:layout_weight="1"                    android:textSize="12dp"                    android:id="@+id/tvhistoryasuLevel " />            </TableRow>        </TableLayout>        <android.support.v7.widget.RecyclerView            android:scrollbars="vertical"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:divider="#ffff0000"            android:dividerHeight="10dp"            android:id="@+id/historyrcv"/>    </LinearLayout></RelativeLayout>
3. item
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    android:orientation="vertical"    android:layout_width="match_parent"    android:layout_height="wrap_content">    <TableLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:background="#ffcccccc"        android:layout_margin="0dp">        <TableRow            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:background="#ffffcc99"            android:layout_margin="0.5dp">            <TextView                android:text="Type:"                android:layout_width="0.0dp"                android:layout_height="match_parent"                android:layout_weight="1"                android:textSize="12dp"                android:id="@+id/tvCellType" />            <TextView                android:text="Tac:"                android:layout_width="0.0dp"                android:layout_height="match_parent"                android:layout_weight="1"                android:textSize="12dp"                android:id="@+id/tvTac" />            <TextView                android:text="CI:"                android:layout_width="0.0dp"                android:layout_height="match_parent"                android:layout_weight="1"                android:textSize="12dp"                android:id="@+id/tvCellId" />            <TextView                android:text="PCI/PSC:"                android:layout_width="0.0dp"                android:layout_height="match_parent"                android:layout_weight="1"                android:textSize="12dp"                android:id="@+id/tvPCI" />            <TextView                android:text="dBm:"                android:layout_width="0.0dp"                android:layout_height="match_parent"                android:layout_weight="1"                android:textSize="12dp"                android:id="@+id/tvdBm" />            <TextView                android:text="asulevel:"                android:layout_width="0.0dp"                android:layout_height="match_parent"                android:layout_weight="1"                android:textSize="12dp"                android:id="@+id/tvasulevel " />        </TableRow>    </TableLayout></LinearLayout>

原创粉丝点击