Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Michael Mealy
Michael Mealy
13,247 Points

Need help with an Android Project

Can anyone help me, I am building android App that when a button is pressed it opens a calendar app already installed on the phone using intents. here is my Current Code so far.(Inside the OnClick Method).

 public void onClick(View v) {

Intent calendarIntent = new Intent(Intent.ACTION_MAIN, null);

PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(calendarIntent, 0);
boolean isIntentSafe = activities.size() > 0;

if(isIntentSafe) {

}else{ Toast.makeText(this, "No Suitable Application is     installed",Toast.LENGTH_LONG).show();

This Code Works fine, if you have got a min API of 15, but mine is 10. is there anyway to access a calendar App using an API lower than 15.

2 Answers

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Intent.CATEGORY_APP_CALENDAR is only available as of API 15. So you need to create your intent differenty for < API 15.

Kind of like this untested code:

Intent calendarIntent;
int apiVersion = android.os.Build.VERSION.SDK_INT;
if (apiVersion >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
    calendarIntent = new Intent(Intent.ACTION_MAIN, null);
else {
    calendarIntent = new Intent(Intent.ACTION_EDIT);