Android Question [SOLVED] Should I ever add permissions to the manifest or will the IDE handle that?

Discussion in 'Android Questions' started by Sandman, May 24, 2018.

  1. Sandman

    Sandman Well-Known Member Licensed User

    I'm upgrading my app for API26 and all that, and realized that the List Permissions window not only show permissions the IDE will auto-add, but also show the permissions I have manually specified in the manifest.

    I kind of suspect that the manual permissions in the manifest is leftovers from when I started making this app. I also suspect that I can delete the lot of them and just rely on the IDE to do a good job.Is this correct?

    Can I bring out the axe and remove my manually specified permissions? Or are there edge cases where the IDE misses something that I actually need to add manually? And if the latter, how can I tell what I can delete?
  2. Erel

    Erel Administrator Staff Member Licensed User

    It is not a about the IDE doing a good job or not missing something. The compiler will add all the permissions that are specified in the various types metadata (types used in your program).

    In most cases you do not need to add anything.
    Cases where you need to add permissions:
    - A code snippet based on JavaObject that requires a permission.
    - A library that do not declare all permissions as some are optional.
    - Make sure to see the runtime permissions tutorial as you might need to add the version specific storage permission.
  3. Sandman

    Sandman Well-Known Member Licensed User

    So basically I can do this:
    1. Copy my current manifest to an external file (backup)
    2. Empty the manifest, save and reopen it to get a fresh manifest template
    3. Add back everything from the backup that wasn't related to permissions
    4. Add permissions required by JavaObjects in my code
    5. Add permissions required by any extra libraries I've installed
    6. Change DirRootExternal/DirDefaultExternal to DirInternal/GetSafeDirDefaultExternal to avoid some permissions
    And then I'm done and have a perfect, slim manifest. Correct?

    Follow-up questions:

    How to determine if JavaObjects require permissions

    In my code I have these two JavaObjects:

    Dim channel As JavaObject
    ""Array(channelId, Application.LabelName, ImportanceLevel))
    Dim ctxt As JavaObject
    Dim manager As JavaObject = ctxt.RunMethod("getSystemService"Array("notification"))
    I'm generally clueless when it comes to JavaObject so I don't really know what to look for. I tried googling for permission and the different names in the code, so "permission", "permission getSystemService" and "permission createNotificationChannel". These search terms led me to pages like these:

    None of these pages seemed to indicate anything regarding permissions.

    Please note that I'm not looking for info on this exact JavaObject code. I'm really, really trying to understand the thinking I need to solve this myself and not having to ask on the forum each time. @Erel , how do you know whether some JavaObject requires a permission? Can you look it up somewhere in some reference doc, or is it just something that you have learned over the years through trial and error..?

    How to determine if a Library require permissions

    In my case I use the very nice lib QRCodeReaderView by @Johan Schoeman. Looking at the lib in the very nice B4x Object Browser by @Vader, which lists permissions, I can see none listed. Yet, looking at the forum page for the lib, Johan has specified three required permissions.

    Does this mean that these are the steps to determining what permissions a lib needs?

    - Check the documentation on the forum for the lib
    - Ask the author
    - Test the lib as much as possible in the app and see if it crashes

    Did I miss something? The lib doesn't really specify those things itself?
  4. Erel

    Erel Administrator Staff Member Licensed User

    When I post a snippet based on JavaObject I always include the permissions that need to be added if there are such. If you don't see anything about permissions then they are not required.

    Android documentation.

    Proper libraries include all the required permissions automatically and document any optional permissions in the tutorial.
    QRCodeReaderView properly declares the three required permissions. You can see it in the XML file and in the IDE under Logs - List Permissions.
  5. Sandman

    Sandman Well-Known Member Licensed User

    So basically this?
    1. Go to
    2. Enter the "RunMethod" method name in search box and go to the method in the docs (*)
    3. If the method require a permission, it's listed there. If none is needed, it's not mentioned.
    It's as simple as that, correct?

    (*) Seems it's easier to pick the correct match in the dropdown box than in the full page results.

    Understood, thanks. And it turns out I had an older version of this lib installed, which didn't define the permissions.
  6. Erel

    Erel Administrator Staff Member Licensed User

    Sandman likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice