Android获取ID点击事件,Android日历,获取事件ID

小编典典

我提取了用于将事件存储到android日历中的列的列表。这里的清单:

[0]“ originalEvent”(id = 830007842672)

[1]“ availabilityStatus”(id = 830007842752)

[2]“ ownerAccount”(id = 830007842840)

[3]“ _sync_account_type”(id = 830007842920)

[4]“可见性” (id = 830007843008)

[5]“ rrule”(id = 830007843080)

[6]“ lastDate”(id = 830007843144)

[7]“ hasAlarm”(id = 830007843216)

[8]“ guestsCanModify”(id = 830007843288)[ 9]“ guestsCanSeeGuests”(id =

830007843376)

[10]“执行”(id = 830007843464)

[11]“ rdate”(id = 830007843528)

[12]“透明度”(id = 830007843592)

[13]“时区”( id = 830007843672)

[14]“已选择”(id = 830007843744)

[15]“ dtstart”(id = 830007843816)[16]“标题”(id = 830007843888)

[17]“ _sync_time”(id = 830007843952)

[18]“ _id”(id = 830007844024)[19]“ hasAttendeeData”(id = 830007844088)[20]“

_sync_id”(id = 830007844176)

[21]“ commentsUri” (id = 830007844248)[22]“说明”(id = 830007844328)[23]“

htmlUri”(id = 830007844408)[24]“ _sync_account”(id = 830007844480)

[25]“ _sync_version”(id = 830007844560)

[ 26]“ hasExtendedProperties”(id = 830007844640)

[27]“ calendar_id”(id = 830007844736)

然后,如果我想获取事件的新事件ID:

public static long getNewEventId(ContentResolver cr, Uri cal_uri){

Uri local_uri = cal_uri;

if(cal_uri == null){

local_uri = Uri.parse(calendar_uri+"events");

}

Cursor cursor = cr.query(local_uri, new String [] {"MAX(_id) as max_id"}, null, null, "_id");

cursor.moveToFirst();

long max_val = cursor.getLong(cursor.getColumnIndex("max_id"));

return max_val+1;

}

和插入事件:

public void insertDomainEntry(Date exp_date, String name, long event_id){

SQLiteDatabase db = getWritableDatabase();

ContentValues values = new ContentValues();

values.put("exp_date", exp_date.getTime()/1000);

values.put("event_id", event_id);

values.put("domainname", name);

db.insertOrThrow("domains_events", null, values);

}

该解决方案似乎可行,即使这可能不是一个很好的解决方案。

编辑02/2015 getNextEventId 的目的是为事件表创建一个新的事件条目,此处是使用此方法的代码:

@Override

public void onItemClick(AdapterView> adapter, View curview, int position,

long id) {

WhoisEntry entry = this.adapter.getItem(position);

long event_id = CalendarUtils.getNewEventId(getContentResolver(), null);

Toast.makeText(getApplicationContext(), "Domain: " + entry.getDomainName(),

Toast.LENGTH_SHORT).show();

Intent intent = new Intent(Intent.ACTION_EDIT);

intent.setType("vnd.android.cursor.item/event");

intent.putExtra("beginTime", entry.getExpiration().getTime());

intent.putExtra("_id", event_id);

intent.putExtra("allDay", false);

intent.putExtra("endTime", entry.getExpiration().getTime()+60*30);

intent.putExtra("title", "Expiration of " + entry.getDomainName());

startActivity(intent);

database.insertDomainEntry(entry.getExpiration(),

entry.getDomainName(), event_id);

}

更新09/2015

根据评论中的要求,我添加了如何获取Calendar URI(基本上是日历的存储位置,应用程序尝试猜测它,在所有已知的可能的日历路径中进行搜索)

public static String getCalendarUriBase(Activity act) {

String calendarUriBase = null;

Uri calendars = Uri.parse("content://calendar/calendars");

Cursor managedCursor = null;

try {

managedCursor = act.getContentResolver().query(calendars,

null, null, null, null);

} catch (Exception e) {

}

if (managedCursor != null) {

calendarUriBase = "content://calendar/";

} else {

calendars = Uri.parse("content://com.android.calendar/calendars");

try {

managedCursor = act.getContentResolver().query(calendars,

null, null, null, null);

} catch (Exception e) {

}

if (managedCursor != null) {

calendarUriBase = "content://com.android.calendar/";

}

}

calendar_uri= calendarUriBase;

return calendarUriBase;

}

2020-09-26

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值