本文介绍了客户端必须具有ACCESS_FINE_LOCATION权限才能请求android 6中的PRIORITY_HIGH_ACCURACY位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我最近在装有Android 6.0版的设备上发生了一个问题
I have a problem that happen recently on devices with android version 6.0
我遇到以下崩溃
java.lang.SecurityException: Client must have ACCESS_FINE_LOCATION permission to request PRIORITY_HIGH_ACCURACY locations.
at android.os.Parcel.readException(Parcel.java:1627)
at android.os.Parcel.readException(Parcel.java:1579)
at ub.a(:com.google.android.gms.DynamiteModulesB:1191)
at to.a(:com.google.android.gms.DynamiteModulesB:2110)
at lw.b(:com.google.android.gms.DynamiteModulesB:148)
at ml.b(:com.google.android.gms.DynamiteModulesB:1164)
at nf.b(:com.google.android.gms.DynamiteModulesB:260)
at na.b(:com.google.android.gms.DynamiteModulesB:324)
at tn.a(:com.google.android.gms.DynamiteModulesB:78)
at maps.af.L.a(Unknown Source)
at na.a(:com.google.android.gms.DynamiteModulesB:13201)
at mo.g(:com.google.android.gms.DynamiteModulesB:499)
at mo.a(:com.google.android.gms.DynamiteModulesB:435)
at mh.a(:com.google.android.gms.DynamiteModulesB:1437)
at pj.a(:com.google.android.gms.DynamiteModulesB:227)
at oz.a(:com.google.android.gms.DynamiteModulesB:780)
at oq.a(:com.google.android.gms.DynamiteModulesB:1829)
at ot.handleMessage(:com.google.android.gms.DynamiteModulesB:5339)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:234)
at android.app.ActivityThread.main(ActivityThread.java:5526)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
任何人都可以帮忙吗?
推荐答案
以下是示例代码,可用于请求运行时权限:
Here is a sample code that you can use to request for Runtime permissions:
private static final int MY_PERMISSIONS_REQUEST_READ_FINE_LOCATION = 100;
和
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission( getApplicationContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.ACCESS_FINE_LOCATION)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.READ_CONTACTS},
MY_PERMISSION_REQUEST_READ_FINE_LOCATION);
// MY_PERMISSION_REQUEST_READ_FINE_LOCATION is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
然后您可以在此处接收请求:
Then you can receive the request here:
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSION_REQUEST_READ_FINE_LOCATION: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay! Do the contacts-related task you need to do.
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
}
return;
}
// other 'case' lines to check for other
// permissions this app might request
}
}
您可以在活动中轻松地调用它,但我强烈建议您阅读文档以获得更好的主意.
You can easily call this in your activity but I would highly recommend you read the documentation here to get a better idea.
我希望这会有所帮助!
这篇关于客户端必须具有ACCESS_FINE_LOCATION权限才能请求android 6中的PRIORITY_HIGH_ACCURACY位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!