我在使用 CalendarContract API 选择帐户时遇到问题。我收到以下错误:
引起:android.database.sqlite.SQLiteException:靠近“@iancorneli”:语法错误(代码1):,编译时:SELECT _id FROM Calendars WHERE(account_name = me@iancorneli.us account_type = LOCAL)
代码如下:
private void getAccounts() {
AccountManager manager = AccountManager.get(context);
Account[] accounts = manager.getAccountsByType("com.google");
for (Account account : accounts) {
accountName = account.name;
accountType = account.type;
break;
}
}
private long getCalendarID() {
getAccounts();
String[] projection = new String[]{CalendarContract.Calendars._ID};
String selection =
CalendarContract.Calendars.ACCOUNT_NAME +
" = " + accountName + " " +
CalendarContract.Calendars.ACCOUNT_TYPE +
" = " + CalendarContract.ACCOUNT_TYPE_LOCAL + " ";
String[] selArgs =
new String[]{
CalendarContract.Calendars.ACCOUNT_NAME,
CalendarContract.ACCOUNT_TYPE_LOCAL
};
Cursor cursor = context.getContentResolver().query(
CalendarContract.Calendars.CONTENT_URI,
projection,
selection,
selArgs,
null
);
if (cursor.moveToFirst()) {
return cursor.getLong(0);
}
return -1;
}
关于我哪里出错的任何帮助?