Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

android - How to use Calendar Intent?

I am trying to Launch a calendar from my app, so I can let users put their appointments to it and then have my app read those.

I tried the piece of code I found on 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 the 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 did declare the com.android.calendar.LaunchActivity to my android manifest file and it still isn't working...

I'd think this not doable using the emulator? I am doing this in Android 3.0 (HoneyComb).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);

More info here: Android calendar docs.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...