Android Dev Q Regarding Permission Request - java

Hey all!
So as Android Devs know, Android M introduced a new Permissions system.. I am nearing the end stages of Coding my App, and implementing this Permission Request is one of my final tasks. I just have a few quick questions about the way it works..
Upon starting my App for the first time, the user see's a Welcome screen, with a view pager type of interface with 4 pages containing information about using the App.. The last page will explain to the user that the App needs a Permission to be granted in order to use the App, and upon clicking a "Lets get Started" Button, I will have the Permission Request pop up..
Here are my Questions:
(1) - Am I actually able to Request the Permission on the fly like I descibed above, to be used later at some point, before I actually need to use the Permission? or am I limited to Requesting the Permission at specific times, such as when I actually need it, or at runtime, etc..?
(2) - Once the user Grants the Permission I Request, is it permanent? or will I need to Request Permission yet again if for example they reboot their phone etc?
Huge thanks for the information!

You can request for Marshmallow permissions at any point of time, they are not limited.
Yes, once the user grants the permission it is permanent, so no pop up will need to be generated. Although the user will still be able to manually remove the permission from the Settings app, which will require you to ask for it again next time you'll need it.

Related

How to know that user don't give internet access to our app?

Android system now gives users the decision to give or restrict internet access to selected apps. This is very detrimental to developers, especially for developers that use AdMob and other advertisement services. How to know that users don't give internet access to our app so i can give them warnings?
This is what i mean "Android system now gives users the decision to give or restrict internet access to selected apps":
Internet permission is normal permission in android 12(Which is least preview version of android) too. I don't know what is your problem but if you want to check user's network status, see this document https://developer.android.com/training/basics/network-ops/managing
EDIT
In your case, if turning off switch, android will block network in background. This document will help you https://developer.android.com/training/basics/network-ops/data-saver?hl=en
Forground access will works fine. You're able to access internet switch has been disabled also.

Directly Enable Permission Like Location

I can implement Runtime permission where a dialog appears to the user to allow the permission or deny the permission. But I want The permission will be enabled or allowed in the background without asking the User. Is it possible? is it possible then how to do it? Please explain in Java (Android studio).
in the background without asking the User. Is it possible?
no.
this defeats the point of the permission model - if any random app could just get your location (or any other sensitive permission) without requesting for it, why would apps even bother to implement runtime permissions ?

Android permissions: asking options guide

I apologize in advance for my language and if this thread is a duplicate.
I would like to ask for a 'mini-guide' on android permission asking for 6.0+. The problem that I am personally having is some applications I recently released require permissions like internet and external storage. But the only way I could 'help' the user from going manually to settings -> app settings etc, is launching an intent on button press for the app setting page.
So what I am asking is:
For newest versions of Android (assuming it will work on most older versions too),
is there a way to:
Ask for every permission you need to be accepted before downloading on Play Store and then enabled by default?
Ask on first time app launch to give permanent permissions to app and on positive response, programmatically enable them?
Ask the user for a one-time, dynamic, TEMPORARY, permission request. For example, app1 does not have permission to write to an external storage. On button1 press, ask temporary permission to write to a file in the external storage. If the user clicks button1 again, permission will be asked again.
Again, apologies if this question has been asked before. I want to assure you I did a lot of research, and most of the answers I found didn't seem to work...
Thanks
1) I think its not possible to enable all permissions by default since its a major update in Android 6+ devices to enable users to control runtime permissions the app needed.
For 2 & 3)
For my project I have written a static java class to request android runtime permissions. You can use that if you want. You have to add other permissions as you need in the same pattern as described in the class.
I have provided the Github link below
Github

How to centralize the run time permission when we have multiple activity

Sorry for my bad english.
I have multiple Activity in my app, I need to centralize the runtime app permission.
Do I need to use BaseActivity?
If yes, please suggest me how to handle it in case of many Activity in app.
If no, please suggest better approach to handle it.
I want to reduce the code redundancy. Not interested to write same code again and again with every Activity.
I am looking for negative scenario also where user denied the permission and i have to show rational instead of keep asking to allow permission. and based on that i have to provide message or i have to update UI
Run time permission were introduced to have control over the dangerous resources
So ideally you must be checking for the permission every time you use a resource. This code must not be eliminated.
Then when it comes to request a permission, it is a single line code. I don't think you must be having a trouble with this.
Now comes the tricky part. Handling the permissions that are given. You can definitely have a base class (not recommended) but ideally different permission is used for different purpose.
For example location permission:
In same Activity say Location.java, i might need location permission for getting the address of the person using LatLon values, and in the same activity I am using location permission for live tracking the user.
Now to handle different implementations for same permission, you must have unique permissions codes based on the purpose, but not based on the resource you are accessing permission for. Handling all these things in a base class can be tricky. So ideally you must handle permission in the activity where it belongs. It will keep your code safe and prevent any mix ups with other codes.
Always advisable to read the official docs.
There might be cases where you might get confused with redundancy of the codes and multiple implementations. For that, Android is handling most of the code in its end, as a programmer, least expected is to check for permissions and perform appropriate operations wherever dangerous resources are used.
If you have 10 activities and all of them need location permission.Then I guess it is very crucial permission for your application.
For crucial permission, if not allowed by user you can close your application, hence do it on first activity itself. Like facebook does for various permission. It might be bad experience for user but It is necessary permission for your application.
Just write it once in the first activity and stop application if not permitted by user. A lot of flagship application does that.

Android Preference-Specific Permission Requests

Is there a way to request a specific permission only when the user enables a certain preference?
In my case, I have an option to sync with the calendar to add dates and set reminders (to my knowledge, you can't set reminders in the calendar with Intents). Obviously I need permission to access the calendar, but ONLY when the user enables this option. I'd like to, when the user enables the preference, request permission, then disable the option if permission isn't granted.
No. Unfortunately there is no option to do that.
No checks with the user are done while an application is running: it either was granted a particular permission when installed, and can use that feature as desired, or the permission was not granted and any attempt to use the feature will fail without prompting the user.
http://developer.android.com/guide/topics/security/permissions.html
This is possible since Marshmallow. See video showing best practice to ask for permission from Android Marshmallow
You can find snippets of code allowing you to do this at Android developer guide to requesting permission for Marshmallow and above

Categories

Resources