Remove or filter duplicate holidays events from calendar database - Android

天涯浪子 提交于 2020-06-01 03:21:06

问题


I am fetching all calendar events including holidays from Android Calendar Database using Content providers. As I am signed in with two different Gmail accounts, the Query returns duplicate holidays. I want to avoid duplicate Holidays and I am trying to do the same by making changes in Query.

Is it possible to avoid duplicate holidays by making changes in the query? Can someone help me with making a proper query which by default avoids duplicate Holidays? Or is there any other solution for this issue?

Below is my code:

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    String[] PROJECTION = { CalendarContract.Events._ID,
            CalendarContract.Events.TITLE ,
            CalendarContract.Events.OWNER_ACCOUNT,
            CalendarContract.Events.ACCOUNT_NAME,
            CalendarContract.Events.ACCOUNT_TYPE};

    Cursor cursor = getContentResolver().query(
            CalendarContract.Events.CONTENT_URI, PROJECTION, null, null,
            null);


    int titleIndex = cursor.getColumnIndexOrThrow(CalendarContract.Events.TITLE);
    int eventIdIndex = cursor.getColumnIndexOrThrow(CalendarContract.Events._ID);
    int ownerAccountIndex = cursor.getColumnIndexOrThrow(CalendarContract.Events.OWNER_ACCOUNT);
    int accountNameIndex = cursor.getColumnIndexOrThrow(CalendarContract.Events.ACCOUNT_NAME);
    int accountTypeIndex = cursor.getColumnIndexOrThrow(CalendarContract.Events.ACCOUNT_TYPE);

    String[] result = new String[cursor.getCount()];
    while (cursor.moveToNext()) {
        String name = cursor.getString(titleIndex);
        String id = cursor.getString(eventIdIndex);
        String ownerAccount = cursor.getString(ownerAccountIndex);
        String accountName = cursor.getString(accountNameIndex);
        String accountType = cursor.getString(accountTypeIndex);
        result[cursor.getPosition()] = name + "(" + id + ")"+" ownerAccount->"+ownerAccount+", accountName-->"+accountName+" accountType->"+accountType;

        Log.d("AllDataLog","* result->"+result[cursor.getPosition()]);
    }
    cursor.close();
}
}

来源:https://stackoverflow.com/questions/61571997/remove-or-filter-duplicate-holidays-events-from-calendar-database-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!