2011-02-17 111 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

相关问题