[英]Create calendar event in the default android calendar
當按下按鈕時,我有以下代碼可以執行某些操作。 我希望按鈕可以在2013年3月3日上午10:00創建日歷活動。 感謝所有幫助。
碼:
@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()) {
您可以在Intent的幫助下打開日歷。
以下是用於在“日歷”應用程序中設置事件的代碼。 您只能打開帶有默認事件字段的日歷活動。
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"
Android Coder提供了一種輕松完成此任務的方法
此外,您必須在manifest.xml中添加權限才能使用日歷事件
機器人:名字= “android.permission.READ_CALENDAR”
機器人:名字= “android.permission.WRITE_CALENDAR”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.