Android 通过intent打开Samsung S Planner时出现异常

Android 通过intent打开Samsung S Planner时出现异常,android,android-intent,nullpointerexception,Android,Android Intent,Nullpointerexception,我正在尝试打开已安装的日历应用程序,以便用户可以输入新事件。我使用下面的意图,它在Nexus和许多其他设备上运行良好 Intent intent = new Intent(Intent.ACTION_EDIT); intent.setType("vnd.android.cursor.item/event"); 目前唯一的问题是安装了S Planner日历应用程序的三星设备。执行意图时,LogCat中会显示以下异常,S Planner应用程序会严重崩溃(带有系统错误对话框) 在试图追踪Calen

我正在尝试打开已安装的日历应用程序,以便用户可以输入新事件。我使用下面的意图,它在Nexus和许多其他设备上运行良好

Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
目前唯一的问题是安装了S Planner日历应用程序的三星设备。执行意图时,LogCat中会显示以下异常,S Planner应用程序会严重崩溃(带有系统错误对话框)

在试图追踪
CalendarEventModel
中发生的事情时,我在中没有找到任何线索


有人知道如何正确启动S Planner来创建新事件吗?

我创建了这个用于创建日历事件的实用程序类,希望您觉得它有用:

public class CalendarOrganizer {
    private final static int ICE_CREAM_BUILD_ID = 14;
    /**
     * Creates a calendar intent going from startTime to endTime
     * @param startTime
     * @param endTime
     * @param context
     * @return true if the intent can be handled and was started, 
     * false if the intent can't be handled
     */
    public static boolean createEvent(long startTime, long endTime, String title, String description, 
            String location, boolean isAllDay, Context context) {
        Intent intent = new Intent(Intent.ACTION_EDIT);
        int sdk = android.os.Build.VERSION.SDK_INT;
        if(sdk < ICE_CREAM_BUILD_ID) {
            // all SDK below ice cream sandwich
            intent.setType("vnd.android.cursor.item/event");
            intent.putExtra("beginTime", startTime);
            intent.putExtra("endTime", endTime);
            intent.putExtra("title", title);
            intent.putExtra("description", description);
            intent.putExtra("eventLocation", location);
            intent.putExtra("allDay", isAllDay);

//          intent.putExtra("rrule", "FREQ=YEARLY");
        } else {
            // ice cream sandwich and above
            intent.setType("vnd.android.cursor.item/event");
            intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, startTime);
            intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime);
            intent.putExtra(Events.TITLE, title);
            intent.putExtra(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE);
            intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY , isAllDay);
            intent.putExtra(Events.DESCRIPTION, description);
            intent.putExtra(Events.EVENT_LOCATION, location);

//          intent.putExtra(Events.RRULE, "FREQ=DAILY;COUNT=10") 
        }
        try {
            context.startActivity(intent);
            return true;
        } catch(Exception e) {
            return false;
        }
    }
}
公共类日历管理器{
私人最终静态int冰淇淋构建ID=14;
/**
*创建从开始时间到结束时间的日历
*@param startTime
*@param endTime
*@param上下文
*@return true如果可以处理并启动意图,
*如果无法处理意图,则为false
*/
公共静态布尔createEvent(长开始时间、长结束时间、字符串标题、字符串描述、,
字符串位置、布尔值(isAllDay、上下文){
意向意向=新意向(意向.行动\编辑);
int sdk=android.os.Build.VERSION.sdk\u int;
如果(sdk<冰淇淋\u构建\u ID){
//所有的冰淇淋三明治
intent.setType(“vnd.android.cursor.item/event”);
intent.putExtra(“开始时间”,开始时间);
intent.putExtra(“结束时间”,结束时间);
意向。额外(“标题”,标题);
意图。额外(“说明”,说明);
intent.putExtra(“事件位置”,位置);
intent.putExtra(“全天”,即全天);
//意向。额外(“rrule”,“FREQ=年度”);
}否则{
//冰淇淋三明治及以上
intent.setType(“vnd.android.cursor.item/event”);
intent.putExtra(CalendarContract.EXTRA\u EVENT\u BEGIN\u TIME,startTime);
intent.putExtra(CalendarContract.EXTRA\u EVENT\u END\u TIME,endTime);
意向。额外(事件。标题,标题);
intent.putExtra(Events.ACCESS\u LEVEL,Events.ACCESS\u PRIVATE);
intent.putExtra(CalendarContract.EXTRA\u EVENT\u ALL\u DAY,isAllDay);
intent.putExtra(Events.DESCRIPTION,DESCRIPTION);
intent.putExtra(Events.EVENT_位置,位置);
//intent.putExtra(Events.RRULE,“FREQ=DAILY;COUNT=10”)
}
试一试{
背景。开始触觉(意图);
返回true;
}捕获(例外e){
返回false;
}
}
}

感谢您的各种回复。我已经弄明白了。S Planner需要设置开始和结束日期。否则它就会崩溃

Intent intent = new Intent(Intent.ACTION_INSERT).setData(Events.CONTENT_URI) .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime.getMillis()) .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime.getMillis()); Intent Intent=新Intent(Intent.ACTION\u INSERT).setData(Events.CONTENT\u URI) .putExtra(CalendarContract.EXTRA\u事件\u开始时间,beginTime.getMillis()) .putExtra(CalendarContract.EXTRA\u EVENT\u END\u TIME,endTime.getMillis());
有一些例子…我希望它会有用。谢谢你的提示。我帮助走上了正确的道路。 Intent intent = new Intent(Intent.ACTION_INSERT).setData(Events.CONTENT_URI) .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime.getMillis()) .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime.getMillis());