[TIMOB-19885] Android 6.0 : Asking for contacts permissions fails with "one or more permissions denied" with SDK 5.1.0.v20151104190037
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2015-11-12T02:14:06.000+0000 |
Affected Version/s | Release 5.1.0 |
Fix Version/s | Release 5.1.0, Release 5.2.0 |
Components | Android |
Labels | qe-5.1.0, regression |
Reporter | Lokesh Choudhary |
Assignee | Hieu Pham |
Created | 2015-11-06T02:31:21.000+0000 |
Updated | 2016-05-27T22:46:41.000+0000 |
Description
*This is a regression. This issue is not seen with SDK 5.1.0.v20151104153625*
Description:
1. Use the code below in your tiapp.xml & build for android 6.0 device:
var win = Ti.UI.createWindow();
win.addEventListener("open", function(e) {
if (Ti.Contacts.hasContactsPermissions()) {
Ti.API.info("People: " + JSON.stringify(Ti.Contacts.getAllPeople()));
} else {
Ti.Contacts.requestContactsPermissions(function(e) {
if (e.success === true) {
alert("Access granted");
Ti.API.info("People: " + JSON.stringify(Ti.Contacts.getAllPeople()));
} else {
alert("Access denied, error: " + e.error);
}
});
}
});
win.open();
2. After the app launches grant permissions to access contacts.
3. Observe the alert you get after.
Actual Results:
1. We see alert "Access denied, error: ContactsOne or more permissions were denied" *Attached screenshot for the alert & the permissions in settings for the app.*Expected Results:
1. We should see success.Attachments
File | Date | Size |
---|---|---|
Screenshot_20151105-181714.png | 2015-11-06T02:32:01.000+0000 | 64681 |
Screenshot_20151105-181723.png | 2015-11-06T02:32:03.000+0000 | 88483 |
Tried this and unable to reproduce this. I got
Access granted
. Using Android 6.0, Nexus 6.[~hpham] Could you see if you can reproduce this as well?
I can also reproduce this issue. Mac OSX El Capitan 10.11 (15A284) Ti SDK: 5.1.0.v20151104190037 Appc NPM: 4.2.1 Appc CLI: 5.1.0-43 Ti CLI: 5.0.4 Alloy: 1.7.23 Xcode 7.1(7B91b) Node v0.12.7 production
I tried it, couldn't reproduce this either. Edit: Ok, I figured out what the problem is. This problem will occur when your AndroidManifest is missing either READ_CONTACT, or WRITE_CONTACT permission. Usually the CLI is pretty good at adding these permissions, but contacts is a special case. Depending on which method you use, sometimes only READ_CONTACT permission is included in the manifest. This causes the problem.
master PR: https://github.com/appcelerator/titanium_mobile/pull/7413 5.1.X PR: https://github.com/appcelerator/titanium_mobile/pull/7414
Both master and 5.1.X PR merged.
[~hpham], This piece of code throws same errors when getting contact permissions:
AndroidManifest has following permissions:
Notice it does not have contact permissions added. Do we need to have a code to access contacts in the permissions code i.e Ti.Contacts.hasContactsPermissions or Ti.Contacts.requestContactsPermissions to get a success? Reopening for the time being. Environment: Appc Studio : 4.4.0.201511101919 Ti SDK : 5.1.0.v20151110202023 Ti CLI : 5.0.5 Alloy : 1.7.24 MAC Yosemite : 10.10.5 Appc NPM : 4.2.1 Appc CLI : 5.1.0-50 Node: v0.10.37 Nexus 6 - Android 6.0
Well, that's expected. You're not using any contacts method, so no permission is given, therefore your access is denied. This will be the case for ALL permissions, not just contacts. If you request a permission but not actually using an API regarding that permission, your access will be denied. Edit: Keep in mind that the AndroidManifest is generated at compile time, and we append needed permissions based on API usage. Checking and asking for permissions do NOT trigger the permissions to be added to the manifest - only APIs that require permissions to work do.
So the issue is not fixed running the code in the description goes not get the contact info & shows
In logcat I get this:
Android Manifest has the READ_CONTACTS permissions:
Reopening. Environment: Appc Studio : 4.4.0.201511101919 Ti SDK : 5.1.0.v20151110202023 Ti CLI : 5.0.5 Alloy : 1.7.24 MAC Yosemite : 10.10.5 Appc NPM : 4.2.1 Appc CLI : 5.1.0-50 Node: v0.10.37 Nexus 6 - Android 6.0
master PR: https://github.com/appcelerator/titanium_mobile/pull/7427 5_1_X PR: https://github.com/appcelerator/titanium_mobile/pull/7428
Code reviewed and functionally tested. Able to see contacts with test code in description. Both PR Merged.
Verified the fix. Permissions are granted successfully & we can see the contacts. Closing. Environment: Appc Studio : 4.4.0.201511101919 Ti SDK : 5.1.0.v20151111182050, 5.2.0.v20151112112825 Ti CLI : 5.0.5 Alloy : 1.7.24 MAC Yosemite : 10.10.5 Appc NPM : 4.2.1 Appc CLI : 5.1.0-52 Node: v0.10.37 Nexus 6 - Android 6.0