gpt4 book ai didi

android - 在 android 上创建一个带有与会者电子邮件的事件

转载 作者:行者123 更新时间:2023-11-30 04:42:23 26 4
gpt4 key购买 nike

我尝试创建一个 Activity 并向其添加电子邮件。

我无法让它工作,我得到的时间是 1970 年,没有电子邮件出现。

有什么想法吗?

谢谢。

这是我使用的代码:

    Uri calendars = null;
if (Integer.parseInt(Build.VERSION.SDK) == 8 )
{
calendars = Uri.parse("content://com.android.calendar/calendars");
}
else
{
calendars = Uri.parse("content://calendar/calendars");
}

Cursor cursor = context.getContentResolver().query(calendars, new String[] { "_id", "displayName" }, "selected=1", null, null);

if (cursor != null && cursor.moveToFirst())
{
String[] calNames = new String[cursor.getCount()];
final int[] calIds = new int[cursor.getCount()];
for (int i = 0; i < calNames.length; i++)
{
// retrieve the calendar names and ids
calIds[i] = cursor.getInt(0);
calNames[i] = cursor.getString(1);
cursor.moveToNext();
}
cursor.close();
String name = "Name1";
String eMail = "name1@nnn.com";
ContentValues event = new ContentValues();

int cal_id = calIds[which];
event.put("calendar_id", cal_id);
event.put("title", "test title");
event.put("eventLocation", "test location");
event.put("eventStatus", 1);
event.put("visibility", 0);
event.put("transparency", 0);
event.put("hasAlarm", 1);
event.put("hasAttendeeData", "1");

Calendar c = Calendar.getInstance();
c.roll(Calendar.DAY_OF_MONTH, true);

Date date = c.getTime();
Date begine = new Date(date.getYear(),
date.getMonth(),
date.getDate(),
14, 0); long dtstart = begine.getTime();
event.put("dtstart", dtstart);

Date end = new Date(date.getYear(),
date.getMonth(),
date.getDate(),
15, 0);
long dtend = end.getTime();

event.put("dtend", dtend);
Uri eventsUri = null;
if (Integer.parseInt(Build.VERSION.SDK) == 8 )
{
eventsUri = Uri.parse("content://com.android.calendar/events");
}
else
{
eventsUri = Uri.parse("content://calendar/events");
}
Uri url = context.getContentResolver().insert(eventsUri, event);
long id = -1;

if (url != null)
{
id = Long.parseLong(url.getLastPathSegment());
ContentValues values = new ContentValues();
values.put("event_id", id);
values.put("method", 1); //METHOD_ALERT
values.put("minutes", 15); // 15 minutes
Uri reminder = Uri.parse("content://com.android.calendar/reminders");
context.getContentResolver().insert(reminder, values);
if(name.length() > 0 || eMail.length() > 0)
{
ContentValues attendees = new ContentValues();
attendees.put("attendeeEmail", eMail);
attendees.put("attendeeName", name);
attendees.put("attendeeRelationship", 2);//RELATIONSHIP_ATTENDEE
attendees.put("attendeeStatus", 3); //ATTENDEE_STATUS_INVITED
attendees.put("attendeeType", 1); //TYPE_REQUIRED
attendees.put("event_id", id);

Uri attendeesUri = null;
if (Integer.parseInt(Build.VERSION.SDK) == 8 )
{
attendeesUri = Uri.parse("content://com.android.calendar/attendees");
}
else
{
attendeesUri = Uri.parse("content://calendar/attendees");
}
context.getContentResolver().insert(attendeesUri, attendees);

Intent i = new Intent(Intent.ACTION_EDIT);

i.setType("vnd.android.cursor.item/event");
i.setData(url);

context.startActivity(i);
}
else
{
Toast.makeText(context, "Could not create an event!", Toast.LENGTH_LONG);
}

最佳答案

更正在这里....

代替 attendees.put("attendeeRelationship", 2);//RELATIONSHIP_ATTENDEE

您必须输入 attendees.put("attendeeRelationship", 1);//RELATIONSHIP_ATTENDEE。只需进行更改,您就会获得所需的电子邮件地址和与会者姓名。

这里的2组织者

1 用于与会者

还有 look here

关于android - 在 android 上创建一个带有与会者电子邮件的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5735953/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com