我尝试使用下面的代码获取当前位置,它适用于6.0-6.0.1,应用程序在5.0和7.0中崩溃

时间:2017-07-20 13:01:01

标签: android

在我的应用程序中,我需要当前位置才能在ATM附近找到。我使用gms来查找具有运行时权限的当前位置,它适用于6.0-6.0.1和5.0。问题是在7.0关闭三星和5.1版本的应用程序。我将ACCESS_FINE_LOCATIONACCESS_COURSE_LOCATION权限放在android清单中。我使用目标sdk版本25。

   @Override
    public void onLocationReceived(Location location) {
        if (location != null) {
            latLng = new LatLng(location.getLatitude(), location.getLongitude());
            address=new FetchAddress(RegisterActivity.this,latLng);
            Log.e("My Address",address.getAddress());
            Log.e("My Locality",address.getLocality());
            tracker1.stopLocationUpdates();
        }

    }

1 个答案:

答案 0 :(得分:0)

嘿,你的问题清楚地表明你没有写下你的部分许可。

  1. 您可能会获得像

    这样的棉花糖的许可
    if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M){
     //after success you call some method
        getLocation();
    
    }  
    
  2. 此功能仅在marshmallow

  3. 中调用
  4. 您必须如下所示编写其他部分许可

        if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M){
     //after success you call some method
        getLocation();
        dependentData(); //Main function
    
        }else
        {
           dependentData(); // If Is > 6 or < 5.0 no matter this should be executed
        }
    
  5. 试试这个希望它的作品。