When to request permission at runtime for Android Marshmallow 6.0?

后端 未结 11 980
故里飘歌
故里飘歌 2020-12-06 05:54

I am testing my app on Marshmallow 6.0 and it\'s getting force closed for the android.permission.READ_EXTERNAL_STORAGE, even if it is defined in th

11条回答
  •  抹茶落季
    2020-12-06 06:24

    In my opinion, there is no one correct answer to your question. I strongly suggest you to look at this official permissions patterns page.

    Couple of things suggested by Google :

    "Your permissions strategy depends on the clarity and importance of the permission type you are requesting. These patterns offer different ways of introducing permissions to the user."

    "Critical permissions should be requested up-front. Secondary permissions may be requested in-context."

    "Permissions that are less clear should provide education about what the permission involves, whether done up-front or in context."

    This illustration might give you better understanding.

    Maybe the most crucial thing here is that whether you ask the permission up-front or in the context, you should always keep in mind that these permissions can be revoked anytime by the user (e.g. your app is still running, in background).

    You should make sure that your app doesn't crash just because you asked the permission on the very beginning of the app and assumed that user didn't change his/her preference about that permission.

提交回复
热议问题