我怎么能打开,从我的应用程序中的日历? [英] how can i open the calendar from my app?

查看:154
本文介绍了我怎么能打开,从我的应用程序中的日历?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个应用程序为Android,我不需要我的应用程序有一个日历是它的一部分(加上它会破坏目的),我的应用程序允许用户收听广播电台,并且需要的选项设置一个事件(记得要听收音机在特定时间),如果应用程序有自己的日历,则此事件的报警只会响,如果用户有应用程序打开...毫无意义的。我一直在寻找,并不能找到,有没有办法使用意图或别的东西,打开谷歌日历或其他日历,Android的可能? 我需要把我的意图(/其他code)在我的听众,我已经有了,看起来像这样,现在

I am building an app for the android, i dont need my app to have a calendar be part of it(plus it would defeat the purpose), my app allows the user to listen to a radio station, and needs the option to set an event to(remember to listen to the radio at a specific time), if the app has its own calendar then the event alarms will only go off if the user has the app open... pointless. i have been looking and cannot find, is there a way to use an intent or something else to open a google calendar or some other calendar that Android might have? i need to put my intent(/ other code) in my listener which i already have and looks like this for now

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

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

            }
};

我不需要的应用程序,以pre-填写任何领域只要打开它的日历,我将离开,其余由用户。 所有帮助是值得欢迎,并感谢您

i dont need the app to pre-fill in any field in the calendar just open it, i will leave the rest up to the user. all help is welcome and thank you

推荐答案

如果你只是想与其中任一组件名称打开日历,你可以使用和意图(您可能必须同时满足,如果你想支持旧电话)

If you just want to open the calendar you can use and intent with EITHER of these component names (you might have to cater for both if you want to support older phones)

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

如果你想要去到add事件屏幕(这听起来你的目的更好)使用这样的:

If you want to go to the add event screen (which sounds better for your purpose) use something like:

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

(code是未经测试,从现有项目复制)

(code is untested, copied from an existing project)

这篇关于我怎么能打开,从我的应用程序中的日历?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆