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[]
{"[email protected]",
"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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en