mirror of
https://github.com/YTVanced/VancedMicroG
synced 2024-11-10 13:05:05 +00:00
Android M: Request permission before using location in Map
This commit is contained in:
parent
8df631cd95
commit
1c5da4a07a
1 changed files with 14 additions and 0 deletions
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package org.microg.gms.maps;
|
package org.microg.gms.maps;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.location.Criteria;
|
import android.location.Criteria;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
|
@ -25,6 +26,8 @@ import android.os.Bundle;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.support.v4.app.ActivityCompat;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -72,6 +75,10 @@ import org.microg.gms.maps.markup.PolygonImpl;
|
||||||
import org.microg.gms.maps.markup.PolylineImpl;
|
import org.microg.gms.maps.markup.PolylineImpl;
|
||||||
import org.microg.gms.maps.markup.TileOverlayImpl;
|
import org.microg.gms.maps.markup.TileOverlayImpl;
|
||||||
|
|
||||||
|
import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
|
||||||
|
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
|
||||||
|
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||||
|
|
||||||
public class GoogleMapImpl extends IGoogleMapDelegate.Stub
|
public class GoogleMapImpl extends IGoogleMapDelegate.Stub
|
||||||
implements UiSettingsImpl.UiSettingsListener, Markup.MarkupListener, BackendMap.CameraUpdateListener {
|
implements UiSettingsImpl.UiSettingsListener, Markup.MarkupListener, BackendMap.CameraUpdateListener {
|
||||||
private static final String TAG = "GoogleMapImpl";
|
private static final String TAG = "GoogleMapImpl";
|
||||||
|
@ -417,6 +424,13 @@ public class GoogleMapImpl extends IGoogleMapDelegate.Stub
|
||||||
@Override
|
@Override
|
||||||
public void setMyLocationEnabled(boolean myLocation) throws RemoteException {
|
public void setMyLocationEnabled(boolean myLocation) throws RemoteException {
|
||||||
Log.w(TAG, "MyLocation not yet supported");
|
Log.w(TAG, "MyLocation not yet supported");
|
||||||
|
boolean hasPermission = ContextCompat.checkSelfPermission(context, ACCESS_COARSE_LOCATION) == PERMISSION_GRANTED
|
||||||
|
|| ContextCompat.checkSelfPermission(context, ACCESS_FINE_LOCATION) == PERMISSION_GRANTED;
|
||||||
|
if (!hasPermission) {
|
||||||
|
if (context instanceof Activity)
|
||||||
|
ActivityCompat.requestPermissions((Activity) context, new String[]{ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION}, -1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||||
if (myLocation) {
|
if (myLocation) {
|
||||||
locationManager.requestLocationUpdates(5000, 10, criteria, listener, Looper.getMainLooper());
|
locationManager.requestLocationUpdates(5000, 10, criteria, listener, Looper.getMainLooper());
|
||||||
|
|
Loading…
Reference in a new issue