2011-02-17 52 views
3

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

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

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

      } 
}; 

我不需要的應用程序在任何領域預填充在日曆剛剛打開,我將把其餘部分留給用戶。 所有幫助是值得歡迎,並感謝您

回答

9

如果你只是想打開你可以使用日曆和意圖使用其中任一組件名稱(你可能要同時迎合如果你想支持舊手機)

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); 

(代碼是未經測試,從現有項目複製)

+0

我該如何運行這個ComponentName?或者我用這個新的ComponentName做什麼? – kyle 2011-02-17 22:02:45

相關問題