我正在尝试使用 Calendar Provider 编辑和删除 Google 日历中的 Activity 。我已经使用 Calendar Provider 创建了 Activity 。
这是我创建事件的代码:
Calendar beginTime = Calendar.getInstance();
beginTime.set(2014, 5, 19, 7, 30);
Calendar endTime = Calendar.getInstance();
endTime.set(2014, 5, 19, 8, 30);
Intent intent = new Intent(Intent.ACTION_INSERT)
.setData(Events.CONTENT_URI)
.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime.getTimeInMillis())
.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime.getTimeInMillis())
.putExtra(Events.TITLE, "")
.putExtra(Events.DESCRIPTION, "")
.putExtra(Events.EVENT_LOCATION, "")
.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY)
.putExtra(Intent.EXTRA_EMAIL, email);
startActivity(intent);
Activity 创建成功。现在我想编辑/删除事件。那么,我该如何执行此操作。对于编辑/删除,我需要创建事件的事件 ID,我怎么才能得到它??
请...帮帮我,伙计们。
最佳答案
检查这个网址
Update and delete calendar events in android through my application
希望对您有所帮助:)
获取事件 ID:
private int ListSelectedCalendars(String eventtitle) {
Uri eventUri;
if (android.os.Build.VERSION.SDK_INT <= 7) {
// the old way
eventUri = Uri.parse("content://calendar/events");
} else {
// the new way
eventUri = Uri.parse("content://com.android.calendar/events");
}
int result = 0;
String projection[] = { "_id", "title" };
Cursor cursor = getContentResolver().query(eventUri, null, null, null,
null);
if (cursor.moveToFirst()) {
String calName;
String calID;
int nameCol = cursor.getColumnIndex(projection[1]);
int idCol = cursor.getColumnIndex(projection[0]);
do {
calName = cursor.getString(nameCol);
calID = cursor.getString(idCol);
if (calName != null && calName.contains(eventtitle)) {
result = Integer.parseInt(calID);
}
} while (cursor.moveToNext());
cursor.close();
}
return result;
}
更新事件:
@SuppressLint("InlinedApi")
private int UpdateCalendarEntry(int entryID) {
int iNumRowsUpdated = 0;
Uri eventUri;
if (android.os.Build.VERSION.SDK_INT <= 7) {
// the old way
eventUri = Uri.parse("content://calendar/events");
} else {
// the new way
eventUri = Uri.parse("content://com.android.calendar/events");
}
ContentValues values = new ContentValues();
values.put(Events.TITLE, "test");
values.put(Events.EVENT_LOCATION, "Chennai");
Uri updateUri = ContentUris.withAppendedId(eventUri, entryID);
iNumRowsUpdated = getContentResolver().update(updateUri, values, null,
null);
return iNumRowsUpdated;
}
删除事件:
private int DeleteCalendarEntry(int entryID) {
int iNumRowsDeleted = 0;
Uri eventUri = ContentUris
.withAppendedId(getCalendarUriBase(), entryID);
iNumRowsDeleted = getContentResolver().delete(eventUri, null, null);
return iNumRowsDeleted;
}
private Uri getCalendarUriBase() {
Uri eventUri;
if (android.os.Build.VERSION.SDK_INT <= 7) {
// the old way
eventUri = Uri.parse("content://calendar/events");
} else {
// the new way
eventUri = Uri.parse("content://com.android.calendar/events");
}
return eventUri;
}
关于android - 编辑/删除谷歌日历事件并获取事件 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23626240/
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
查看Ruby的CSV库的文档,我非常确定这是可能且简单的。我只需要使用Ruby删除CSV文件的前三列,但我没有成功运行它。 最佳答案 csv_table=CSV.read(file_path_in,:headers=>true)csv_table.delete("header_name")csv_table.to_csv#=>ThenewCSVinstringformat检查CSV::Table文档:http://ruby-doc.org/stdlib-1.9.2/libdoc/csv/rdoc/CSV/Table.html
我发现ActiveRecord::Base.transaction在复杂方法中非常有效。我想知道是否可以在如下事务中从AWSS3上传/删除文件:S3Object.transactiondo#writeintofiles#raiseanexceptionend引发异常后,每个操作都应在S3上回滚。S3Object这可能吗?? 最佳答案 虽然S3API具有批量删除功能,但它不支持事务,因为每个删除操作都可以独立于其他操作成功/失败。该API不提供任何批量上传功能(通过PUT或POST),因此每个上传操作都是通过一个独立的API调用完成的
有没有办法在这个简单的get方法中添加超时选项?我正在使用法拉第3.3。Faraday.get(url)四处寻找,我只能先发起连接后应用超时选项,然后应用超时选项。或者有什么简单的方法?这就是我现在正在做的:conn=Faraday.newresponse=conn.getdo|req|req.urlurlreq.options.timeout=2#2secondsend 最佳答案 试试这个:conn=Faraday.newdo|conn|conn.options.timeout=20endresponse=conn.get(url
我有一个存储主机名的Ruby数组server_names。如果我打印出来,它看起来像这样:["hostname.abc.com","hostname2.abc.com","hostname3.abc.com"]相当标准。我想要做的是获取这些服务器的IP(可能将它们存储在另一个变量中)。看起来IPSocket类可以做到这一点,但我不确定如何使用IPSocket类遍历它。如果它只是尝试像这样打印出IP:server_names.eachdo|name|IPSocket::getaddress(name)pnameend它提示我没有提供服务器名称。这是语法问题还是我没有正确使用类?输出:ge
我想获取模块中定义的所有常量的值:moduleLettersA='apple'.freezeB='boy'.freezeendconstants给了我常量的名字:Letters.constants(false)#=>[:A,:B]如何获取它们的值的数组,即["apple","boy"]? 最佳答案 为了做到这一点,请使用mapLetters.constants(false).map&Letters.method(:const_get)这将返回["a","b"]第二种方式:Letters.constants(false).map{|c
我安装了ruby版本管理器,并将RVM安装的ruby实现设置为默认值,这样'哪个ruby'显示'~/.rvm/ruby-1.8.6-p383/bin/ruby'但是当我在emacs中打开inf-ruby缓冲区时,它使用安装在/usr/bin中的ruby。有没有办法让emacs像shell一样尊重ruby的路径?谢谢! 最佳答案 我创建了一个emacs扩展来将rvm集成到emacs中。如果您有兴趣,可以在这里获取:http://github.com/senny/rvm.el
假设我有这个范围:("aaaaa".."zzzzz")如何在不事先/每次生成整个项目的情况下从范围中获取第N个项目? 最佳答案 一种快速简便的方法:("aaaaa".."zzzzz").first(42).last#==>"aaabp"如果出于某种原因你不得不一遍又一遍地这样做,或者如果你需要避免为前N个元素构建中间数组,你可以这样写:moduleEnumerabledefskip(n)returnto_enum:skip,nunlessblock_given?each_with_indexdo|item,index|yieldit
我目前正在使用以下方法获取页面的源代码:Net::HTTP.get(URI.parse(page.url))我还想获取HTTP状态,而无需发出第二个请求。有没有办法用另一种方法做到这一点?我一直在查看文档,但似乎找不到我要找的东西。 最佳答案 在我看来,除非您需要一些真正的低级访问或控制,否则最好使用Ruby的内置Open::URI模块:require'open-uri'io=open('http://www.example.org/')#=>#body=io.read[0,50]#=>"["200","OK"]io.base_ur