How to use calendar appointment?

I am trying to start a calendar from my application, so I can allow users to add their appointments to it, and then read the application.

I tried the code snippet I found here:

ComponentName cn; Intent i = new Intent(); cn = new ComponentName("com.google.android.calendar", "com.android.calendar.LaunchActivity"); i.setComponent(cn); startActivity(i); 

and get an error

 07-07 21:05:33.944: ERROR/AndroidRuntime(1089): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.google.android.calendar/com.android.calendar.LaunchActivity}; have you declared this activity in your AndroidManifest.xml? 

I declared com.android.calendar.LaunchActivity my android manifest file and still not working ...

I think this is not feasible using an emulator? I do this in Android 3.0 (HoneyComb).

+4
source share
7 answers

This from Andriod docs worked for me:

 long startMillis = System.currentTimeMillis(); Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon(); builder.appendPath("time"); ContentUris.appendId(builder, startMillis); intent = new Intent(Intent.ACTION_VIEW).setData(builder.build()); startActivity(intent); 

Read more here: Android calendars .

+12
source

Firstly, it will not work in the emulator, because the Calendar application you are trying to use is not in the emulator image.

Secondly, this application may or may not be on any production device. Anyone who creates an Intent using a ComponentName (pointing to some other component) poses problems at best.

Thirdly, you won’t be able to “immediately read my application”, even if the user decided to add an event. They will be available only through the Google Calendar GData API after synchronization, which may not be immediately.

+3
source

you have to write this

 setContentView(R.layout.tabla); ComponentName cn; Intent i = new Intent(); cn = new ComponentName("com.android.calendar", "com.android.calendar.LaunchActivity"); i.setComponent(cn); startActivity(i); 
+1
source

You need to provide viewing permission to read the calendar. Try adding this to your AndroidManifest.xml

 <uses-permission android:name="android.permission.READ_CALENDAR"></uses-permission> 
0
source

If you use API 14 or higher, you can use this code

 Intent intent = new Intent(Intent.ACTION_INSERT); intent.setData(CalendarContract.Events.CONTENT_URI); startActivity(intent) 
0
source

apb answer translated into MonoDroid,

 long startMillis = Java.Lang.JavaSystem.CurrentTimeMillis( ); Uri.Builder builder = Android.Provider.CalendarContract.ContentUri.BuildUpon( ); builder.AppendPath( "time" ); ContentUris.AppendId( builder,startMillis ); Intent intent = new Intent( Intent.ActionView ); intent.SetData( builder.Build() ); StartActivity( intent ); 
0
source

The easiest way to open Google Calendar without a specified date:

 Uri calendarUri = CalendarContract.CONTENT_URI .buildUpon() .appendPath("time") .build(); startActivity(new Intent(Intent.ACTION_VIEW, calendarUri)); 
0
source

All Articles