在默认的安卓日历中创建日历事件
问题描述:
我有以下代码来按下按钮时执行某些操作。我希望能够在2013年3月3日上午10点按钮创建日历活动。所有的帮助表示赞赏。在默认的安卓日历中创建日历事件
代码:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Button button = (Button)findViewById(R.id.button1);
// button.setOnClickListener(this);
final CheckBox checkBox = (CheckBox) findViewById(R.id.checkBox1);
final CheckBox checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
final Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
if (checkBox.isChecked()) {
答
你可以用意向的帮助下打开日历。
以下是在Calendar应用程序中设置事件的代码。您只能打开默认事件字段填充的日历活动。
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("title", "Some title");
intent.putExtra("description", "Some description");
intent.putExtra("beginTime", eventStartInMillis);
intent.putExtra("endTime", eventEndInMillis);
startActivity(intent);
将上面的代码放在按钮的onclick监听器中。
此外,您必须在manifest.xml中添加这些日历权限:
android:name="android.permission.READ_CALENDAR"
android:name="android.permission.WRITE_CALENDAR"
好的,那么如何在同一个按钮下添加另一个事件?我想要生成多个事件。 – ScorpioBlue 2012-08-17 04:03:47
用上面的代码做一个函数,并且如果你想添加N个事件,则调用该函数的N个时间。 – rajpara 2012-08-17 04:26:18
丹J&Klaudo感谢编辑:) – rajpara 2012-08-17 05:48:50