Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-12565

Android: Not possible to retrieve birthday for contact

    Details

      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

        Attachments

          Activity

            People

            • Assignee:
              pwang Ping Wang
              Reporter:
              dsefton Daniel Sefton
              Reviewer:
              Hieu Pham
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-15531
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Integration