@easydl/native-calendar
v0.0.3
Published
android native calendar plugin
Downloads
14
Readme
@easydl/native-calendar
📅 Android Native Calendar Plugin for Capacitor
A lightweight Capacitor plugin to interact with the native Android Calendar. It allows you to create, list, update, and delete calendar events directly from your Capacitor app.
Note: This plugin currently supports Android only.
Features
- ✅ Create Events: Add events with title, location, description, and time.
- ✅ List Events: Query events within a specific time range.
- ✅ Update Events: Modify existing events.
- ✅ Delete Events: Remove events by ID.
- ✅ Permission Handling: Automatically handles Android runtime permissions.
Install
npm install @easydl/native-calendar
npx cap syncAndroid Configuration (Required)
To use this plugin, you must add the following permissions to your AndroidManifest.xml file.
Open android/app/src/main/AndroidManifest.xml and add these lines inside the <manifest> tag:
XML
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.your.app">
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<application ...>
...
</application>
</manifest>Usage Example
TypeScript
import { NativeCalendar } from '@easydl/native-calendar';
const testCalendar = async () => {
try {
// 1. Create an Event
const createRes = await NativeCalendar.createEvent({
title: "Team Meeting",
location: "Conference Room A",
description: "Discuss Q1 goals",
startDate: Date.now() + 3600000, // 1 hour from now
endDate: Date.now() + 7200000 // 2 hours from now
});
console.log("Event Created, ID:", createRes.id);
// 2. List Events
const listRes = await NativeCalendar.listEvents({
startDate: Date.now(),
endDate: Date.now() + 86400000 // Next 24 hours
});
console.log("Events found:", listRes.events);
} catch (error) {
console.error("Error:", error);
}
};API
listEvents(...)
TypeScript
listEvents(options: { startDate: number; endDate: number; }) => Promise<{ events: CalendarEvent[]; }>Get a list of events within a specific date range.
| Param | Type | Description | | --- | --- | --- | | options | { startDate: number; endDate: number; } | Time range in milliseconds (timestamp) |
Returns: Promise<{ events: CalendarEvent[]; }>
createEvent(...)
TypeScript
createEvent(options: { title: string; startDate: number; endDate: number; location?: string; description?: string; }) => Promise<{ id: string; }>Create a new calendar event.
| Param | Type | | --- | --- | | options | { title: string; startDate: number; endDate: number; location?: string; description?: string; } |
Returns: Promise<{ id: string; }>
deleteEvent(...)
TypeScript
deleteEvent(options: { id: string; }) => Promise<{ deleted: boolean; }>Delete an event by its ID.
| Param | Type | | --- | --- | | options | { id: string; } |
Returns: Promise<{ deleted: boolean; }>
updateEvent(...)
TypeScript
updateEvent(options: { id: string; title?: string; startDate?: number; endDate?: number; description?: string; }) => Promise<{ updated: boolean; }>Update an existing event. Only provide the fields you want to update.
| Param | Type | | --- | --- | | options | { id: string; title?: string; startDate?: number; endDate?: number; description?: string; } |
Returns: Promise<{ updated: boolean; }>
ping()
TypeScript
ping() => Promise<{ ok: boolean; platform: string; }>Test the plugin connection.
Returns: Promise<{ ok: boolean; platform: string; }>
Interfaces
CalendarEvent
| Prop | Type | Description | | --- | --- | --- | | id | string | Unique ID of the event | | title | string | | | start | number | Start timestamp (ms) | | end | number | End timestamp (ms) | | description | string | | | location | string | |
