【问题标题】:Android , get ID if the shared calendarAndroid , 如果共享日历,则获取 ID
【发布时间】:2016-12-02 09:52:34
【问题描述】:

我尝试在与我共享的日历上设置活动。我知道我应该使用日历的 id。但是我有问题。这是我的代码:

@OnClick(R.id.add_event_button)
    public void addEvent() {

        CalendarDB calendar = (CalendarDB) mCalendarSpinner.getSelectedItem();
        Long id = calendar.getId();
        ContentValues event = new ContentValues();
        event.put("calendar_id", 1);
        event.put(CalendarContract.Events.EVENT_TIMEZONE, "Europe/Berlin");  // Here choose your location time zone
        event.put("title", "test application");
        event.put("description",  "This is test event");
        event.put("eventLocation", "School");
        event.put("dtstart", System.currentTimeMillis());
        event.put("dtend", System.currentTimeMillis() + 1800 * 1000);
        event.put("allDay", 0);
        // status: 0~ tentative; 1~ confirmed; 2~ canceled
        // event.put("eventStatus", 1);
        event.put(CalendarContract.Events.CALENDAR_ID,8);
        Uri l_eventUri;
        if (Build.VERSION.SDK_INT >= 8) {
            l_eventUri = Uri.parse("content://com.android.calendar/events");
        } else {
            l_eventUri = Uri.parse("content://calendar/events");
        }
        Uri l_uri = this.getContentResolver()
                .insert(l_eventUri, event);
        Toast.makeText(this, "SUCCESS", Toast.LENGTH_SHORT).show();

        }

这是可行的,但是正在添加事件,日历的 ID 是未知的 - 我的意思是我尝试手动设置它们 - 1,2,3 等等,然后确定将添加哪个日历事件。 Google API 网站说 id 应该是 Long ,当我得到日历列表时,我得到的字符串是 id - 日历的名称。同样的情况在 android.provider CalendarContract.class 中:

public static final String CALENDAR_ID = "calendar_id";

当我将该 id 设置为参数时,应用程序崩溃 - 它需要 Long 参数。那么,我怎样才能获得共享日历的 id;s 呢?提前感谢您的帮助:)

【问题讨论】:

    标签: android calendar


    【解决方案1】:

    What is the easiest way to get the current day of the week in Android?

    因此您将获得当前日期,并且您将以相同的方式获得当前日期以及相同日期的天数。现在计算一下

    【讨论】:

      猜你喜欢
      • 2021-05-06
      • 1970-01-01
      • 1970-01-01
      • 2017-04-03
      • 2019-08-04
      • 2013-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多