Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.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 6.0 api 23-获得许可后,我的位置为空_Android_Geolocation_Android Permissions - Fatal编程技术网

Android 6.0 api 23-获得许可后,我的位置为空

Android 6.0 api 23-获得许可后,我的位置为空,android,geolocation,android-permissions,Android,Geolocation,Android Permissions,我在安卓6.0中还有一个位置问题 我阅读了Android 6.0的官方许可指南,现在可以工作了,但是我的位置是空的,代码似乎被阻止了 这是OnCreate方法: if ( Build.VERSION.SDK_INT >= 23 ) { //CONTROLLO PER ANDROID 6.0 O SUPERIORE int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission

我在安卓6.0中还有一个位置问题

我阅读了Android 6.0的官方许可指南,现在可以工作了,但是我的位置是空的,代码似乎被阻止了

这是OnCreate方法:

if ( Build.VERSION.SDK_INT >= 23 ) { //CONTROLLO PER ANDROID 6.0 O SUPERIORE
        int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION);

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

            if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                    Manifest.permission.ACCESS_FINE_LOCATION)) {
            } else {
                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                        MY_PERMISSIONS_ACCESS_FINE_LOCATION);
            }
        }
    }else{
        Log.d("ANDROID","ANDROID SENZA FRONZOLI");
        //dA QUI IN POI MAIN STANDARD
    }
这是检查权限类:

@Override
public void onRequestPermissionsResult(int requestCode,
                                       String permissions[], int[] grantResults) {
    switch (requestCode) {
        case MY_PERMISSIONS_ACCESS_FINE_LOCATION: {
            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {


                Log.d("PERMESSI-fine", "PERMESSI OK");

                LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

                if ( ContextCompat.checkSelfPermission( this, android.Manifest.permission.ACCESS_FINE_LOCATION ) != PackageManager.PERMISSION_GRANTED ) {

                    ActivityCompat.requestPermissions( this, new String[] {  android.Manifest.permission.ACCESS_FINE_LOCATION  },
                            MY_PERMISSIONS_ACCESS_FINE_LOCATION );
                }

                    Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);

                    if (location != null) {
                        double longitude = location.getLongitude();
                        double latitude = location.getLatitude();

                        Log.d("GPS-PROVIDER", String.valueOf(longitude));
                        Log.d("GPS-PROVIDER", String.valueOf(latitude));

                        // Toast.makeText(MainActivity.this, "GPS OK", Toast.LENGTH_SHORT).show();
                    }else{
                        Log.d("GPS","NIENTE ZONA VUOTA");
                        Log.d("GPS", String.valueOf(location));
                    }



            } else {


                Log.d("PERMESSI-fine","PERMESSE NO");
            }
            return;
        }

        // other 'case' lines to check for other
        // permissions this app might request
    }
}
代码没有给出错误,简单什么都没有!空对象。现在我正在使用android 6.0模拟器。我没有这个操作系统版本的真正设备


请帮助我。

emulator没有gps,因此位置提供商将无法获取任何位置或任何最后已知的位置。您需要添加gps数据。或者

对于插入坐标,我使用了emulator的extend控件,geo fix不起作用,他告诉我你在emulator中使用的是google api