zengjingfang / AndroidBox

Android开发知识、经验、资料等总结,作为个人的开发知识体系
Apache License 2.0
16 stars 3 forks source link

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

Closed zengjingfang closed 6 years ago

zengjingfang commented 6 years ago
 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 commented 6 years ago

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