通过getAllCellInfo()获取手机信号塔位置

时间:2019-09-07 16:26:49

标签: android location telephonymanager

我写了一个应用程序 我代替了手机。 这些是我的代码 适用于许多手机。 但这在Android 9上不起作用。 GsmCellLocation返回Null ... 而且我认为它已过时,并且我必须使用getAllCellInfo。 但是我不知道如何更改它。

    TelephonyManager tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    String networkOperator = tel.getNetworkOperator();

    if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return;
    }
    GsmCellLocation cellLocation;
     cellLocation = (GsmCellLocation) tel.getCellLocation();

    if (!TextUtils.isEmpty(networkOperator)) {
        mcc = Integer.parseInt(networkOperator.substring(0, 3));
        mnc = Integer.parseInt(networkOperator.substring(3));
    }
    if (cellLocation != null) {
        lac = cellLocation.getLac();
        cid = cellLocation.getCid();
    }
    String payam_b = "S.B" + ":" + mcc + ":" + mnc + ":" + lac + ":" + cid;
    Log.d(TAG, "payam_b: " + payam_b);
}

0 个答案:

没有答案
相关问题