Xiaomi - java.lang.SecurityException:客户必须具有ACCESS_FINE_LOCATION权限才能请求PRIORITY_HIGH_ACCURACY位置

时间:2016-08-19 09:23:33

标签: android android-permissions

我正在使用小米MI 5 Marshmallow 在Fabric上遇到SecurityException崩溃。

Fatal Exception: java.lang.SecurityException: Client must have ACCESS_FINE_LOCATION permission to request PRIORITY_HIGH_ACCURACY locations.
       at android.os.Parcel.readException(Parcel.java:1599)
       at android.os.Parcel.readException(Parcel.java:1552)
       at com.google.android.gms.location.internal.zzi$zza$zza.zza(Unknown Source)
       at com.google.android.gms.location.internal.zzl.disconnect(Unknown Source:4000)
       at com.google.android.gms.location.internal.zzd$1.zza(Unknown Source:1000)
       at com.google.android.gms.internal.zzpr$zza.zzb(Unknown Source)
       at com.google.android.gms.internal.zzqa.begin(Unknown Source:1000)
       at com.google.android.gms.internal.zzqf.zzd(Unknown Source)
       at com.google.android.gms.internal.zzqd.zzd(Unknown Source)
       at com.google.android.gms.location.internal.zzd.getLastLocation(Unknown Source)
       at com.betvictor.bettingapp.helpers.LocationHelper.startFusedLocationUpdates(LocationHelper.java:1216)
       at com.google.android.gms.internal.zzqd.zzd(Unknown Source:12000)
       at com.google.android.gms.internal.zzqb.zzapm(Unknown Source)
       at com.google.android.gms.internal.zzqb.begin(Unknown Source)
       at com.google.android.gms.internal.zzpu.onConnected(Unknown Source:1000)
       at com.google.android.gms.common.internal.zzk$1.onConnected$79e5e33f(Unknown Source)
       at com.google.android.gms.common.internal.zzd$zzj.zzl(Unknown Source)
       at com.google.android.gms.common.internal.zzd$zza.zzarz(Unknown Source:1000)
       at com.google.android.gms.common.internal.zzd$zze.zzasb(Unknown Source)
       at com.google.android.gms.common.internal.zzd$zzd.handleMessage(Unknown Source)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:5459)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)

应用的权限:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

这就是我管理权利的方式:

    if (ContextCompat.checkSelfPermission(mContext,
            Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        // The user already gave permission
        startLocationActions();
    } else {
        // We need to ask the user for permission
        ActivityCompat.requestPermissions((MainActivity) mContext,
                new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, ACCESS_FINE_LOCATION_PERMISSION);
    }

然后

 if (!mDoWeHaveLocation) {
        final LocationRequest locationRequest = new LocationRequest();
        locationRequest.setInterval(INTERVAL_MILLIS);
        locationRequest.setFastestInterval(FASTEST_INTERVAL_MILLIS);
        locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
        mFusedLocationListener = new com.google.android.gms.location.LocationListener() {
            @Override
            public void onLocationChanged(final Location location) {
                if (!mDoWeHaveLocation) {
                    //do stuff
                }
            }
        };
        LocationServices.FusedLocationApi
                .requestLocationUpdates(mGoogleApiClient, locationRequest, mFusedLocationListener);
    }

有同样问题的人?或者有一个如何复制的线索?

2 个答案:

答案 0 :(得分:0)

只需在AndroidManifest文件中添加ACCESS_FINE_LOCATION权限即可。

答案 1 :(得分:0)

如果您使用的是Android OS 6.0.1设备,GPS位置提供商需要在menifest.xml中为Android 6.0提供ACCESS_FINE_LOCATION权限。

自6.0以来,一些权限被视为“危险”(FINE_LOCATION就是其中之一)。

为了保护用户,他们必须在运行时获得授权,以便用户知道它是否与他的行为有关。您可以在以下链接中查看完整示例:https://www.learn2crack.com/2015/10/android-marshmallow-permissions.html