我有一個PhoneGap應用程序,我想通過Content Provider訪問Android日曆。我的PhoneGap JavaScript函數可以成功調用並返回Java函數,但是我只是無法讓Content Provider調用工作。該應用程序編譯沒有問題,並運行,但只要我打電話給相關的內容提供者功能它掛了一段時間,崩潰。以下是我發現的Content Provider功能的修改版本: package com.george.myapp;Android日曆內容提供者查詢不斷崩潰
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class EventsInCalender extends Activity {
//@Override
public void onCreate() {
//public void onCreate(Bundle savedInstanceState) {
//super.onCreate(savedInstanceState);
//setContentView(R.layout.event);
}
public String getCal()
{
String cal_name = "createdstring";
Cursor cursor = getContentResolver().query(Uri.parse("content://com.android.calendar/calendars"),new String[] { "_id", "displayName" }, "selected=1", null, null);
if (cursor != null && cursor.moveToFirst()) {
String[] calNames = new String[cursor.getCount()];
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();
}
cal_name = calNames[0];
cursor.close();
}
return cal_name;
}
}
謝謝,我已經通過了,但我看到使用sdk android:minSdkVersion =「14」,我知道有應用程序訪問舊版SDK的日曆,有什麼建議嗎? – 2012-02-03 08:07:05
谷歌不建議在API版本14下使用任何日曆,因此我不明白爲什麼開發者會選擇使用這些黑客。恕我直言,他們只是帶來更多的問題和頭痛。 – dmaxi 2012-02-03 17:31:52
訪問API版本14之前的日曆的應用程序要麼手動讀取本地數據庫以獲取日曆事件(hacky),要麼可能使用Google的日曆Web服務 – 2012-04-12 07:49:40