Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

runtime plugin permissions support?
Started by troylyndon Jan 02 2019 03:29 AM

13 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

troylyndon

[GLOBAL: userInfoPane.html]
troylyndon
  • Contributor

  • 584 posts
  • Corona SDK

I'm looking to implement "android.permission.READ-CONTACTS" only if the user wants to share certain contact records, instead of requesting this permission up-front. I've seen that Android 6.0 and newer will support the removal of requiring this permission at install, so that it will be requested ONLY AFTER the user of my app enters the share contact portion of the app. How can I do this WITHOUT creating a native build?



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,646 posts
  • Enterprise

Look at the SampleCode/Media/Camera sample app. It has an example on how to request permissions at runtime.

 

 

Rob



[TOPIC: post.html]
#3

troylyndon

[GLOBAL: userInfoPane.html]
troylyndon
  • Contributor

  • 584 posts
  • Corona SDK

@Rob, thank you.



[TOPIC: post.html]
#4

troylyndon

[GLOBAL: userInfoPane.html]
troylyndon
  • Contributor

  • 584 posts
  • Corona SDK

@Rob,

Okay, I've implemented it. But there is one important question that needs answering for BUILD.SETTINGS in order to properly configure READ_CONTACTS so that it is NOT REQUIRED.

In the sample Camera app you sent me, we have this:
 

	android =
	{
		usesPermissions =
		{
			"android.permission.CAMERA",
			"android.permission.WRITE_EXTERNAL_STORAGE",
		},
		usesFeatures =
		{
			{ name = "android.hardware.camera", required = true },
			{ name = "android.hardware.camera.front", required = false },
		},
	},

So, how do I configure this for READ_CONTACTS? This is the last thing that needs answering to make this work. So far, I have this:
 

          usesPermissions =
          {
              "android.permission.READ_CONTACTS",     --ask for this now when needed
          },
          
	  usesFeatures =
          {
            { name = "android.???????.?????", required = false }
          },


[TOPIC: post.html]
#5

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,646 posts
  • Enterprise

The usesFeatures is a way for Google to rule out devices that don't meet your minimum hardware requirements. The code above lets Google Play know to hide your app if the user's device doesn't have a camera. I don't believe there is a feature you need to specify for contacts since that's all software driven.

 

Rob 



[TOPIC: post.html]
#6

troylyndon

[GLOBAL: userInfoPane.html]
troylyndon
  • Contributor

  • 584 posts
  • Corona SDK

@Rob,

So, here is the problem. If I include ""android.permission.READ_CONTACTS" in usesPermissions, the user is prompted that the app "REQUIRES" access to device contacts. As a result, many people may not use our app. When I remove it, the default is "DENIED" when my app requests access with an error message that READ_CONTACTS is not in the Manifest.xml.

 

My goal is to only ask for the READ_CONTACTS permission AFTER they have indicated a desire to share their contacts.

 

The reason that Google implemented the "required = FALSE" feature is so that apps that run fine and don't need access to a permission unless used, can be installed without alerting the app user that their contacts could be accessed until it is necessary.

How can I solve this? usesFeatures =
{
{ name = "android.???????.?????", required = false }
},



[TOPIC: post.html]
#7

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,646 posts
  • Enterprise

You are right in that Google makes hardware features like the camera optional, which is why there is a required = false. But these are all hardware features. Contacts is not included.

 

https://developer.android.com/guide/topics/manifest/uses-feature-element

 

I don't know if you've seen this blog post or not:

 

https://coronalabs.com/blog/2016/02/23/breaking-change-android-6-and-device-ids/

 

But it may provide you with more information about how to do this.

 

Rob



[TOPIC: post.html]
#8

troylyndon

[GLOBAL: userInfoPane.html]
troylyndon
  • Contributor

  • 584 posts
  • Corona SDK

@Rob, from what I can see, you are right in that there is no way to ask the user for permission to open Contacts. It must be requested up-front at the apps initial install, unless you know of another way.



[TOPIC: post.html]
#9

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,646 posts
  • Enterprise

You follow the instructions in the blog post and in the sample I showed you. You detect if you're on Android API 23 or higher and if so, fetch already granted permissions and see if READ_CONTACTS have been granted or not. If not, ask for permission at run time.

 

Rob



[TOPIC: post.html]
#10

troylyndon

[GLOBAL: userInfoPane.html]
troylyndon
  • Contributor

  • 584 posts
  • Corona SDK

Actually, from what I can tell, on my Android 8, is there is no way to attempt to get READ_CONTACTS at runtime. It must be included in the manifest.xml. So, the solution is include them in the manifest and because it defaults to disabled, give the user instructions on how to enable Contacts after checking if the permissions have not been granted.



[TOPIC: post.html]
#11

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,065 posts
  • Corona SDK

Why oh why do you want this? Just don't do it.



[TOPIC: post.html]
#12

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,646 posts
  • Enterprise

Troy, Google changed their permission system starting with Android 6. They have not made a significant change since. Android 8 certainly reads permissions and allows you request them at runtime. 

 

Are you getting an error?

 

Can you produce a sample app with what you're doing and share it here so others can help? I don't have an Android 8 device.

 

Rob



[TOPIC: post.html]
#13

troylyndon

[GLOBAL: userInfoPane.html]
troylyndon
  • Contributor

  • 584 posts
  • Corona SDK

@SGS, its an option if the gamer wants to share from their contacts, if they don't want to share via FB Post.
@Rob, I'll try and create a sample app. The issue is that if I include the READ_CONTACTS in the build.settings permissions (which Corona uses to create the manifest.xml), it will work. But we may lose some players who don't want to approve access to Contacts before installing the game. If I don't include READ_CONTACTS in the permissions, I do get a developer error. So as I said above, we include it in the build.settings permissions and because my Android defaults to the feature as 'disabled', the gamer gets a message about how to change it via SETTINGS -> APPS -> MYGAME ->Contacts (on/off toggle)



[TOPIC: post.html]
#14

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,646 posts
  • Enterprise

I want to help you, but I need a starting point.

 

Rob




[topic_controls]
[/topic_controls]