android-获取手机信号强度(2)

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
  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值