2016-08-10 18 views
0

私はアンドロイド6.0(sdk 23)で現在の位置を見つけるのに問題があります。主な活動で現在の場所を見つけるAndroid 6.0

は私が書きました:

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

     locationListener = new LocationListener() { 

      @Override 
      public void onLocationChanged(Location location) { 

textView.append("\n " + location.getLongitude() + " " + location.getLatitude()); 

      } 

      @Override 
      public void onStatusChanged(String provider, int status, Bundle extras) { 

      } 

      @Override 
      public void onProviderEnabled(String provider) { 

      } 

      @Override 
      public void onProviderDisabled(String provider) { 
       Intent i = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); 
       startActivity(i); 
      } 

     }; 

     configure_list(); 

は要求許可結果にも実装:

@Override 
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 
     switch (requestCode) { 
      case 10: 
       if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 
        // permission granted 

       } else { 
        // permission denied 

       } 
       break; 
      default: 
       break; 
     } 
    } 

    public void configure_list() { 
     // first check for permissions 
     if 

(ActivityCompat.checkSelfPermission(Applicazione.getInstance().getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(Applicazione.getInstance().getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 
      requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.INTERNET} ,10); 
     } 
     return; 
    } 

    locationManager.requestLocationUpdates("gps", 5000, 0, locationListener); 

} 

しかし、現在の場所は常に0でエラーがありますか?誰かが私に何かを提案できますか?

答えて

関連する問題