“检查权限”

时间:2015-10-05 09:22:18

标签: android android-permissions

当我在我的项目上运行lint时,我得到了几个与

相关的安全异常
  Cursor managedCursor = mContext.getContentResolver().query(
            URI, null, null, null, null);

   startActivity(callIntent);

显示

  

呼叫需要用户可能拒绝的权限:代码应该   明确检查是否有权限(使用   checkPermission)或明确处理潜力   SecurityException

对于位置我可以通过像这样放置checkselfPermission来解决这个问题,

 if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                            if (mContext.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
                                    || mContext.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
                                locationManager.requestLocationUpdates(
                                        LocationManager.GPS_PROVIDER,
                                        MIN_TIME_BW_UPDATES,
                                        MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                                location = locationManager
                                        .getLastKnownLocation(LocationManager.GPS_PROVIDER);
                            }
                        } else {
                            locationManager.requestLocationUpdates(
                                    LocationManager.GPS_PROVIDER,
                                    MIN_TIME_BW_UPDATES,
                                    MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                            location = locationManager
                                    .getLastKnownLocation(LocationManager.GPS_PROVIDER);

                        }

光标 startActivity 所需的条件(权限)是什么。

SDK版本:23

BuildTool版本:23.0.1

0 个答案:

没有答案