我做了gps位置监听器,但我的位置更新需要许可吗?

时间:2016-07-19 10:40:38

标签: android gps locationlistener

我做了gps位置监听器,但我的位置更新需要权限吗?

public abstract class MapsActivity extends FragmentActivity implements GoogleApiClient.ConnectionCallbacks,GoogleApiClient.OnConnectionFailedListener {
    protected GoogleApiClient mGoogleApiClient;
    protected Location mLastLocation;

    private GoogleMap mMap;
    private LocationManager mng;
    private TextView txt1, txt2;
    private LocationListener receiver;

    private void init() {

        mng = (LocationManager)
                this.getSystemService(Context.LOCATION_SERVICE);

        mng.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 1.0F, receiver);
    }

1 个答案:

答案 0 :(得分:0)

首先,您需要为android manifest xml添加权限。

对于位置,您需要:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

然后,对于Android Marshmallow及以上,您将需要运行时权限。

请在此处查找信息

docs

example

良好的图书馆将使您的生活更轻松:

Karumi/Dexter

MarshmallowPermissionManager