gpt4 book ai didi

android - Android 4.0 中日历的位置是什么?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:06:40 25 4
gpt4 key购买 nike

当我在 Nexus S 上开发一个 API 为 7 的应用程序时,在我的日历上创建一个新事件没有问题。

我使用该代码获取日历在手机上的位置:

cursor = cr.query(Uri.parse("content://com.android.calendar/calendars"), new String[]{ "_id", "displayname" }, null, null, null);

当我将我的 nexus S 更新到 Android ICS 4.0 时,问题就来了。在不更改任何代码的情况下,我犯了一个错误。在 logcat 上我可以阅读:

  • 没有这样的列:显示名称,db=/data/data/com.android.providers.calendar/databases/calendar.db

当然游标是空的。也许日历数据库有任何变化?所以,我想知道如何在 Android 4.0 上开发 API 7 应用程序来创建新的日历事件

谢谢;)

最佳答案

在 Android 4.0 中,日历与 Android 2.3 中的 Uri 相同。所以我附上了我的代码,以防其他人遇到同样的问题。

    public void addToCalendar(Context ctx, final String title, final String comment, final long dtstart, final long dtend) {


final ContentResolver cr = ctx.getContentResolver();
Cursor cursor ;

cursor = cr.query(Uri.parse("content://com.android.calendar/calendars"), new String[]{ "_id","calendar_displayName" }, null, null, null);

/*if (Integer.parseInt(Build.VERSION.SDK) == 8 )
cursor = cr.query(Uri.parse("content://com.android.calendar/calendars"), new String[]{ "_id", "displayname" }, null, null, null);
*/

//Get all the calendar ids and name available in the phone
if ( cursor.moveToFirst() ) {
final String[] calNames = new String[cursor.getCount()];
final int[] calIds = new int[cursor.getCount()];
for (int i = 0; i < calNames.length; i++) {
calIds[i] = cursor.getInt(0);
calNames[i] = cursor.getString(1);
cursor.moveToNext();
}

//Creation of a new event in calendar whose position is 0 on the phone
ContentValues cv = new ContentValues();
cv.put("calendar_id", calIds[0]);
cv.put("title", title);
cv.put("dtstart", dtstart );
cv.put("dtend", dtend);
cv.put("eventTimezone","Spain");
cv.put("description", comment );

//Insertion on the events of the calendar
cr.insert(Uri.parse("content://com.android.calendar/events"), cv);

/*Uri newEvent ;
if (Integer.parseInt(Build.VERSION.SDK) == 8 )
newEvent = cr.insert(Uri.parse("content://com.android.calendar/events"), cv);
*/

finish();

}
cursor.close();

}

您拥有所有信息:http://developer.android.com/guide/topics/providers/calendar-provider.html正如约翰之前所说。

关于android - Android 4.0 中日历的位置是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8593923/

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