无法检查日历安卓中添加的重复事件

时间:2016-03-09 07:21:17

标签: java android calendar

我正在向日历实施添加活动,如果已添加到日历,则不允许。但我无法在日历中查看重复的活动,任何人都可以帮助我,这是我的代码

public void add_to_calendar() {
        try {
            boolean check_add_cal = check_add_cal();
            if (check_add_cal) {
                Toast.makeText(Opportunity_events.this,
                        "Already Added to calendar", Toast.LENGTH_SHORT).show();
            } else {

                Calendar beginTime = Calendar.getInstance();
                SimpleDateFormat yyyymmdd = new SimpleDateFormat("yyyymmdd");
                SimpleDateFormat timeFormat = new SimpleDateFormat("dd-MM-yyyy");

                Date untilDate = null;
                try {
                    untilDate = timeFormat.parse(lastdate_value.getText()
                            .toString());
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                beginTime.setTime(untilDate);

                Intent intent = new Intent(Intent.ACTION_INSERT)
                        .setData(Events.CONTENT_URI)
                        .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
                                beginTime.getTimeInMillis())
                        // .putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
                        // endTime.getTimeInMillis())
                        .putExtra(Events.TITLE,
                                text_title_event.getText().toString())
                        .putExtra(Events._ID, selected_eventid.toString())
                        // .putExtra(Events.DESCRIPTION,
                        // description_value.getText().toString())
                        // .putExtra(Events.EVENT_LOCATION, "The gym")
                        .putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY);
                // .putExtra(Intent.EXTRA_PHONE_NUMBER,
                // "rowan@example.com,trevor@example.com");
                startActivity(intent);
            }

        } catch (Exception e) {
            // TODO: handle exception
        }
    }

这是我的检查方法

 public boolean check_add_cal() {
        String calUriString = Events.CONTENT_URI.toString();
        System.out.println("value if path " + calUriString);
        Uri cal = Uri.parse(calUriString);

        Cursor cursor = this.getApplicationContext().getContentResolver().query(cal,
                new String[] { "_id" }, " _id = ? ",
                new String[] { selected_eventid }, null);
        System.out.println("curso" + cursor.getCount() + ",,"
                + cursor.getPosition()+","+cursor.toString());
        if (cursor.moveToFirst()) {
            return true;
        } else {
            return false;
        }

    }
  but it's not working please help me..

0 个答案:

没有答案