Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-12565] Android: Not possible to retrieve birthday for contact

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2013-03-23T01:18:28.000+0000
Affected Version/sRelease 3.0.0
Fix Version/sRelease 3.1.0, 2013 Sprint 05 API, 2013 Sprint 05
ComponentsAndroid
LabelsSupportTeam, parity, qe-closed-3.1.0, qe-testadded
ReporterDaniel Sefton
AssigneePing Wang
Created2013-02-04T19:15:37.000+0000
Updated2013-10-04T10:40:35.000+0000

Description

*Problem description* Titanium.Contacts.Person.getBirthday() returns null for a contact on Android, works fine on iOS. *Test case*
var tabGroup = Titanium.UI.createTabGroup();

var win = Titanium.UI.createWindow({
	backgroundColor : "#fff",
	tabBarHidden : true
});

var tab1 = Titanium.UI.createTab({
	title : 'Tab 1',
	window : win
});

var android = (Ti.Platform.osname === 'android');

var activityIndicator;
if (android) {
	activityIndicator = Ti.UI.createActivityIndicator({
		message : 'Loading all contacts, please wait...'
	});
	activityIndicator.show();
}

var makeTable = function() {
	Ti.API.info("Making table...");
	var people = Titanium.Contacts.getAllPeople();
	var rows = [];
	for (var i = 0; i < people.length; i++) {
		Ti.API.info("People object is: " + people[i]);
		var title = people[i].fullName;
		if (!title || title.length === 0) {
			title = "(no name)";
		}
		rows[i] = Ti.UI.createTableViewRow({
			title : title,
			person : people[i],
			hasChild : true
		});
		rows[i].addEventListener('click', function(e) {
			var display = Ti.UI.createWindow({
				backgroundColor : 'white',
				title : e.row.person.fullName
			});
			display.add(Ti.UI.createLabel({
				text : "Birthday: " + e.row.person.getBirthday()
			}));
			tab1.open(display, {
				animated : true
			});
		});
	}
	return rows;
};

var tableview = Ti.UI.createTableView({
	data : makeTable()
});

win.add(tableview);

if (android && activityIndicator) {
	activityIndicator.hide();
}

tabGroup.addTab(tab1);
tabGroup.open();
*Native example*
private String getBirthday2(long contactId) {
    // read birthday
    Cursor c = getContentResolver().query(
        Data.CONTENT_URI,
        new String[] { Event.DATA },
        Data.CONTACT_ID + "=" + contactId + " AND " + Data.MIMETYPE + "= '" + Event.CONTENT_ITEM_TYPE + "' AND "
            + Event.TYPE + "=" + Event.TYPE_BIRTHDAY, null, Data.DISPLAY_NAME);
    if (c != null) {
      try {
        if (c.moveToFirst()) {
          return c.getString(0);
        }
      } finally {
        c.close();
      }
    }
    throw new IllegalStateException();
  }
*Native discussion* http://stackoverflow.com/questions/8579883/get-birthday-for-each-contact-in-android-application http://stackoverflow.com/questions/2396975/what-is-the-fieldname-to-store-a-birthday-for-a-contact-entry *Community discussion* http://developer.appcelerator.com/question/123848/coud-not-retrieve-birthday-from-picked-contact

Comments

  1. Ping Wang 2013-03-07

    PR: https://github.com/appcelerator/titanium_mobile/pull/3940
  2. Anshu Mittal 2013-03-21

    Tested with: SDK:3.1.0.v20130319222852 Studio: 3.1.0.201303091040 Device: Samsung Galaxy note(2.3.6) On Android, Titanium.Contacts.Person.getBirthday() still returns undefined
  3. Ping Wang 2013-03-21

    Anshu, can you check if the contacts have already had the birthday set in the phone? If no birthday is set to the contact, it will surely return undefined.
  4. Anshu Mittal 2013-03-22

    Yes, I created a contact and added b'dayto this contact to verify this bug but still returned undefined.
  5. Ping Wang 2013-03-22

    Hi Anshu, this PR was merged on 3/20/2013. You used the SDK from 3/19/2013 so you can still reproduce the issue. Can you use the latest SDK to test again?
  6. Allen Yeung 2013-03-23

    [~amittal] please retest this and reopen it if you are still seeing it with the latest sdk.
  7. Anshu Mittal 2013-04-11

    Tested with: SDK: 3.1.0.v20130409124549 Studio:3.1.0.201304011603 Device: Samsung galaxy note(v 2.3.6) OS: OSX 10.7.5 works as expected

JSON Source