Android实现调用系统日历

在我们编写代码的时候如果想在自己设定的某一天给出提醒功能,按照闹钟提醒方式就不能够解决这个问题了(只能设置时、分)。对于这个问题,比较简单(或者偷懒)的做法就是调用系统的日历,让系统自带的日历来给提醒。

在监听事件中添加以下几行代码就可以了。

	Intent intent = new Intent();  
		        intent.setComponent(new ComponentName("com.android.calendar", "com.android.calendar.LaunchActivity"));  
		        startActivity(intent);  

另外,值得注意的是:如果SDK版本小于8的,应该把com.android.calendar改为com.google.android.calendar

在一个网友的blog中发现一段比较好的写法:http://hi.baidu.com/sibylslove/item/5c0b03344d4ac75780f1a756  在此对他表示感谢!

try {
            Intent i = new Intent();
            ComponentName cn = null;
            if (Integer.parseInt(Build.VERSION.SDK) >= 8) {
                cn = new ComponentName("com.android.calendar",
                        "com.android.calendar.LaunchActivity");

            } else {
                cn = new ComponentName("com.google.android.calendar",
                        "com.android.calendar.LaunchActivity");
            }
            i.setComponent(cn);
            startActivity(i);
        } catch (ActivityNotFoundException e) {
            // TODO: handle exception
            Log.e("ActivityNotFoundException", e.toString());
        }


原文地址:https://www.cnblogs.com/jinfenglee/p/4388733.html