Hi and welcome to another tutorial from CodingDemos :)
In this tutorial, you will learn how to add an event to the calendar programmatically using Android Intent.
Here are the steps:
1- Open up Android Studio.
2- Add some checking Inside the addEvent button's onClickListener to ensure that the title, location, and description edittexts are not empty. Otherwise, show an error Toast message.
if (!title.getText().toString().isEmpty() && !location.getText().toString().isEmpty() && !description
.getText().toString().isEmpty()) {
}else{
Toast.makeText(MainActivity.this, "Please fill all the fields",
Toast.LENGTH_SHORT).show();
}
3- Initialize the Android calendar Intent.
Intent intent = new Intent(Intent.ACTION_INSERT);
4- Set the Intent Datatype.
intent.setData(CalendarContract.Events.CONTENT_URI);
5- Pass the title, location, and description values inside the intent using PutExtra.
intent.putExtra(CalendarContract.Events.TITLE, title.getText().toString());
intent.putExtra(CalendarContract.Events.EVENT_LOCATION, location.getText().toString());
intent.putExtra(CalendarContract.Events.DESCRIPTION, description.getText().toString());
6- Set the event type so that it will be able available all day without start and end time.
intent.putExtra(CalendarContract.Events.ALL_DAY, true);
7- Include some emails of guests that you want them to be part of this event.
intent.putExtra(Intent.EXTRA_EMAIL, "test@yahoo.com, test2@yahoo.com, test3@yahoo.com");
8- Before you can call startActivity(), you need to do some checking to ensure that there is an application that can handle this type of action. Otherwise, show an error Toast Message.
if(intent.resolveActivity(getPackageManager()) != null){
startActivity(intent);
}else{
Toast.makeText(MainActivity.this, "There is no app that support this action", Toast.LENGTH_SHORT).show();
}
9- Now build and run the app to see the result :)
Links:
Android Calendar Intent: [ Ссылка ]
Website: [ Ссылка ]
FaceBook: [ Ссылка ]
Introduction 00:00
Final output 00:15
Android Studio project introduction 01:49
Setup the Calendar event 03:54
Conclusion 18:15
How to Insert an Event to Calendar Using Android Intent
Теги
androidandroid tutorialandroid studioandroid studio tutorialandroid app developmentandroid intentjavaandroid intent actionandroid-intent putextraIntent.ACTION_INSERTandroid calendar intentandroid studio calendar eventsadd event to calendar android exampleandroid add event to calendar programmatically exampleandroid calendar app tutorialandroid calendar apphow to add calendar in androidcalendarcontractcalendarcontract eventsandroid intent example