Android check permission for LocationManager

后端 未结 6 812
我寻月下人不归
我寻月下人不归 2020-11-28 01:35

I\'m trying to get the GPS coordinates to display when I click a button in my activity layout. The following is the method that gets called when I click the button:

6条回答
  •  情歌与酒
    2020-11-28 02:11

    SIMPLE SOLUTION

    I wanted to support apps pre api 23 and instead of using checkSelfPermission I used a try / catch

    try {
       location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    } catch (SecurityException e) {
       dialogGPS(this.getContext()); // lets the user know there is a problem with the gps
    }
    

提交回复
热议问题