Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neither user 10421 nor current process has android.permission.ACCESS_COARSE_LOCATION. #2

Closed
zengjingfang opened this issue Dec 28, 2017 · 1 comment

Comments

@zengjingfang
Copy link
Owner

zengjingfang commented Dec 28, 2017

 Process: com.xxx.xxx.xxx:push, PID: 5783
 java.lang.SecurityException: Neither user 10421 nor current process has android.permission.ACCESS_COARSE_LOCATION.
     at android.os.Parcel.readException(Parcel.java:1546)
     at android.os.Parcel.readException(Parcel.java:1499)
     at com.android.internal.telephony.ITelephony$Stub$Proxy.getAllCellInfoUsingSubId(ITelephony.java:2923)
     at android.telephony.TelephonyManager.getAllCellInfo(TelephonyManager.java:2729)
     at android.telephony.TelephonyManager.getAllCellInfo(TelephonyManager.java:2723)
     at com.xxx.im.core.common.utils.SIMUtil.getMobileDbm(Unknown Source)
     at com.xxx.im.core.common.utils.SIMUtil.isSignalStrong(Unknown Source)
/**
     * 获取手机信号强度,需添加权限 android.permission.ACCESS_COARSE_LOCATION <br>
     * API要求不低于17 <br>
     *
     * @return 当前手机主卡信号强度, 单位 dBm(-1是默认值,表示获取失败)
     */
    private static int getMobileDbm(Context context) {

        int dbm = -1;
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        List<CellInfo> cellInfoList;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            cellInfoList = tm.getAllCellInfo();
            if (null != cellInfoList) {
                for (CellInfo cellInfo : cellInfoList) {
                    if (cellInfo instanceof CellInfoGsm) {//移动
                        CellSignalStrengthGsm cellSignalStrengthGsm = ((CellInfoGsm) cellInfo).getCellSignalStrength();
                        dbm = cellSignalStrengthGsm.getDbm();
                    } else if (cellInfo instanceof CellInfoCdma) {//电信
                        CellSignalStrengthCdma cellSignalStrengthCdma = ((CellInfoCdma) cellInfo).getCellSignalStrength();
                        dbm = cellSignalStrengthCdma.getDbm();
                    } else if (cellInfo instanceof CellInfoWcdma) {//联通
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                            CellSignalStrengthWcdma cellSignalStrengthWcdma = ((CellInfoWcdma) cellInfo).getCellSignalStrength();
                            dbm = cellSignalStrengthWcdma.getDbm();
                        }
                    } else if (cellInfo instanceof CellInfoLte) {//移动
                        CellSignalStrengthLte cellSignalStrengthLte = ((CellInfoLte) cellInfo).getCellSignalStrength();
                        dbm = cellSignalStrengthLte.getDbm();
                    }
                }
            }
        }
        LogUtil.d(TAG,"mobile dbm: "+dbm);
        return dbm;
    }

增加了权限,还是报权限问题。为什么???

@zengjingfang
Copy link
Owner Author

傻逼,
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/><!--手表的-->
copy 多了一个点

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant