无法自动将事件添加到Google日历

时间:2016-01-20 21:42:13

标签: java android google-calendar-api

我的TotalCalendar课程有问题。在本课程中,我将每个事件(例如:20个事件)添加到我自己的日历中。我应该将此事件添加到Google日历中,但是它会添加到设备日历中。我该怎么改变它?当我把单个活动放到日历上时,我可以选择日历类型,但在这种情况下,我不能。

public class TotalCalendar {
    Context mContext;
    Intent mIntent;

    public TotalCalendar(Context context) {
        this.mContext = context;
    }

    public boolean insert(String dzien, String miesiac, String lokacja, String tytul, String opis, String godziny) {

        int year = Calendar.getInstance().get(Calendar.YEAR);
        Calendar beginTime = Calendar.getInstance();
        Calendar endTime = Calendar.getInstance();
        int currentMonth = Calendar.getInstance().get(Calendar.MONTH);

        if((Miesiac(miesiac) == 0) && (currentMonth == 11)  )
        {
            year++;
        }

        int hh1 = 0;
        int mm1 = 0;
        int hh2 = 0;
        int mm2 = 0;

        if(isNumeric(getHH1(godziny)) && isNumeric(getMM2(godziny)))
        {
            Log.d("debug","numeric");
            hh1 = Integer.valueOf(getHH1(godziny)).intValue();
            mm1 = Integer.valueOf(getMM1(godziny)).intValue();
            hh2 = Integer.valueOf(getHH2(godziny)).intValue();
            mm2 = Integer.valueOf(getMM2(godziny)).intValue();
        }
        else
        {
            hh1 = 0;
            mm1 = 0;
            hh2 = 0;
            mm2 = 0;
        }

        beginTime.set(year, Miesiac(miesiac), Integer.valueOf(dzien).intValue(), hh1, mm1);
        endTime.set(year, Miesiac(miesiac), Integer.valueOf(dzien).intValue(), hh2, mm2);
        Log.d("debug", "Begin time: " + Miesiac(miesiac) + " " + Integer.valueOf(dzien));

        long startMillis = beginTime.getTimeInMillis();
        long endMillis = endTime.getTimeInMillis();


        ContentResolver cr = mContext.getContentResolver();
        ContentValues values = new ContentValues();
        TimeZone tz = TimeZone.getDefault();

        values.put(CalendarContract.Events.DTSTART, startMillis);
        values.put(CalendarContract.Events.DTEND, endMillis);
        values.put(CalendarContract.Events.TITLE,tytul);
        values.put(CalendarContract.Events.DESCRIPTION,opis);
        values.put(CalendarContract.Events.CALENDAR_ID,1);
        values.put(CalendarContract.Events.EVENT_TIMEZONE,tz.getID());
        Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI,values);


        Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
        builder.appendPath("time");
        ContentUris.appendId(builder, startMillis);

        this.mIntent = new Intent(Intent.ACTION_VIEW).setData(builder.build());
        mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(mIntent);

        return true;
    }

0 个答案:

没有答案
相关问题