Hi,

What do you see in logcat? i.e. what's the crash? Also does your app have
calendar read permission?
http://developer.android.com/guide/topics/providers/calendar-provider.html#manifest

Thanks,
Mike

On Mon, May 14, 2012 at 12:43 PM, chronogps <chrono...@free.fr> wrote:

> I try to read google agenda content with following code (from here :
> http://developer.android.com/guide/topics/providers/calendar-provider.html
> )
>
> The code crach at : cur = cr.query(uri, EVENT_PROJECTION, selection,
> selectionArgs, null);
>
> I'm running this source code on my Acer A500 / ICS 4.0.3 (as it is not
> possible to manage agenda on the emulator).
>
> Any idea to fix the app crash ?
>
>
>                        final int PROJECTION_ID_INDEX = 0;
>                        final int PROJECTION_ACCOUNT_NAME_INDEX = 1;
>                        final int PROJECTION_DISPLAY_NAME_INDEX = 2;
>                        final int PROJECTION_OWNER_ACCOUNT_INDEX = 3;
>
>                        // Projection array. Creating indices for this
> array instead of
> doing
>                        // dynamic lookups improves performance.
>                        final String[] EVENT_PROJECTION = new String[]
>                                {
>                                Calendars._ID,                           //
> 0
>                                Calendars.ACCOUNT_NAME,                  //
> 1
>                                Calendars.CALENDAR_DISPLAY_NAME          //
> 2
>                                };
>
>
>                        // Run query
>                        Cursor cur = null;
>                        ContentResolver cr = getContentResolver();
>                        Uri uri = Calendars.CONTENT_URI;
>                        String selection = "((" + Calendars.ACCOUNT_NAME +
> " = ?) AND ("
>                                                + Calendars.ACCOUNT_TYPE +
> " = ?))";
>                        String[] selectionArgs = new String[] {"
> chrono...@gmail.com",
> "com.google"};
>
>                        // Submit the query and get a Cursor object back.
>
>                        cur = cr.query(uri, EVENT_PROJECTION, selection,
> selectionArgs,
> null);
>
>                        // Use the cursor to step through the returned
> records
>                        while (cur.moveToNext())
>                                {
>                            long calID = 0;
>                            String displayName = null;
>                            String accountName = null;
>                            // Get the field values
>                            calID = cur.getLong(PROJECTION_ID_INDEX);
>                            displayName =
> cur.getString(PROJECTION_DISPLAY_NAME_INDEX);
>                            accountName =
> cur.getString(PROJECTION_ACCOUNT_NAME_INDEX);
>                            // Do something with the values...
>                                }
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to