Android - 请求运行时权限

时间:2016-05-27 06:37:04

标签: android permissions

我试图了解如何在Android中为“危险权限”(如位置)请求运行时权限。

我的理解是代码应该像这样

public void checkPermission(){ 
  if (ActivityCompat.checkSelfPermission(..) == PackageManager.PERMISSION_GRANTED){

    getLocation();

  } else {

    ActivityCompat.requestPermissions(..);

  }
}

public void onRequestPermissionsResult(..){
  switch (requestCode) {
    case MY_PERMISSIONS_REQUEST: {
      if (..) {
                // permission was granted, yay!
                getLocation();
            } else {
                // permission denied, boo!
            }
            return;
        }
     }
}

public Location getLocation(){
  locationManager.requestLocationUpdates(..)
  ..
}

问题是,这段代码在locationManager告诉我必须请求位置许可时给我错误

那么这个序列的问题是什么?

1 个答案:

答案 0 :(得分:0)

试试这个,它对我有用

public static List<List<Model>> Data = new List<List<Model>>()
{
    new List<Model>()
    { 
        new Model{Cover= false, Supplied= false, Coverers= "A"},
        new Model{Cover= true, Supplied= false, Coverers= "B"},
    },
    new List<Model>()
    { 
        new Model{Cover= false, Supplied= true, Coverers= "C"},
        new Model{Cover= false, Supplied= false, Coverers= "D"},
    },
};