Check Android Permissions in a Method

后端 未结 2 2127
无人及你
无人及你 2021-02-12 16:14

here is my code and it works perfectly fine.

if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManag         


        
2条回答
  •  萌比男神i
    2021-02-12 16:53

    You can suppress this error in both the editor and in lint reports by annotating your method with @SuppressWarnings("MissingPermission"), or you can suppress the error for just a single statement by putting //noinspection MissingPermission above that line.

    For example:

    @SuppressWarnings("MissingPermission")
    public boolean hasMapLocationPermissions(Activity activity) {
      // your checking logic
    }
    

    Or:

    if (Utils.hasMapLocationPermissions(getActivity())) {
        //noinspection MissingPermission
        mMap.setMyLocationEnabled(true);
    }
    

提交回复
热议问题