版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Gdeer/article/details/88841207
发现自己的应用 targetSdkVersion 小于 23,但启动时还是会弹定位权限申请框。
新创建一个 targetSdkVersion 小于 23 的新项目:
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
String provider = LocationManager.GPS_PROVIDER;
Location location = locationManager.getLastKnownLocation(provider);
执行 getLastKnownLocation 后,就会弹权限申请框。
- 在 AndroidManifest 中声明权限,并申请定位信息,会弹申请框
- 只在 AndroidManifest 中声明权限,不申请,不会弹
- 不在 AndroidManifest 中声明权限,申请,会抛异常(java.lang.SecurityException: “gps” location provider requires ACCESS_FINE_LOCATION permission.)
自己的应用:
去除 AndroidManifest 中的权限,不会弹申请框,应该是使用的 sdk 里做了 try/catch。