{"id":1163,"date":"2011-11-19T12:26:18","date_gmt":"2011-11-19T04:26:18","guid":{"rendered":"http:\/\/leybreeze.com\/blog\/?p=1163"},"modified":"2011-11-19T12:26:18","modified_gmt":"2011-11-19T04:26:18","slug":"android%e4%b8%ad%e8%8e%b7%e5%8f%96%e8%ae%be%e5%a4%87google%e6%97%a5%e5%8e%86%ef%bc%88google-calendar%ef%bc%89%e4%bf%a1%e6%81%af","status":"publish","type":"post","link":"http:\/\/leybreeze.com\/blog\/?p=1163","title":{"rendered":"Android\u4e2d\u83b7\u53d6\u8bbe\u5907Google\u65e5\u5386\uff08Google Calendar\uff09\u4fe1\u606f"},"content":{"rendered":"<p>\u4ee3\u7801\u4e0e\u8303\u4f8b\uff1a<\/p>\n<pre lang=\"JAVA\">\r\nimport android.app.Activity;\r\nimport android.content.ContentValues;\r\nimport android.database.Cursor;\r\nimport android.net.Uri;\r\nimport android.os.Build;\r\nimport android.os.Bundle;\r\nimport android.text.format.DateUtils;\r\nimport android.widget.TextView;\r\n\r\npublic class CalendarTestActivity extends Activity {\r\n\tprivate TextView tv;\/\/ \u7528\u4e8e\u5c4f\u5e55\u6587\u5b57\u663e\u793a\u7684TextView\r\n\tprivate String temp;\/\/ \u7528\u4ee5\u8bb0\u5f55TextView\u7684\u6587\u672c\u5185\u5bb9\r\n\tpublic String AUTHORITY;\/\/ \u7528\u4ee5\u9002\u5e94\u4e0d\u540c\u7684Android\u7cfb\u7edf\u7248\u672c\u4e0b\u65e5\u5386\u7684\u5185\u5bb9\u63d0\u4f9b\u5668Uri\u7684\u4e0d\u540c\r\n\r\n\t@Override\r\n\tpublic void onCreate(Bundle savedInstanceState) {\r\n\t\tsuper.onCreate(savedInstanceState);\r\n\t\tsetContentView(R.layout.main);\r\n\r\n\t\tfinal int sdkVersion = Build.VERSION.SDK_INT; \/\/\u83b7\u53d6\u8bbe\u5907\u7684Android\u7cfb\u7edf\u7248\u672c\u53f7\r\n\t\t\/\/ 8=Build.VERSION_CODES.FROYO\r\n\t\tif (sdkVersion < 8) { \/\/Android\u4ece\u7248\u672c2.2\u8d77Calendar\u7684Uri\u53d1\u751f\u4e86\u53d8\u5316\uff0c\u5fc5\u987b\u6ce8\u610f\r\n\t\t\tAUTHORITY = \"calendar\";\r\n\t\t} else {\r\n\t\t\tAUTHORITY = \"com.android.calendar\";\r\n\t\t}\r\n\t\ttemp = \"\";\r\n\r\n\t\tCursor cursor = getContentResolver().query(Uri.parse(\"content:\/\/\" + AUTHORITY + \"\/calendars\"), new String[] { \"_id\", \"displayName\" }, \"selected=1\", null, null);\r\n\t\tif (cursor != null &#038;&#038; cursor.moveToFirst()) {\r\n\t\t\tString[] calNames = new String[cursor.getCount()];\r\n\t\t\tint[] calIds = new int[cursor.getCount()];\r\n\t\t\tfor (int i = 0; i < calNames.length; i++) {\r\n\t\t\t\tcalIds[i] = cursor.getInt(0);\r\n\t\t\t\tcalNames[i] = cursor.getString(1);\r\n\t\t\t\t\/\/\u5c06\u83b7\u53d6\u7684\u65e5\u5386\u540d\u79f0\u4fe1\u606f\u52a0\u5165\u5b57\u7b26\u4e32\u53d8\u91cftemp\r\n\t\t\t\ttemp += Integer.toString(calIds[i]); \r\n\t\t\t\ttemp += \"  \";\r\n\t\t\t\ttemp += calNames[i];\r\n\t\t\t\ttemp += \"\\n\";\r\n\t\t\t\tcursor.moveToNext();\r\n\t\t\t}\r\n\t\t\tcursor.close();\r\n\t\t\tif (calIds.length > 0) {\r\n\t\t\t\t\/\/\u53ef\u4ee5\u5728\u6b64\u8fdb\u884c\u64cd\u4f5c\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\ttv = (TextView) findViewById(R.id.con);\r\n\t\ttv.setText(temp);\r\n\r\n\t}\r\n\r\n\t\/\/\u6dfb\u52a0\u65e5\u5386\u9879\u76ee\r\n\tpublic void insert(int calIDs) {\r\n\t\tint cal_id = calIDs;\r\n\r\n\t\tContentValues cv = new ContentValues();\r\n\t\tcv.put(\"calendar_id\", cal_id);\r\n\t\tcv.put(\"title\", \"Judy's birthday\");\r\n\t\tcv.put(\"description\", \"Time to celebrate Judy's birthday.\");\r\n\t\tcv.put(\"eventLocation\", \"KFC, SH\");\r\n\t\tcv.put(\"dtstart\", System.currentTimeMillis());\r\n\t\tcv.put(\"dtend\", System.currentTimeMillis() + DateUtils.DAY_IN_MILLIS);\r\n\t\tcv.put(\"allDay\", 1);\r\n\t\tcv.put(\"hasAlarm\", 1);\r\n\t\tgetContentResolver().insert(Uri.parse(\"content:\/\/\" + AUTHORITY + \"\/events\"), cv);\r\n\t}\r\n}\r\n<\/pre>\n<p>\u8bf4\u660e\uff1aAndroid\u4e2d\u5185\u5bb9\u63d0\u4f9b\u5668\uff08ContentProvider\uff09\u6709\u7740\u5e7f\u6cdb\u7684\u5e94\u7528\uff0cGoogle\u8d26\u6237\u540c\u6b65\u7684\u65e5\u5386\u4e5f\u5c06\u6570\u636e\u50a8\u5b58\u5728\u76f8\u5e94\u7684\u5185\u5bb9\u63d0\u4f9b\u5668\u4e2d\u3002\u8fd9\u91cc\u662f\u65e5\u5386\u5185\u5bb9\u63d0\u4f9b\u5668\u7684\u4e00\u4e2a\u7b80\u5355\u8303\u4f8b\uff0c\u53ef\u4ee5\u83b7\u53d6\u65e5\u5386\u7684\u540d\u79f0\uff0c\u5e76\u63d0\u4f9b\u4e86\u4e00\u4e2a\u6dfb\u52a0\u65e5\u5386\u9879\u76ee\u7684\u65b9\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee3\u7801\u4e0e\u8303\u4f8b\uff1a import android.app.Activity; import android.cont &hellip; <a href=\"http:\/\/leybreeze.com\/blog\/?p=1163\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cAndroid\u4e2d\u83b7\u53d6\u8bbe\u5907Google\u65e5\u5386\uff08Google Calendar\uff09\u4fe1\u606f\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[5,100],"_links":{"self":[{"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1163"}],"collection":[{"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1163"}],"version-history":[{"count":1,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1163\/revisions"}],"predecessor-version":[{"id":1164,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1163\/revisions\/1164"}],"wp:attachment":[{"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1163"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}