在Android应用程序中获取用户的位置权限 [英] Get Location Permissions from User in Android Application

查看:1753
本文介绍了在Android应用程序中获取用户的位置权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过typicaly权限框获取用户的实际位置:
像这样:

I´m trying to get the users actual location with the typicaly permissions box: like this:

如果有人知道怎么做,请求答案。

If anyone knows how to make it , pleas answer.

推荐答案

请求运行时使用权限设备当前位置如下:

Ask for permission at runtime to use device current location as below :

if (ActivityCompat.checkSelfPermission(YourActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(YourActivity.this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
      ActivityCompat.requestPermissions(YourActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
      return;
}else{
  // Write you code here if permission already given.
} 

这篇关于在Android应用程序中获取用户的位置权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆