Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.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
Android 在棉花糖中请求位置许可时应用程序崩溃_Android_Android 6.0 Marshmallow_Android Permissions_Android Location - Fatal编程技术网

Android 在棉花糖中请求位置许可时应用程序崩溃

Android 在棉花糖中请求位置许可时应用程序崩溃,android,android-6.0-marshmallow,android-permissions,android-location,Android,Android 6.0 Marshmallow,Android Permissions,Android Location,在棉花糖中请求位置许可时,应用程序崩溃。崩溃后,将出现权限请求对话框。单击允许,然后退出。然后我们可以打开应用程序而不会崩溃。帮我找出错误。 权限请求对话框也出现了5次以上 public boolean checkLocationPermission(){ if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != Pack

棉花糖中请求位置许可时,应用程序崩溃。崩溃后,将出现权限请求对话框。单击允许,然后退出。然后我们可以打开应用程序而不会崩溃。帮我找出错误。 权限请求对话框也出现了5次以上

public boolean checkLocationPermission(){
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)!=PackageManager.PERMISSION_GRANTED){

        // Asking user if explanation is needed
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                      Manifest.permission.ACCESS_FINE_LOCATION)&& ActivityCompat.shouldShowRequestPermissionRationale(this,Manifest.permission.ACCESS_COARSE_LOCATION)) {
            // Show an explanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.
            //Prompt the user once explanation has been shown
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.ACCESS_COARSE_LOCATION},
                    MY_PERMISSIONS_REQUEST_LOCATION);
        } else {
            // No explanation needed, we can request the permission.
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.ACCESS_COARSE_LOCATION},
                    MY_PERMISSIONS_REQUEST_LOCATION);
        }
        return false;
    } else {
        return true;
    }
}
@Override
public void onRequestPermissionsResult(int requestCode,
                                       String permissions[], int[] grantResults) {
    switch (requestCode) {
        case MY_PERMISSIONS_REQUEST_LOCATION: {
           if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                // permission was granted. Do the
                // contacts-related task you need to do.
                if (ContextCompat.checkSelfPermission(this,
                        Manifest.permission.ACCESS_FINE_LOCATION)
                        == PackageManager.PERMISSION_GRANTED && (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED)) {
                    if (mGoogleApiClient == null) {
                        buildGoogleApiClient();
                    }
                    try {
                        mMap.setMyLocationEnabled(true);
                    } catch (Exception e) {
                        Log.e("map exiting code", "mMap.setMyLocationEnabled(true);");
                    }
                }
            } else
                // Permission denied, Disable the functionality that depends on this permission.
                Toast.makeText(this, "permission denied", Toast.LENGTH_LONG).show();
            }
            return;
        }
        // other 'case' lines to check for other permissions this app might request.
        // You can add here other case statements according to your requirement.
    }
}

发布日志…同时在此处发布完整的活动代码。崩溃日志?…我确信您在允许权限之前正在执行一些位置任务。这就是位置变为空的原因。。它应该是空指针异常。。我猜看到我的示例发布了日志…也在这里发布了完整的活动代码。崩溃日志?…我确信您在允许权限之前正在执行一些位置任务。这就是位置变为空的原因。。它应该是空指针异常。。我想看到我的样品了