-5

Google allows the permission at run time and it allows the user to allow or deny the permission.

When user installs the app the permissions should automatically be ON, it should not be asked to user.

How can i get this functionality?

Thank you.

Arjun Shah
  • 41
  • 3
  • 4
    If you could do those things, there wouldn't really be any point to the new permissions model. The best you can do is set the `targetSdkVersion` to less than 23. Your app will get the permissions at installation, but you can't stop the user from revoking them manually. – Mike M. Sep 16 '16 at 10:56
  • 1
    Once the user gives the permission the android system does not ask for it again and again, it will only ask if you re-install the App – Kaveesh Kanwal Sep 16 '16 at 10:57
  • You have to ask for permission untill user **allow** it, otherwise your task related to those permission will not complete. Best of luck. – Rahul Sharma Sep 16 '16 at 10:57
  • before doing task add code for checking its relative permission. – Sohail Zahid Sep 16 '16 at 10:57
  • @RahulSharma actually i don't have to ask user about permissions it should be on automatically – Arjun Shah Sep 16 '16 at 10:59
  • No, for M you have to explicitly ask user for permissions, if the user denies it then handle the required functionality in your code – Kaveesh Kanwal Sep 16 '16 at 11:00
  • 1
    Well, I initially misread your questions and misspoke slightly, so #1 is possible with a `targetSdkVersion` less than 23. I don't really believe you regarding #2, though. :-) – Mike M. Sep 16 '16 at 11:01
  • @MikeM. it is not possible by setting targetSdkVersion. – Arjun Shah Sep 16 '16 at 11:23
  • "it is not possible by setting targetSdkVersion" -- your item #1 certainly is. Your item #2 is not, but that is not possible at all. – CommonsWare Sep 16 '16 at 11:25
  • Well, I guess it depends on exactly what you mean by "not be asked to user". They'll be presented the permissions at installation, but you won't need to request them at runtime, if the `targetSdkVersion` is less than 23. – Mike M. Sep 16 '16 at 11:26
  • Sorry I misunderstood it. Now Finally got it, that it can't be done. – Arjun Shah Sep 16 '16 at 11:40
  • target version >=23 needs runtime permissions. And ideally your target SDK must always be the latest one provided by google. – Mohammed Atif Sep 16 '16 at 11:42
  • Hello @ArjunShah try this it will help you http://stackoverflow.com/a/41221852/5488468 – Bipin Bharti Dec 20 '16 at 10:56

3 Answers3

2

It is not possible. If user not allow permission then app cant access resource related to particular permission. It is done by google for security purpose.

D.J
  • 1,439
  • 1
  • 12
  • 23
1

It is not possible to do so on marsh mallow, as it is fully based on runtime permissions.It increases users security.Your queries are supported only to Versions below marshmallow.Try having target version as 22 and run your app.

raasesh
  • 161
  • 11
1

When user installs the app the permissions should automatically be ON, it should not be asked to user.

Have a targetSdkVersion below 23. This is not a viable long-term solution, as eventually something will force your hand to have a targetSdkVersion of 23 or higher.

You cite OlaCabs as an example of the behavior that you want. OlaCabs has a targetSdkVersion of 22.

How can I set default permission in marshmallow so that if user sets off the permission manually and again when user opens the app the permission should be ON and the permissions should not be ask to user, it should be directly ON.

That is not possible. For example, with OlaCabs, after installing it but before running it, I revoked its rights to access contacts, location, phone, SMS, and storage. I then ran OlaCabs, and it crashed, because I had revoked its access to location data, and the authors of OlaCabs do not check to see whether they have permission first. OlaCabs does not magically cause those permissions to be re-granted.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I tried it by setting targetSdkVersion but its not working – Arjun Shah Sep 16 '16 at 11:34
  • @ArjunShah: Then you have some other issue with your app. For example, perhaps you are setting the `targetSdkVersion` in both your manifest and `build.gradle` (the value from `build.gradle` wins). Also, be sure to fully uninstall and reinstall the app -- the build process should warn you about this and do that for you, when you lower your `targetSdkVersion`. – CommonsWare Sep 16 '16 at 11:40