如何设置onClick监听器以查看Google日历?

时间:2019-01-20 04:12:47

标签: android android-studio onclick calendar onclicklistener

这是我当前的代码,可让我通过应用程序在Google日历中创建事件。

import java.util.GregorianCalendar;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.CalendarContract;
import android.provider.CalendarContract.Calendars;
import android.provider.CalendarContract.Events;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

public class AppointmentCalendar extends AppCompatActivity {

    public static final String[] EVENT_PROJECTION = new String[]{
            Calendars._ID, // 0
            Calendars.ACCOUNT_NAME, // 1
            Calendars.CALENDAR_DISPLAY_NAME // 2
    };

    private static final int PROJECTION_DISPLAY_NAME_INDEX = 2;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_appointment_calendar);
    }

    public void onClick1(View view) {

        Intent intent = new Intent(Intent.ACTION_INSERT);
        intent.setType("vnd.android.cursor.item/event");
        intent.putExtra(Events.TITLE, "");
        intent.putExtra(Events.EVENT_LOCATION, "");
        intent.putExtra(Events.DESCRIPTION, "");

        GregorianCalendar calDate = new GregorianCalendar(2019, 1, 1);
        intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
                calDate.getTimeInMillis());
        intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
                calDate.getTimeInMillis());

        intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);

        intent.putExtra(Events.RRULE,
                "FREQ=WEEKLY;COUNT=11;WKST=SU;BYDAY=TU,TH");

        intent.putExtra(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE);
        intent.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY);

        startActivity(intent);

    }

}

我想知道如何添加onClick侦听器,以便在单击名为“查看日历”的按钮时,可以带我查看和编辑日历?

0 个答案:

没有答案