View Code? Open in Web Editor
NEW
Get events in calendar with use Google Calendar Api
geteventcalendar's Introduction
geteventcalendar's People
Contributors
Watchers
geteventcalendar's Issues
Hey thanks for the article and the code! I am able to get the app to run and it shows the accounts and I can select an email account. The accountName is set as expected. I followed your article and placed a credentials.json in the app folder. I do not see any reference to that file in the code.
I click the "get event" button and I see a progress indicator and then back to the main page. I'm missing something here. Any suggestions on how I might get this sample working?
After downloading and rebuild to run, I always get "Request cancelled" after clicking the "GET EVENT" button.
fix these two functions:
private fun makeRequestTask () {
var mLastError: Exception ? = null
lifecycleScope.launch {
mProgress!! .show()
val job = async(Dispatchers .IO ) {
try {
Log .d(" zzanzu" , " makeRequestTask: doInBackground" )
getDataFromCalendar()
} catch (e: Exception ) {
Log .d(" zzanzu" , " makeRequestTask2: $e " )
mLastError = e
null
}
}
val output = job.await()
if (mLastError != null ) {
if (mLastError is GooglePlayServicesAvailabilityIOException ) {
showGooglePlayServicesAvailabilityErrorDialog(
(mLastError as GooglePlayServicesAvailabilityIOException )
.connectionStatusCode
)
} else if (mLastError is UserRecoverableAuthIOException ) {
startActivityForResult(
(mLastError as UserRecoverableAuthIOException ).intent,
REQUEST_AUTHORIZATION
)
} else {
binding.txtOut.text =
" The following error occurred:\n " + mLastError!! .message
}
} else {
binding.txtOut.text = " Request cancelled."
}
mProgress!! .hide()
if (output == null || output.size == 0 ) {
Log .d(" Google" , " veri yok" )
} else {
for (index in 0 until output.size) {
binding.txtOut.text = (TextUtils .join(" \n " , output))
Log .d(
" Google" ,
output[index].id.toString() + " " + output[index].summary + " " + output[index].startDate
)
}
}
}
}
private fun getDataFromCalendar (): MutableList <GetEventModel > {
val now = DateTime (System .currentTimeMillis())
val eventStrings = ArrayList <GetEventModel >()
val events = mService!! .events().list(" primary" )
.setMaxResults(10 )
.setTimeMin(now)
.setOrderBy(" startTime" )
.setSingleEvents(true )
.execute()
val items = events.items
for (event in items) {
var start = event.start.dateTime
if (start == null ) {
start = event.start.date
}
eventStrings.add(
GetEventModel (
summary = event.summary,
startDate = start.toString()
)
)
}
return eventStrings
}
and then add any schedule to your default google calendar for today.
then finally you can see your data in text area.
good luck!