get Voice Card Calendar - Android android.provider

Android examples for android.provider:CalendarContract

Description

get Voice Card Calendar

Demo Code


//package com.java2s;

import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;

import android.provider.CalendarContract.Calendars;

public class Main {
    private static final String CALENDAR_NAME = "VoiceCard";
    private static final int CALENDAR_ID_INDEX = 0,
            CALENDAR_ACCOUNT_NAME_INDEX = 1,
            CALENDAR_DISPLAY_NAME_INDEX = 2,
            CALENDAR_OWNER_ACCOUNT_INDEX = 3;
    public static final String[] CALENDAR_PROJECTION = new String[] {
            Calendars._ID, Calendars.ACCOUNT_NAME,
            Calendars.CALENDAR_DISPLAY_NAME, Calendars.OWNER_ACCOUNT };

    protected static long getVoiceCardCalendar(Context context) {
        long calID = 0;
        Cursor cur = null;//www  .  j  a  v a  2 s . c o  m
        String where = null, selection[] = null;
        try {
            where = CALENDAR_PROJECTION[CALENDAR_DISPLAY_NAME_INDEX]
                    + " = ?";
            selection = new String[] { CALENDAR_NAME };
            cur = context.getContentResolver().query(Calendars.CONTENT_URI,
                    CALENDAR_PROJECTION, where, selection, null);
            if (cur != null && cur.getCount() > 0) {
                while (cur.moveToNext()) {
                    calID = cur.getLong(CALENDAR_ID_INDEX);
                }
            }
        } catch (SQLException e) {
            System.out
                    .println("[CalendarIntentHelper][getVoiceCardCalendar]SQLException:"
                            + e);
        } catch (Exception ex) {
            System.out
                    .println("[CalendarIntentHelper][getVoiceCardCalendar]Exception:"
                            + ex);
        }
        if (cur != null && !cur.isClosed()) {
            cur.close();
        }
        return calID;
    }
}

Related Tutorials