我需要在我的应用程序中集成谷歌日历事件(CRUD 操作)。首先,我想到了使用内容提供程序从本地日历应用程序访问事件数据。但我发现只有 ICS(api 14) 支持日历提供程序。1)有没有办法在较低版本中访问日历提供程序?2)是否可以在android 中使用谷歌日历api(https://developers.google.com/google-apps/calendar/ )?
问问题
179 次
3 回答
1
要获取日历事件,下面的代码正在运行:
private void getCalenderEvents() {
Cursor cursor = context.getContentResolver().query(Uri.parse("content://com.android.calendar/events"),
new String[] { "calendar_id", "title", "description", "dtstart", "dtend", "eventLocation" }, null, null, null);
cursor.moveToFirst();
// fetching calendars name
String CNames[] = new String[cursor.getCount()];
for (int i = 0; i < CNames.length; i++) {
rowDataEvents = new HashMap<String, String>();
String eventTitle = cursor.getString(1);
String eventStartDate = cursor.getString(3);
String eventEndDate = cursor.getString(4);
String eventDescription = cursor.getString(2);
String eventLocation = cursor.getString(5);
cursor.moveToNext();
}
cursor.close();
}
于 2013-10-11T06:01:03.800 回答
0
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.util.Calendar;
public class MainActivity extends Activity {
Button disp,add;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
disp = (Button) findViewById(R.id.dispbut);
add = (Button) findViewById(R.id.btn1);
disp.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
disp();
}
});
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
add();
}
});
}
public void disp() {
Calendar startTime = Calendar.getInstance();
startTime.set(2013, 2, 13, 11, 35);
Uri uri = Uri.parse("content://com.android.calendar/time/"
+ String.valueOf(startTime.getTimeInMillis()));
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
// Use the Calendar app to view the time.
startActivity(intent);
}
public void add(){
Calendar cal = Calendar.getInstance();
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", cal.getTimeInMillis());
intent.putExtra("allDay", true);
intent.putExtra("rrule", "FREQ=YEARLY");
intent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000);
intent.putExtra("title", "Test Event");
intent.putExtra("description", "This is a sample description");
startActivity(intent);
}
}
于 2015-06-02T10:57:18.447 回答
-1
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/dispbut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="Display Event" />
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add An Event" />
</RelativeLayout>
于 2015-06-02T11:05:08.107 回答