Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19887] Android 6.0: Issues with getting contacts info on android 6.0

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionFixed
Resolution Date2015-11-12T19:37:41.000+0000
Affected Version/sRelease 5.1.0
Fix Version/sn/a
ComponentsAndroid
Labelsqe-5.1.0
ReporterLokesh Choudhary
AssigneeChee Kiat Ng
Created2015-11-06T19:41:59.000+0000
Updated2016-05-27T22:46:42.000+0000

Description

Description:

1. There are various issues while you try to get contacts info from android 6.0: *Case 1*: Run the code below on android 6.0 device which has contacts:
var win = Ti.UI.createWindow();
win.addEventListener("open", function(e) {
    if (Ti.Contacts.hasContactsPermissions()) {
       display();
    } else {
       Ti.Contacts.requestContactsPermissions(function(e) {
           if (e.success === true) {
              display();         
           } else {
              alert("Access denied, error: " + e.error);
           }
       });
    }
});


function display(){
	var singleValue = [
	  'recordId', 'firstName', 'middleName', 'lastName', 'fullName', 'prefix', 'suffix', 
	  'nickname', 'firstPhonetic', 'middlePhonetic', 'lastPhonetic', 'organization', 
	  'jobTitle', 'department', 'note', 'birthday', 'created', 'modified', 'kind'
	];
	var multiValue = [
	  'email', 'address', 'phone', 'instantMessage', 'relatedNames', 'date', 'url'
	];
	var people = Ti.Contacts.getAllPeople(3);
	Ti.API.info('Total contacts: ' + people.length);
	for (var i=0, ilen=people.length; i<ilen; i++){
	  Ti.API.info('---------------------');
	  var person = people[i];
	  for (var j=0, jlen=singleValue.length; j<jlen; j++){
	    Ti.API.info(singleValue[j] + ': ' + person[singleValue[j]]);
	  }
	  for (var j=0, jlen=multiValue.length; j<jlen; j++){
	    Ti.API.info(multiValue[j] + ': ' + JSON.stringify(person[multiValue[j]]));
	  }
	}
}
win.open();
2. Let the app launch. 3. Grant permissions to access contacts.

Actual Result:

1. We get runtime error "Can't read property length of null". 2. This works fine on android 5.1.1. 3. In logcat I see these logs:
11-06 11:25:22.326: W/TiCommonContactsApi(11772): (KrollRuntimeThread) [231,231] Contact permissions are missing
11-06 11:25:22.327: W/TiCommonContactsApi(11772): (KrollRuntimeThread) [1,232] Contact permissions are missing
11-06 11:25:22.331: I/ActivityManager(864): START u0 {act=android.content.pm.action.REQUEST_PERMISSIONS pkg=com.google.android.packageinstaller cmp=com.google.android.packageinstaller/com.android.packageinstaller.permission.ui.GrantPermissionsActivity (has extras)} from uid 10135 on display 0
11-06 11:25:22.461: I/Keyboard.Facilitator(1922): onFinishInput()
11-06 11:25:22.480: I/ActivityManager(864): Displayed com.google.android.packageinstaller/com.android.packageinstaller.permission.ui.GrantPermissionsActivity: +113ms (total +2s311ms)
11-06 11:25:23.469: W/TypeConverter(11772): jsObjectToJavaKrollDict returning null.
11-06 11:25:23.471: W/TiCommonContactsApi(11772): (KrollRuntimeThread) [1144,1376] Contact permissions are missing
11-06 11:25:23.471: E/TiContacts5(11772): (KrollRuntimeThread) [0,1376] Contacts permissions missing
11-06 11:25:23.471: D/audio_hw_primary(378): out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
11-06 11:25:23.473: I/TiAPI(11772):  ---------------------
The issue might be that even after granting permissions in reality the permissions are not really granted. *Case 2*: Run the code below on android 6.0 device which has contacts:
var win = Ti.UI.createWindow();
win.addEventListener("open", function(e) {
    if (Ti.Contacts.hasContactsPermissions()) {
       display();
    } else {
       Ti.Contacts.requestContactsPermissions(function(e) {
           if (e.success === true) {
              display();         
           } else {
              alert("Access denied, error: " + e.error);
           }
       });
    }
});


function display(){
	var btn = Ti.UI.createButton({
	       title: 'contacts'
	});
	
	btn.addEventListener('click', function() {
	    Ti.Contacts.showContacts({
	        selectedPerson: function(e) {
	
	            Ti.API.info('FullName of Selected' + e.person.fullName);
	            Ti.API.info('Organization of Selected' + e.person.organization);
	            Ti.API.info('Phone of Selected' + e.person.phone);
	            Ti.API.info('Email of Selected' + e.person.email);
	            Ti.API.info('Address of Selected' + e.person.address);
	            Ti.API.info('Phone of Selected' + e.person.phone);
	            Ti.API.info('NickName of Selected' + e.person.nickname);
	            Ti.API.info('Website of Selected' + e.person.url);
	            Ti.API.info('Related Names of Selected' + e.person.relatedNames);
	            Ti.API.info('Notes of Selected' + e.person.note);
	            //alert('FullName of Selected ' + e.person.fullName);
	
	        }
	    });
	});
	
	win.add(btn);
}
win.open();
2. Let the app launch. 3. Grant permissions to access contacts.

Actual Result:

1. We get runtime error "Can't read property fullName of null" & so on for other properties as well. 2. This works fine on android 5.1.1. 3. In logcat I see:
11-06 11:33:54.157: W/TiCommonContactsApi(12143): (main) [2506,7641] Contact permissions are missing
11-06 11:33:54.192: E/TiExceptionHandler(12143): (main) [35,7676] ----- Titanium Javascript Runtime Error -----
11-06 11:33:54.193: E/TiExceptionHandler(12143): (main) [1,7677] - In app.js:26,59
11-06 11:33:54.193: E/TiExceptionHandler(12143): (main) [0,7677] - Message: Uncaught TypeError: Cannot read property 'fullName' of null
11-06 11:33:54.193: E/TiExceptionHandler(12143): (main) [0,7677] - Source: 	            Ti.API.info('FullName of Selected' + e.person.fullName);
11-06 11:33:54.223: E/V8Exception(12143): Exception occurred at app.js:26: Uncaught TypeError: Cannot read property 'fullName' of null
This also shows the permissions granting is sketchy.

Expected Results:

1. We should be able to read contacts & all the properties of contact on android 6.0

Attachments

FileDateSize
Screenshot_20151106-113702.png2015-11-06T19:41:38.000+0000104603

Comments

  1. Lokesh Choudhary 2015-11-12

    This issue got fixed with TIMOB-19885. Closing. Environment: Appc Studio : 4.4.0.201511101919 Ti SDK : 5.1.0.v20151111182050 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

JSON Source