Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从CellSignalStrengthLte获取Android应用程序API 17的RSRP+;_Java_Android_Telephonymanager_Phone State Listener_Lte - Fatal编程技术网

Java 从CellSignalStrengthLte获取Android应用程序API 17的RSRP+;

Java 从CellSignalStrengthLte获取Android应用程序API 17的RSRP+;,java,android,telephonymanager,phone-state-listener,lte,Java,Android,Telephonymanager,Phone State Listener,Lte,在过去的十年中,有一些人提出了类似的问题,但没有人给出任何答案。我需要编写一个android应用程序来收集和存储RSRP、RSRQ、CINR和手机ID。答案需要尽可能准确(我正在三星Galaxy S5上测试),因为我需要用这些值进行后处理统计 有人知道如何使用telephonyManager或CellSignalStrengthLite获取RSRP吗?或者有没有其他更好的方法来获得RSRP 到目前为止,我所能做的最好的事情就是使用PhoneStateListener和TelephonyManag

在过去的十年中,有一些人提出了类似的问题,但没有人给出任何答案。我需要编写一个android应用程序来收集和存储RSRP、RSRQ、CINR和手机ID。答案需要尽可能准确(我正在三星Galaxy S5上测试),因为我需要用这些值进行后处理统计

有人知道如何使用telephonyManager或CellSignalStrengthLite获取RSRP吗?或者有没有其他更好的方法来获得RSRP

到目前为止,我所能做的最好的事情就是使用PhoneStateListener和TelephonyManager来获取RSSI值,但RSSI对我的统计数据毫无用处:

    package com.pscr.jparks.signalstrength;

    import android.app.Activity;
    import android.os.Bundle;
    import android.telephony.PhoneStateListener;
    import android.telephony.TelephonyManager;
    import android.widget.TextView;
    /*
    TS 27.007 8.5
    Defined values
    <rssi>:
    0 -113 dBm or less
    1 -111 dBm
    2...30 -109... -53 dBm
    31 -51 dBm or greater
    99 not known or not detectable
    */

    public class SignalStrengthActivity  extends Activity {

        SignalStrengthListener signalStrengthListener;
        TextView signalStrengthTextView;


        @Override
        public void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);

            //setup content stuff
            this.setContentView(R.layout.signal_strength);
            signalStrengthTextView = (TextView) findViewById(R.id.signalStrengthTextView);

            //start the signal strength listener
            signalStrengthListener = new SignalStrengthListener();
            ((TelephonyManager) getSystemService(TELEPHONY_SERVICE)).listen(signalStrengthListener, SignalStrengthListener.LISTEN_SIGNAL_STRENGTHS);
        }


        private class SignalStrengthListener extends PhoneStateListener {
            @Override
            public void onSignalStrengthsChanged(android.telephony.SignalStrength signalStrength) {

                // get the signal strength (a value between 0 and 31)
                int strengthAmplitude = signalStrength.getGsmSignalStrength();

                //do something with it (in this case we update a text view)
          signalStrengthTextView.setText(String.valueOf(strengthAmplitude));
          super.onSignalStrengthsChanged(signalStrength);
            }
        }
    }
package com.pscr.jparks.signalstrength;
导入android.app.Activity;
导入android.os.Bundle;
导入android.telephony.PhoneStateListener;
导入android.telephony.TelephonyManager;
导入android.widget.TextView;
/*
TS 27.007 8.5
定义值
:
0-113 dBm或更小
1-111 dBm
2...30 -109... -53 dBm
31-51 dBm或更大
99未知或不可检测
*/
公共类信号强度活动扩展活动{
信号强度监听器信号强度监听器;
文本视图信号强度文本视图;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//设置内容内容
此.setContentView(R.layout.signal_strength);
signalStrengthTextView=(TextView)findViewById(R.id.signalStrengthTextView);
//启动信号强度侦听器
signalStrengthListener=新的signalStrengthListener();
((电话管理器)getSystemService(电话服务)).listen(信号强度侦听器,信号强度侦听器。侦听信号强度);
}
私有类SignalStrengthListener扩展PhoneStateListener{
@凌驾
已更改信号强度上的公共无效(android.telephony.SignalStrength信号强度){
//获取信号强度(介于0和31之间的值)
int-strengthhamplitude=signalStrength.getGsmSignalStrength();
//使用它做些什么(在本例中,我们更新一个文本视图)
SignalStrengtTextView.setText(String.valueOf(strengthAmplitude));
超级信号强度改变(信号强度);
}
}
}

如果有人解决了这个问题,或者找到了答案(我到处都找过!),请告诉我

更新:

TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
List<CellInfo> cellInfoList = tm.getAllCellInfo();
for (CellInfo cellInfo : cellInfoList)
{
    if (cellInfo instanceof CellInfoLte)
    {
        // cast to CellInfoLte and call all the CellInfoLte methods you need
        ((CellInfoLte)cellInfo).getCellSignalStrength().getDbm();
    }
}
TelephonyManager tm=(TelephonyManager)getSystemService(Context.TELEPHONY_服务);
List-cellInfoList=tm.getAllCellInfo();
用于(CellInfo CellInfo:cellInfoList)
{
if(CellInfoLte的cellInfo实例)
{
//转换到CellInfoLte并调用您需要的所有CellInfoLte方法
((CellInfoLte)cellInfo.getCellSignalStrength().getDbm();
}
}

这是我的答案和布鲁斯·兰的代码。这仍然是一项正在进行的工作,但它展示了如何收集各种LTE参数。您可以从我的GitHub帐户获取整个Android Studio项目,网址为:

package com.pscr.jparks.signalstrength;
导入android.app.Activity;
导入android.content.Context;
导入android.os.Bundle;
导入android.telephony.CellInfo;
导入android.telephony.CellInfoLte;
导入android.telephony.PhoneStateListener;
导入android.telephony.TelephonyManager;
导入android.util.Log;
导入android.widget.TextView;
导入java.util.List;
/*
TS 27.007 8.5
定义值
:
0-113 dBm或更小
1-111 dBm
2...30 -109... -53 dBm
31-51 dBm或更大
99未知或不可检测
*/
/*
parts[]数组将包含以下元素:
第[0]部分=“信号强度:”\u忽略这一点,这只是标题_
零件[1]=GsmSignalStrength
第[2]部分=GSMBiTerrorate
第[3]部分=CdmaDbm
第[4]部分=CdmaEcio
零件[5]=EvdoDbm
第[6]部分=EvdoEcio
第[7]部分=EvdoSnr
零件[8]=强度
零件[9]=LteRsrp
零件[10]=LteRsrq
第[11]部分=LteRssnr
第[12]部分=LteCqi
第[13]部分=gsm | lte
部分[14]=\u不确定这个数字是多少_
*/
公共类信号强度活动扩展活动{
//应用程序关闭时如何释放侦听器???????
信号强度监听器信号强度监听器;
TextView SignalStrenghtExtView、SignalStrenghtExtView2;
TextView cellIDTextView;
文本视图;文本视图;
TextView单元mnctextview;
text视图cellPciTextView;
TextView cellTacTextView;
列表单元信息列表;
int-cellSig、cellID、cellMcc、cellMnc、cellpic、cellTac=0;
TelephonyManager tm;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//设置内容内容
此.setContentView(R.layout.signal_strength);
signalStrengthTextView=(TextView)findViewById(R.id.signalStrengthTextView);
signalStrengthTextView2=(TextView)findViewById(R.id.signalStrengthTextView2);
cellIDTextView=(TextView)findViewById(R.id.cellIDTextView);
CellMcTextView=(TextView)findViewById(R.id.CellMcTextView);
cellMncTextView=(TextView)findViewById(R.id.cellMncTextView);
cellPciTextView=(TextView)findViewById(R.id.cellPciTextView);
cellTacTextView=(TextView)findViewById(R.id.cellTacTextView);
//启动信号强度侦听器
signalStrengthListener=新的signalStrengthListener();
((电话管理器)getSystemService(电话服务)).listen(信号强度侦听器,信号强度侦听器。侦听信号强度);
tm=(TelephonyManager)getSystemService(Context.TELEPHONY_服务);
试一试{
cellInfoList=tm.getAllCellInfo();
}捕获(例外e){
Log.d(“信号强度”、“零阵列点1:”+e);
}
试一试{
为了(细胞)
package com.pscr.jparks.signalstrength;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.CellInfo;
import android.telephony.CellInfoLte;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.TextView;

import java.util.List;
/*
TS 27.007 8.5
Defined values
<rsrp>:
0 -113 dBm or less
1 -111 dBm
2...30 -109... -53 dBm
31 -51 dBm or greater
99 not known or not detectable
*/



/*
The parts[] array will then contain these elements:

part[0] = "Signalstrength:"  _ignore this, it's just the title_
parts[1] = GsmSignalStrength
parts[2] = GsmBitErrorRate
parts[3] = CdmaDbm
parts[4] = CdmaEcio
parts[5] = EvdoDbm
parts[6] = EvdoEcio
parts[7] = EvdoSnr
parts[8] = LteSignalStrength
parts[9] = LteRsrp
parts[10] = LteRsrq
parts[11] = LteRssnr
parts[12] = LteCqi
parts[13] = gsm|lte
parts[14] = _not reall sure what this number is_
*/

public class SignalStrengthActivity  extends Activity {

    // How do I release the Listener when app closes???????
    SignalStrengthListener signalStrengthListener;

    TextView signalStrengthTextView, signalStrengthTextView2;
    TextView cellIDTextView;
    TextView cellMccTextView;
    TextView cellMncTextView;
    TextView cellPciTextView;
    TextView cellTacTextView;

    List<CellInfo> cellInfoList;
    int cellSig, cellID, cellMcc, cellMnc, cellPci, cellTac = 0;

    TelephonyManager tm;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //setup content stuff
        this.setContentView(R.layout.signal_strength);

        signalStrengthTextView = (TextView) findViewById(R.id.signalStrengthTextView);
        signalStrengthTextView2 = (TextView) findViewById(R.id.signalStrengthTextView2);
        cellIDTextView = (TextView) findViewById(R.id.cellIDTextView);
        cellMccTextView = (TextView) findViewById(R.id.cellMccTextView);
        cellMncTextView = (TextView) findViewById(R.id.cellMncTextView);
        cellPciTextView = (TextView) findViewById(R.id.cellPciTextView);
        cellTacTextView = (TextView) findViewById(R.id.cellTacTextView);


        //start the signal strength listener
        signalStrengthListener = new SignalStrengthListener();

        ((TelephonyManager) getSystemService(TELEPHONY_SERVICE)).listen(signalStrengthListener, SignalStrengthListener.LISTEN_SIGNAL_STRENGTHS);
        tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

        try {
            cellInfoList = tm.getAllCellInfo();
        } catch (Exception e) {
            Log.d("SignalStrength", "+++++++++++++++++++++++++++++++++++++++++ null array spot 1: " + e);

        }


        try {
            for (CellInfo cellInfo : cellInfoList) {
                if (cellInfo instanceof CellInfoLte) {
                    // cast to CellInfoLte and call all the CellInfoLte methods you need
                    // gets RSRP cell signal strength:
                    cellSig = ((CellInfoLte) cellInfo).getCellSignalStrength().getDbm();

                    // Gets the LTE cell indentity: (returns 28-bit Cell Identity, Integer.MAX_VALUE if unknown)
                    cellID = ((CellInfoLte) cellInfo).getCellIdentity().getCi();

                    // Gets the LTE MCC: (returns 3-digit Mobile Country Code, 0..999, Integer.MAX_VALUE if unknown)
                    cellMcc = ((CellInfoLte) cellInfo).getCellIdentity().getMcc();

                    // Gets theLTE MNC: (returns 2 or 3-digit Mobile Network Code, 0..999, Integer.MAX_VALUE if unknown)
                    cellMnc = ((CellInfoLte) cellInfo).getCellIdentity().getMnc();

                    // Gets the LTE PCI: (returns Physical Cell Id 0..503, Integer.MAX_VALUE if unknown)
                    cellPci = ((CellInfoLte) cellInfo).getCellIdentity().getPci();

                    // Gets the LTE TAC: (returns 16-bit Tracking Area Code, Integer.MAX_VALUE if unknown)
                    cellTac = ((CellInfoLte) cellInfo).getCellIdentity().getTac();

                }

            }
        } catch (Exception e) {
            Log.d("SignalStrength", "++++++++++++++++++++++ null array spot 2: " + e);
        }

    }



    @Override
    public void onPause() {
        super.onPause();

        try{
            if(signalStrengthListener != null){tm.listen(signalStrengthListener, SignalStrengthListener.LISTEN_NONE);}
        }catch(Exception e){
            e.printStackTrace();
        }
    }


    public void onDestroy() {
        super.onDestroy();

        try{
            if(signalStrengthListener != null){tm.listen(signalStrengthListener, SignalStrengthListener.LISTEN_NONE);}
        }catch(Exception e){
            e.printStackTrace();
        }
    }




    private class SignalStrengthListener extends PhoneStateListener {
        @Override
        public void onSignalStrengthsChanged(android.telephony.SignalStrength signalStrength) {

            //++++++++++++++++++++++++++++++++++

            ((TelephonyManager) getSystemService(TELEPHONY_SERVICE)).listen(signalStrengthListener, SignalStrengthListener.LISTEN_SIGNAL_STRENGTHS);

            tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

            String ltestr = signalStrength.toString();
            String[] parts = ltestr.split(" ");
            String cellSig2 = parts[9];

            try {
                cellInfoList = tm.getAllCellInfo();
                for (CellInfo cellInfo : cellInfoList) {
                    if (cellInfo instanceof CellInfoLte) {
                        // cast to CellInfoLte and call all the CellInfoLte methods you need
                        // gets RSRP cell signal strength:
                        cellSig = ((CellInfoLte) cellInfo).getCellSignalStrength().getDbm();

                        // Gets the LTE cell identity: (returns 28-bit Cell Identity, Integer.MAX_VALUE if unknown)
                        cellID = ((CellInfoLte) cellInfo).getCellIdentity().getCi();

                        // Gets the LTE MCC: (returns 3-digit Mobile Country Code, 0..999, Integer.MAX_VALUE if unknown)
                        cellMcc = ((CellInfoLte) cellInfo).getCellIdentity().getMcc();

                        // Gets theLTE MNC: (returns 2 or 3-digit Mobile Network Code, 0..999, Integer.MAX_VALUE if unknown)
                        cellMnc = ((CellInfoLte) cellInfo).getCellIdentity().getMnc();

                        // Gets the LTE PCI: (returns Physical Cell Id 0..503, Integer.MAX_VALUE if unknown)
                        cellPci = ((CellInfoLte) cellInfo).getCellIdentity().getPci();

                        // Gets the LTE TAC: (returns 16-bit Tracking Area Code, Integer.MAX_VALUE if unknown)
                        cellTac = ((CellInfoLte) cellInfo).getCellIdentity().getTac();

                    }
                }
            } catch (Exception e) {
                Log.d("SignalStrength", "+++++++++++++++++++++++++++++++ null array spot 3: " + e);
            }

            signalStrengthTextView.setText(String.valueOf(cellSig));
            signalStrengthTextView2.setText(String.valueOf(cellSig2));
            cellIDTextView.setText(String.valueOf(cellID));
            cellMccTextView.setText(String.valueOf(cellMcc));
            cellMncTextView.setText(String.valueOf(cellMnc));
            cellPciTextView.setText(String.valueOf(cellPci));
            cellTacTextView.setText(String.valueOf(cellTac));

            super.onSignalStrengthsChanged(signalStrength);

            //++++++++++++++++++++++++++++++++++++

        }
    }

}
List<CellSignalStrength> cellInfoList;
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
cellInfoList = tm.getSignalStrength().getCellSignalStrengths();
    for (CellSignalStrength cellInfo : cellInfoList) {
        if (cellInfo instanceof CellSignalStrengthLte) {
            rsrp = ((CellSignalStrengthLte) cellInfo).getRsrp();
            rsrq = ((CellSignalStrengthLte) cellInfo).getRsrq();
            snr = ((CellSignalStrengthLte) cellInfo).getRssnr();

        }
    }
    rsrpValue.setText(String.valueOf(rsrp));
    rsrqValue.setText(String.valueOf(rsrq));
    sinr.setText(String.valueOf(snr));
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>