android-获取手机小区信息代码设计

本文详细介绍了在Android平台上如何通过代码获取手机当前所在的小区信息,包括必要的权限设置、API调用及数据解析,为开发者提供了一种实现定位辅助的方法。
摘要由CSDN通过智能技术生成

1.main

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.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.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity
{
    public static final int NP_CELL_INFO_UPDATE = 1001;

    private PhoneInfoThread phoneInfoThread;
    private  int msgcount;
    public Handler mMainHandler;
    // for current
    private List<CellGeneralInfo> CellInfoList;
    private CellnfoRecycleViewAdapter myRecycleViewAdapter;
    private RecyclerView recyclerView;
    //for history
    private List<CellGeneralInfo> HistoryServerCellList;
    private CellnfoRecycleViewAdapter historyRecycleViewAdapter;
    private RecyclerView historyrecyclerView;

    void InitProcessThread()
    {
        mMainHandler = new Handler()
        {
            @Override
            public void handleMessage(Message msg)
            {
                if(msg.what == NP_CELL_INFO_UPDATE)
                {
                    msgcount++;
                    Bundle bundle = msg.getData();
                    myRecycleViewAdapter.notifyDataSetChanged();
                    historyRecycleViewAdapter.notifyDataSetChanged();
                    TextView tvTime = (TextView)findViewById(R.id.tvTimeleaps);
                    tvTime.setText("Time:" + msgcount);
                    TextView tvAllCellInfo = (TextView)findViewById(R.id.tvCellCount);
                    tvAllCellInfo.setText("("+HistoryServerCellList.size()+")");

                    TextView tvDeviceId = (TextView)findViewById(R.id.tvDeviceId);
                    tvDeviceId.setText("DeviceId:" + phoneInfoThread.deviceId);

                    TextView tvRatType = (TextView)findViewById(R.id.tvRatType);
                    tvRatType.setText("RatType:"+phoneInfoThread.ratType);

                    TextView tvMnc = (TextView)findViewById(R.id.tMnc);
                    tvMnc.setText("Mnc:"+phoneInfoThread.mnc);

                    TextView tvMcc = (TextView)findViewById(R.id.tvMcc);
                    tvMcc.setText("Mcc:"+phoneInfoThread.mcc);

                    TextView tvOperatorName = (TextView)findViewById(R.id.tvOperaterName);
                    tvOperatorName.setText("Operator:"+phoneInfoThread.operaterName);

                    TextView tvImsi
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值