【发布时间】:2016-06-24 05:23:39
【问题描述】:
我正在尝试创建一个应用程序。应用程序每次打开应用程序时都会询问 Marsh Mallow 中的位置访问权限。请建议解决我的问题的最佳流程。使用以下代码-
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
//for marshmallow
final int LOCATION_PERMISSION_REQUEST_CODE = 100;
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_COARSE_LOCATION},
LOCATION_PERMISSION_REQUEST_CODE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mMap.setMyLocationEnabled(true);
buildGoogleApiClient();
mGoogleApiClient.connect();
}
谢谢。
【问题讨论】:
-
您已经授权了吗?如果没有,在执行此类任务之前征求许可是正常的。
-
它的 bczz 你每次都在征求许可
-
在询问权限之前检查它是否已经被用户授予然后询问..试试这个库:github.com/UttamPanchasara/RuntimePermission
-
在我的回答中查看@Uttams 的想法
标签: java android android-6.0-marshmallow