confused about android runtime permissions

耗尽温柔 提交于 2019-12-02 01:08:39

I also check when I stop the camera

That is not needed, assuming that you do not try to stop a camera that you never opened. If the user revokes the permission while your app is running, your process is immediately terminated. As a result, you can never lose permissions in a running app. Since you checked for and had permission to open the camera, you already have permission to close it.

if I add this runtime permission checks how does this affect android devices lower than 6.0?

ContextCompat.checkSelfPermission() will return PackageManager.PERMISSION_GRANTED on older devices, assuming that you have the permission listed in the manifest.

So a phone with version 5.0.1 will also get a prompt to give camera permissions?

No.

If I use runtime permissions, do I have to remove the camera permissions in the manifest file?

No. Those elements are necessary on all Android versions.

What if I lower the target and compiling sdk to 22 instead of 23, will android devices above 6.0 won't be able to download my app?

Your compileSdkVersion has no impact on what versions of Android you support. Android 6.0 users will still be able to download your app.

If you lower your targetSdkVersion to 22 or lower, that too has no impact on what versions of Android that you support. Android 6.0 users will still be able to download your app. Doing this would mean that you could skip the runtime permission code. However, bear in mind that you still may not have permission. Users of Android 6.0 devices, running your targetSdkVersion 22 app, will grant the CAMERA permission by default. But, those users can still go into Settings > Apps, find your app, and revoke the permission. With the camera API, you basically cannot open the camera.

Tactically, going with targetSdkVersion of 22 or lower is certainly possible. Eventually, though, something is going to "force your hand" and require you to move to a targetSdkVersion of 23 or higher. So, someday, you will need to deal with the runtime permissions. Whether that is today or some day in the future is up to you do decide.

No if the Permission is in Menifest file. Android having less than 23 sdk won't receive a prompt about the permission, It will be the same like before.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!