Event not being added to Calendar on some Android phones -


i using below code add events calendar on android

public void addevent(string datetime) {          string eventdate;         {         simpledateformat formatter = new simpledateformat("yyyy/mm/dd hh:mm");         final calendar cal = calendar.getinstance();         try {              cal.settime(formatter.parse(datetime));             eventdate = cal.get(calendar.year)+"/"+cal.get(calendar.month)+"/"+cal.get(calendar.day_of_month)+" "+cal.get(calendar.hour_of_day)+":"+cal.get(calendar.minute);             //log.e("event date ", eventdate);         } catch (exception e) {             log.e("catch ", "",e);         }         contentvalues event = new contentvalues();         event.put("calendar_id", 3);         event.put("_id", eventid);         event.put("title", mytitle);         event.put("description", mydescription);         event.put("eventtimezone", timezone.getdefault().getid());         event.put("dtstart", cal.gettimeinmillis());         event.put("dtend", cal.gettimeinmillis()+60*60*1000);         event.put("hasalarm", 1); // 0 false, 1 true          string eventuristring = "content://com.android.calendar/events";          uri eventuri = getapplicationcontext()         .getcontentresolver()         .insert(uri.parse(eventuristring), event);          system.out.println("event"+eventuri);     } 

the following code adds event htc phone running android lollipop returns null on phones micromax , samsung running android jellybean. can reason behavior? need turn on settings?

try using constants provided events class.

contentresolver cr = yourcontext.getcontentresolver(); contentvalues event = new contentvalues(); event.put(events.dtstart,  cal.gettimeinmillis()); event.put(events.dtend, cal.gettimeinmillis() + 60 * 60 * 1000); event.put(events.title, mytitle); event.put(events.description, mydescription); event.put(events.calendar_id, calid); event.put(events.event_timezone, timezone.getdefault().getid()); ... uri uri = cr.insert(events.content_uri, event); 

the event id of inserted event can method

long eventid = long.parselong(uri.getlastpathsegment()); 

check title adding events in calendar provider http://developer.android.com/guide/topics/providers/calendar-provider.html

if want insert _id event, should check if there

uri event = contenturis.withappendedid(events.content_uri, _id); cursor cursor = managedquery(event, null, null, null); if (cursor.getcount() == 1) {   //the event exists.. may want update } else {   // can insert id } 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -