3

I am new in Android development.I am using following code to add event calendar in my Android application.

Calendar cal = Calendar.getInstance();              
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", cal.getTimeInMillis());
intent.putExtra("allDay", true);
intent.putExtra("rrule", "FREQ=YEARLY");
intent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000);
intent.putExtra("title", "A Test Event from android app");
startActivity(intent);

But getting following error :

02-21 12:33:38.262: E/AndroidRuntime(404): FATAL EXCEPTION: main
02-21 12:33:38.262: E/AndroidRuntime(404): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.EDIT typ=vnd.android.cursor.item/event (has extras) }
02-21 12:33:38.262: E/AndroidRuntime(404):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
02-21 12:33:38.262: E/AndroidRuntime(404):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
02-21 12:33:38.262: E/AndroidRuntime(404):  at android.app.Activity.startActivityForResult(Activity.java:2817)
02-21 12:33:38.262: E/AndroidRuntime(404):  at android.app.Activity.startActivity(Activity.java:2923)
02-21 12:33:38.262: E/AndroidRuntime(404):  at com.infrasoft.elara.HomeActivity$1.onClick(HomeActivity.java:36)
02-21 12:33:38.262: E/AndroidRuntime(404):  at android.view.View.performClick(View.java:2408)
02-21 12:33:38.262: E/AndroidRuntime(404):  at android.view.View$PerformClick.run(View.java:8816)
02-21 12:33:38.262: E/AndroidRuntime(404):  at android.os.Handler.handleCallback(Handler.java:587)
02-21 12:33:38.262: E/AndroidRuntime(404):  at android.os.Handler.dispatchMessage(Handler.java:92)
02-21 12:33:38.262: E/AndroidRuntime(404):  at android.os.Looper.loop(Looper.java:123)
02-21 12:33:38.262: E/AndroidRuntime(404):  at android.app.ActivityThread.main(ActivityThread.java:4627)
02-21 12:33:38.262: E/AndroidRuntime(404):  at java.lang.reflect.Method.invokeNative(Native Method)
02-21 12:33:38.262: E/AndroidRuntime(404):  at java.lang.reflect.Method.invoke(Method.java:521)
02-21 12:33:38.262: E/AndroidRuntime(404):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-21 12:33:38.262: E/AndroidRuntime(404):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-21 12:33:38.262: E/AndroidRuntime(404):  at dalvik.system.NativeStart.main(Native Method)

AndroidManifest.xml :

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

<activity
    android:name=".CalendarActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.INSERT" />
        <category android:name="android.intent.category.APP_CALENDAR" />
        <data android:mimeType="vnd.android.cursor.item/event" />
    </intent-filter>
</activity>

Please tell me what is wrong.

Thanks in advance.

Maveňツ
  • 1
  • 12
  • 50
  • 89
Bosco
  • 3,835
  • 6
  • 25
  • 33

1 Answers1

2

EDITED

I believe you are trying to run this on an emulator. By default the emulators do not have a calendar app installed on them. So there is nothing to handle this type of intent. It should work on a device that has a calendar event. Try and run it on a physical device which has the native android calendar app installed. It will work.

For emulator you could do the following :

1) download Calendar.apk (native android calendar)

2) install it wia adb (http://developer.android.com/guide/developing/tools/adb.html) with the command :

adb -e install Calendar.apk

3) Then try running your app once the calendar is installed.

You should have the following permissions declared in your manifest.xml :

<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
Abhishek Sabbarwal
  • 3,758
  • 1
  • 26
  • 41