Frage

I'm just getting up to speed on Android, and I want to send calendar event to others from mobile. Same as whatsapp sending contacts. For sending Contact in chat (XMPP) I've used vCard. So for sending calendar event in chat what should I use?

I have searched a lot. But can't find something fruitful.

Please suggest the library or code snippet for sending calendar event in XMPP.

Thanks in advance.

War es hilfreich?

Lösung

You may refer to iCal Import Export allows you to import iCalender files to your calender without using google synchronization services.

Using this you can import all calendar events to iCalendar files and also export those events back to calendar. Using Calendar Provider you can fetch all calendar data, but requires android API level 14 or above while using iCal Import Export you can fetch all calendar data for lower API levels too.

Andere Tipps

manifest

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

Code:

Cursor cursor = cr.query(Uri.parse("content://calendar/calendars"), new String[]{ "_id",  "displayname" }, null, null, null);
cursor.moveToFirst();
String[] CalNames = new String[cursor.getCount()];
int[] CalIds = new int[cursor.getCount()];
for (int i = 0; i < CalNames.length; i++) {
    CalIds[i] = cursor.getInt(0);
    CalNames[i] = cursor.getString(1);
    cursor.moveToNext();
}
cursor.close();

Fetching all events, and particular event is done by specifying range

ContentResolver contentResolver = getContentResolver();

Uri.Builder builder = Uri.parse(getCalendarUriBase() + "/instances/when").buildUpon();
        long now = new Date().getTime();
        ContentUris.appendId(builder, now - DateUtils.MILLIS_PER_DAY*10000);
        ContentUris.appendId(builder, now + DateUtils.MILLIS_PER_DAY * 10000);

and then let's say you wish to log events ID from calendar with ID = 1

Cursor eventCursor = contentResolver.query(builder.build(),
                new String[] { "event_id"}, "Calendars._id=" + 1,
                null, "startDay ASC, startMinute ASC"); 
        // For a full list of available columns see http://tinyurl.com/yfbg76w
        while (eventCursor.moveToNext()) {
            String uid2 = eventCursor.getString(0);
            Log.v("eventID : ", uid2);

        }

Now display this event in Listview select one of this for send as a text messsage and on receiver side :

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", HERE MSG WHICH YOU RECEIVE);
startActivity(intent);

There is no library AFAIK and it's really just a matter of retrieving the calender event and transforming it's data into XML. Unfortunately there is also no XEP on how calendar events should be represented in XMPP/XML so you have to come up with your own representation.

iCalendar/vCalendar is the calendar file format similar to vCard

You can add new field in vcard that save calender info example

VCard vCard = new VCard();
vCard.setField("calender","calender info");

calender info should be a sting, it can be a json format string.

user who receives it can load your vcard and use method

vCard.load(connection, Jid);
String string=vCard.getField("calender");

You really don't need any specific library for that purpose. You can check out Calendar Provider They have an awesome example on it too!

Be sure to use these permissions in your manifest.xml

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

And if you wish to send contacts then check this out Android: How to import contact from phone?

Vote this up if it helped you! I really need it. :)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top