Android 有意打开任何日历应用程序(4.2.2 及更高版本)

标签 android android-intent calendar

我正在尝试做 3 件事。根据首选项中的选择,我想打开已安装的日历应用程序,在已安装的日历中显示事件详细信息,或者使用所需的已安装日历应用程序创建新事件。用户应该能够通过 android 框架的决策对话框来决定使用什么应用程序。

出于测试目的,除了谷歌日历应用程序之外,我还安装了 aCalendar 和 Jorte。 目前只有“创建新事件”列出了所有 3 个应用程序来执行此操作。

Intent intent = null;
intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");

当使用该操作仅打开日历或日历详细信息时,选择对话框中仅显示 aCalendar 和 google calendar。两者都工作正常。

这是我用来创建 Intent 的完整方法:

private Intent createCalendarIntent()
{
    long startMillis = System.currentTimeMillis();
    Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
    builder.appendPath("time");
    ContentUris.appendId(builder, startMillis);
    Intent intent = null;

    Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, 
                                         calHandle.getEventID(0));          

    switch(getPreferenceIntentAction())
    {
        case 1: intent = new Intent(Intent.ACTION_VIEW);
                            intent.setType("vnd.android.cursor.item/event");
                            intent.setData(builder.build());
            break;
        case 2: intent = new Intent(Intent.ACTION_VIEW);
                            intent.setType("vnd.android.cursor.item/event");
                            intent.setData(uri);
            break;
        case 3: intent = new Intent(Intent.ACTION_EDIT);
                            intent.setType("vnd.android.cursor.item/event");
            break;
            default:
                break;
    }

案例 1 只是在实际的一周打开日历,案例 2 是显示事件详细信息,案例 3 是创建一个新事件。

我不知道为什么 Jorte 没有出现。我认为这也会发生在其他日历应用程序上。

如何在不读取设备上所有已安装的应用程序和筛选日历应用程序的情况下也显示 op Jorte(以及其他应用程序),让用户在首选项中而不是在内置对话框中做出决定。

提前致谢!

最佳答案

I don't have any clue, why Jorte isn't showing up.

因为它是日历应用程序,而不是 Google 日历前端。您的其他两个 Intent 配置应该只被使用 CalendarContract 存储其事件的应用程序接受。 Jorte 可能不会,因为它的 Play 商店描述表明“它可以与谷歌日历同步”(强调我的),表明它不会一直将其事件存储在谷歌日历中。不要求所有日历应用程序都将其数据存储在 CalendarContract 中。

I think this will happen to other calendar apps too.

任何使用自己的数据存储的日历应用程序都应该按照 Jorte 的方式运行。

How is it possible to show op Jorte (and others too) too

根据定义,您不可能让任意日历应用程序支持您的第二个 Intent 配置。这是为了查看特定的 Google 日历条目,并非每个日历应用程序都会将其事件存储在 Google 日历中。

关于Android 有意打开任何日历应用程序(4.2.2 及更高版本),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18814924/

相关文章:

javascript - Android 模拟器上的 React-Native 错误 "null is not an object (evaluating ' blob.data') readAsText "

android - Parcelable with arraylist<CustomClass> 将值从 Activity 传递到 fragment android

java - startActivityForResult 两次

android - Retrofit、Gson 和一组异构对象

android - 没有这样的服务 ComponentInfo Android JobScheduler

Android 和 Phonegap : Intent to launch an other Application

Android:在选项卡内传输字符串/值,每个选项卡都有自己的 Activity (Getters-Setter 除外)

android - 获取 IllegalArgumentException : Cannot have both DTEND and DURATION in an event with updating a recurring all day event

iphone - 如何更改Tapku日历的背景图像

java - Calendar.getInstance()...基本问题