簡體   English   中英

如何從我的應用程序中打開日歷?

[英]how can i open the calendar from my app?

我正在為Android構建一個應用程序,我不需要我的應用程序讓日歷成為它的一部分(加上它會打敗目的),我的應用程序允許用戶收聽廣播電台,並需要選項設置事件到(記得在特定時間收聽電台),如果應用程序有自己的日歷,那么只有當用戶打開應用程序時,事件警報才會消失...毫無意義。 我一直在尋找,找不到,有沒有辦法使用意圖或其他東西打開谷歌日歷或Android可能有的其他日歷? 我需要把我的意圖(/其他代碼)放在我已經擁有的監聽器中,現在看起來像這樣

private View.OnClickListener reminder = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
                  // open calendar code goes here.

            }
};

我不需要應用程序預先填寫日歷中的任何字段只需打開它,我會將其余部分留給用戶。 歡迎大家幫忙,謝謝

如果您只是想打開日歷,您可以使用這些組件名稱並使用這些組件名稱(如果您想支持舊手機,則可能需要兼顧兩者)

Intent i = new Intent();

//Froyo or greater (mind you I just tested this on CM7 and the less than froyo one worked so it depends on the phone...)
cn = new ComponentName("com.google.android.calendar", "com.android.calendar.LaunchActivity");

//less than Froyo
cn = new ComponentName("com.android.calendar", "com.android.calendar.LaunchActivity");

i.setComponent(cn);
startActivity(i);

如果你想進入添加事件屏幕(這聽起來更適合你的目的),請使用以下內容:

 //all version of android
 Intent i = new Intent();

 // mimeType will popup the chooser any  for any implementing application (e.g. the built in calendar or applications such as "Business calendar"
 i.setType("vnd.android.cursor.item/event"); 

 // the time the event should start in millis. This example uses now as the start time and ends in 1 hour
 i.putExtra("beginTime", new Date().getTime()); 
 i.putExtra("endTime", new Date().getTime() + DateUtils.HOUR_IN_MILLIS);

 // the action
 i.setAction(Intent.ACTION_EDIT);
 startActivity(i);

(代碼未經測試,從現有項目復制)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM