运行时间权限以访问精细位置

时间:2018-05-13 22:21:36

标签: android permissions maps

我正在为地图生成一个项目并检查我尝试使用的权限,如果对ContextCompat.checkSelfPermission的声明与工作室不接受

我的代码如下:

private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION;

if (ContextCompat.checkSelfPermission(this,getApplicationContext(),FINE_LOCATION)==
          PackageManager.PERMISSION_GRANTED){

任何建议?

1 个答案:

答案 0 :(得分:0)

确保从Manifest

导入以下import android.Manifest;
 private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION;

并改变这个

if (ContextCompat.checkSelfPermission(this,getApplicationContext(),FINE_LOCATION)==
          PackageManager.PERMISSION_GRANTED){

if (ContextCompat.checkSelfPermission(this,FINE_LOCATION)==
                    PackageManager.PERMISSION_GRANTED){

现在它会起作用。谢谢!