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

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

问题描述

我正在尝试使用典型的权限框获取用户的实际位置:像这样:

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天全站免登陆