Qamran Rajput Qamran Rajput - 4 months ago 13
Android Question

different result of event.getCreator() when on kitkat and lollipop

event.getCreator();


does not return
displayName



(displayName:Qamran Rajput,email:qami1502@gmail.com,self:true) Kitkat HTC DESIRE 820

(email:qami1502@gmail.com,self:true) lollipop LG G3


Both using same Google Play Services Versions Can any one suggest how to tackle this issue please.

private List<String> getDataFromApi() throws IOException, ParseException {
// List the next 10 events from the primary calendar.
DateTime now = new DateTime(System.currentTimeMillis());
List<String> eventStrings = new ArrayList<String>();
Events events = mService.events().list("primary")
.setMaxResults(30)
.setTimeMin(now)
.setOrderBy("startTime")
.setSingleEvents(true)
.execute();
List<Event> items = events.getItems();

for (Event event : items) {

String id = event.getId();
DateTime start = event.getStart().getDateTime();
if (start == null) {
// All-day events don't have start times, so just use
// the start date.
start = event.getStart().getDate();
}
DateTime end = event.getEnd().getDateTime();

String eventTitle = event.getSummary();
String Creator = String.valueOf(event.getCreator());//string displayName:Qamran Rajput,email:qami1502@gmail.com,self:true}

}
}

Answer

Calendar Api don't returns creator name for Lollipop and Marshmellow. So you can write

if (creatorName == null) {
creatorName = "";
}

To avoid any Null Pointer Exception Regards