0

I couldn't find the answer to this anywhere, so please help.

Suppose I have 10 activities that needs various dangerous permissions in my Android application.

Activity-1 needs Dangerous Permission-1
Activity-2 needs Dangerous Permission-2
...
Activity-10 needs Dangerous Permission-10 ect.

Question: If I create an 11th activity [lets say PermissionManager.java] and gets all the 10 permissions from user dynamically one after another, will the application work?

Or

Is it like each activity should request the permissions it requires?

CDspace
  • 2,639
  • 18
  • 30
  • 36
George
  • 1,330
  • 1
  • 9
  • 12

6 Answers6

2

Suppose I have 10 activities that needs various dangerous permissions in my Android application. Activity-1 needs Dangerous Permission-1

Activity is just UI element. It does nothing dangerous by itself, so you do not need any permission in context of Activity. You however need permissions per certain type of operations, but you can do them in many places in your app. Activity got in fact nothing with it, except that it usually holds the widget that i.e. shows results of that operation.

If I create an 11th activity [lets say PermissionManager.java] and gets all the 10 permissions from user dynamically one after another, will the application work?

Permission is not granted per Activity. It's granted per your whole application, so once you got it granted you can do that operation wherever in your app without asking. Random related docs:

Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
1

You can ask your permission anywhere you like, as long as it's granted before doing your 'dangerous' operation.

There are even libraries like: https://github.com/k0shk0sh/PermissionHelper who do it for you

Stefan
  • 2,098
  • 2
  • 18
  • 29
1

If I create an activity and gets all the 10 permissions from user dynamically one after another, will the application work?

Answer:

Q1: Yes application will work..if u request multiple permission all at once.

requestPermissions(new String[]{
                            Manifest.permission.READ_CONTACTS,
                            Manifest.permission.ACCESS_FINE_LOCATION},
                    REQUEST_CODE);

See this For Multiple permission approach at once.

Is it like each activity should request the permissions it requires?

Q2: It provides a better user experience if each activity request the permissions it requires. then it is easy for u to handle also. You can disable feature regarding that permission.

For more info see the official Documentation

Community
  • 1
  • 1
rafsanahmad007
  • 23,683
  • 6
  • 47
  • 62
0

The App Manifest or AndroidManifest.xml ought to be used to manage your app permissions.

  • This is handled when the user downloads your app, and all permissions are set up then.
  • It declares the permissions that the application must have in order to access protected parts of the API and interact with other applications.
  • It also declares the permissions that others are required to have in order to interact with the application's components.

See App Manifest on Android Developer

Community
  • 1
  • 1
BenJaminSila
  • 593
  • 5
  • 12
0

Your should ask for permission exactly when it needs it. It is possible that there is a feature of an activity which requires a permission, but what if the user never uses that feature? It would be unintuitive for the user to be asked for a permission he does not understand the reason of. Also, it is recommendable to tell your users why the app needs the permission and what the user will gain by granting it.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
0

Try this library it is very good i just used this in my project 2 days back :--

https://android-arsenal.com/details/1/5364

Varun Jain
  • 171
  • 2
  • 14