PermissionUtils 无法解析

我试图在我的应用程序中获取我当前的位置,但PermissionUtils出现错误。这没有得到解决。我从google 的官方 github 教程中得到了代码。


public class MapsActivity extends FragmentActivity implements GoogleMap.OnMyLocationButtonClickListener,

        GoogleMap.OnMyLocationClickListener,

        OnMapReadyCallback,

        ActivityCompat.OnRequestPermissionsResultCallback {


    /**

     * Request code for location permission request.

     *

     * @see #onRequestPermissionsResult(int, String[], int[])

     */

    private static final int LOCATION_PERMISSION_REQUEST_CODE = 1;


    /**

     * Flag indicating whether a requested permission has been denied after returning in

     * {@link #onRequestPermissionsResult(int, String[], int[])}.

     */

    private boolean mPermissionDenied = false;


    private GoogleMap mMap;


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_maps);


        SupportMapFragment mapFragment =

                (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

        mapFragment.getMapAsync(this);


    }



    @Override

    public void onMapReady(GoogleMap googleMap) {

        mMap = googleMap;


        mMap.setOnMyLocationButtonClickListener(this);

        mMap.setOnMyLocationClickListener(this);

        enableMyLocation();


    }


    private void enableMyLocation() {



        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)

                != PackageManager.PERMISSION_GRANTED) {

            // Permission to access the location is missing.

            PermissionUtils.requestPermission(this, LOCATION_PERMISSION_REQUEST_CODE,

                    Manifest.permission.ACCESS_FINE_LOCATION, true);

        } else if (mMap != null) {

            // Access to the location has been granted to the app.

            mMap.setMyLocationEnabled(true);

        }


    }



白猪掌柜的
浏览 229回答 2
2回答

慕姐8265434

您是否在清单中设置了使用权限?如果没有,你应该先设置它。<uses-permission&nbsp;android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission&nbsp;android:name="android.permission.ACCESS_FINE_LOCATION"/>

UYOU

PermissionUtils是示例项目定义的类。如果你想使用它,你必须将它复制到你的项目中。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java