java - android Calender event issues -
hi newbie , learning android...i got following code this post written @abhi
put reminder in real calendar on phone?
this post provide answers, code. me problem having, first code:
code onclicklistenerevent below:
btnone.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { // calendar datetoshow = calendar.getinstance(); // datetoshow.set(2013, calendar.may, 10, 9, 0); // // showcalendarattime(datetoshow); uri event1; long epoch, epoch1; uri events_uri = uri.parse(getcalendaruribase(this) + "events"); contentresolver cr = getcontentresolver(); contentvalues values = new contentvalues(); try { epoch = new java.text.simpledateformat ("yyyy-mm-dd hh:mm a").parse(date+" "+time).gettime(); //epoch=epoch; log.e("epoch",string.valueof(epoch)); epoch1 = new java.text.simpledateformat ("yyyy-mm-dd hh:mm a").parse(date+" "+time).gettime(); //epoch1=epoch1; log.e("epoch1",string.valueof(epoch1)); } catch (parseexception e) { // todo auto-generated catch block e.printstacktrace(); } values.put("calendar_id", 1); values.put("title", "appoitment"); values.put("allday", 0); values.put("dtstart",epoch); // event starts @ 11 minutes values.put("dtend", epoch1 ); // ends 60 minutes values.put("description", "your consulting date , time "); values.put("visibility", 0); values.put("hasalarm", 1); if(events_uri!=null){ event1 = cr.insert(events_uri, values); } // reminder insert uri reminders_uri = uri.parse(getcalendaruribase(this) + "reminders"); values = new contentvalues(); values.put( "event_id", long.parselong(event1.getlastpathsegment())); values.put( "method", 1 ); values.put( "minutes", 10 ); if(reminders_uri!=null){ cr.insert( reminders_uri, values ); } alertdialog.settitle("event saved"); dismiss(); alertdialog.show(); } // reminder insert uri reminders_uri = uri.parse(getcalendaruribase(this)+ "reminders"); values = new contentvalues(); values.put("event_id", id); values.put("method", 1); values.put("minutes", 0); cr.insert(reminders_uri, values); } });
getcalendaruribase code:
private string getcalendaruribase(activity act) { string calendaruribase = null; uri calendars = uri.parse("content://calendar/calendars"); cursor managedcursor = null; try { managedcursor = act.managedquery(calendars, null, null, null, null); } catch (exception e) { } if (managedcursor != null) { calendaruribase = "content://calendar/"; } else { calendars = uri.parse("content://com.android.calendar/calendars"); try { managedcursor = act.managedquery(calendars, null, null, null, null); } catch (exception e) { } if (managedcursor != null) { calendaruribase = "content://com.android.calendar/"; } } return calendaruribase; }
i having issues code above, found few answers in post such event1
uri type variable, having following issues:
issues in onclicklistenerevent()
- the following code put red line underneath code error
"the method getcalendaruribase(activity)
in type mainactivity
not applicable arguments (new view.onclicklistener(){})
", code is:
uri.parse(getcalendaruribase(this)+ "reminders");
- what return type of epoch, date , time in following line?
epoch = new java.text.simpledateformat ("yyyy-mm-dd hh:mm a").parse(date+" "+time).gettime();
what following code? because in eclipse says
alertdialog
, 8 fixes available: 1st 1 "create new variable", if type of variable, dismiss? need them results or add events in calendar?alertdialog.settitle("event saved");
dismiss();
alertdialog.show();
on following line in eclipse deprecated warning:
managedcursor = act.managedquery(calendars, null, null, null, null);
can @abhi or experienced person me? newbie , android not user fiendly @ all.
thanks.
sounds there 2 things going on:
1) have basic questions example code doing or means. these basic java related questions
2) you're working calendar api (probably pre api 14?) , it's complicated
regarding 1 respect "issues in onclicklistenerevent()": can't use "this" reference activity when invoking getcalendarbaseuri() method since you're in anonymous class @ point. qualify "this" keyword preceding class name. e.g., "myactivity.this"
regarding second question, "gettime()" return long (c.f. http://developer.android.com/reference/java/util/date.html).
finally, "managedquery()" method on activity class deprecated in api 11. may or may not matter (depending on project's goals).
all in all, seems me calendar code little more complicated needs (probably because original author trying support pushing events pre api 14?). calendarcontract (http://developer.android.com/reference/android/provider/calendarcontract.html) if have luxury of targeting apis 14+.
Comments
Post a Comment