用户10093和当前进程都没有Android M中的android.permission.READ_PHONE_STATE错误

时间:2018-05-11 08:59:31

标签: android runtime-error

在具有android M的设备中运行我的应用程序时出现Neither user 10093 nor current process has android.permission.READ_PHONE_STATE.错误。我已添加运行时权限,如下所示:

private void checkAndRequestForPermission() {

        int readCalendarPermissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CALENDAR);
        int localStoragePermissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
        int callPhonePermissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE);
        int coarseLocationPermissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION);
        int fineLocationPermissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION);
        int readPhoneStatePermissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE);

        if (localStoragePermissionCheck != PackageManager.PERMISSION_GRANTED
                || readCalendarPermissionCheck != PackageManager.PERMISSION_GRANTED
                || callPhonePermissionCheck != PackageManager.PERMISSION_GRANTED
                || coarseLocationPermissionCheck != PackageManager.PERMISSION_GRANTED
                || fineLocationPermissionCheck != PackageManager.PERMISSION_GRANTED
                ||readPhoneStatePermissionCheck!=PackageManager.PERMISSION_GRANTED) {

            // For marshmallow and above we need to manually check and prompt for permission
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.READ_CALENDAR
                            , Manifest.permission.WRITE_EXTERNAL_STORAGE
                            , Manifest.permission.CALL_PHONE
                            , Manifest.permission.ACCESS_COARSE_LOCATION
                            , Manifest.permission.ACCESS_FINE_LOCATION
                            ,Manifest.permission.READ_PHONE_STATE},
                    MY_PERMISSIONS_REQUEST_CODE);
            getReadPhoneAccess();
        } else {
            // Means all permissions are granted
            return;
        }

    }

    /***
     * Runtime external storage access
     */
    private void getReadPhoneAccess(){

        if (checkSelfPermission(Manifest.permission.READ_PHONE_STATE)
                != PackageManager.PERMISSION_GRANTED) {

            // Should we show an explanation?
            if (shouldShowRequestPermissionRationale(
                    Manifest.permission.READ_PHONE_STATE)) {
                // Explain to the user why we need to read the contacts
            }

            requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE},
                    2);

            // MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE is an
            // app-defined int constant that should be quite unique

            //return;
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {

        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        switch (requestCode) {
            case MY_PERMISSIONS_REQUEST_CODE: {

                //boolean isAllPermissionGranted = true;

                if ((grantResults.length > 0) && (grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
                    for (int grantResult : grantResults) {
                        if (grantResult != PackageManager.PERMISSION_GRANTED) {
                            /*isAllPermissionGranted = false;*/
                            checkAndRequestForPermission();
                            break;
                        }
                    }
                }
            }
            break;
        }
    }  

错误日志如下:

05-11 14:28:34.548 4229-4319/com.emc.mauth.myorders E/AndroidRuntime: FATAL EXCEPTION: IntentService[com.emc.mauth.myorders.AirWatchSDKContextService]
                                                                      Process: com.emc.mauth.myorders, PID: 4229
                                                                      java.lang.SecurityException: getDeviceId: Neither user 10093 nor current process has android.permission.READ_PHONE_STATE.
                                                                          at android.os.Parcel.readException(Parcel.java:1599)
                                                                          at android.os.Parcel.readException(Parcel.java:1552)
                                                                          at com.android.internal.telephony.ITelephony$Stub$Proxy.getDeviceId(ITelephony.java:4175)
                                                                          at android.telephony.TelephonyManager.getDeviceId(TelephonyManager.java:706)
                                                                          at com.airwatch.core.AirWatchDevice.getIMEINumber(Unknown Source)
                                                                          at com.airwatch.core.AirWatchDevice.getAwDeviceUid(Unknown Source)
                                                                          at com.airwatch.util.ServerConnectionBuilder.buildUpSecureChannel(Unknown Source)
                                                                          at com.airwatch.util.ServerConnectionBuilder.buildSecureChannelConfig(Unknown Source)
                                                                          at com.airwatch.sdk.configuration.SDKSettingsFetchTask.execute(Unknown Source)
                                                                          at com.airwatch.sdk.SDKBaseContextService.handleFetchSDKSettings(Unknown Source)
                                                                          at com.airwatch.sdk.SDKBaseContextService.handleSDKConfigure(Unknown Source)
                                                                          at com.airwatch.sdk.SDKBaseContextService.handleInitAndConfigure(Unknown Source)
                                                                          at com.airwatch.sdk.SDKBaseContextService.onHandleIntent(Unknown Source)
                                                                          at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                          at android.os.Looper.loop(Looper.java:148)
                                                                          at android.os.HandlerThread.run(HandlerThread.java:61)  

我该如何解决?

0 个答案:

没有答案