【问题标题】:How to open native calendar from titanium app?如何从钛应用程序打开本机日历?
【发布时间】:2023-11-13 08:14:02
【问题描述】:

如何从适用于 Android 和 iOS 的钛应用程序打开本机日历?如在单击按钮时,我想在 ipad 上打开本机日历。

【问题讨论】:

  • 为什么?你想让我做什么?只需打开应用程序?
  • 是的,我有一个名为“查看日历中的约会”的按钮。单击该按钮后,应打开本机日历

标签: titanium titanium-alloy


【解决方案1】:

在 android 中,您可以使用本机意图打开它,如 here 解释的那样

低于和高于 Gingerbread 的版本之间存在差异。正如this 问题末尾所述,HTC 设备也因 HTC Sense 软件而有所不同。

这是我测试过的 Titanium 代码:​​

    if (Titanium.Platform.osname=="android"){

        //Params needed to create the android intent.
        var packageStr = "com.google.android.calendar";
        var classStr = "com.android.calendar.LaunchActivity";
        var actionStr = Ti.Android.ACTION_VIEW;

        var model = Ti.Platform.model;


        if ((model.indexOf("HTC") != -1) || (model.indexOf("htc") != -1)){
            //If it's a HTC device
            packageStr = "com.htc.calendar";
            classStr = "com.htc.calendar.MonthActivity";
            actionStr = Ti.Android.ACTION_MAIN;
        }
        else {
            //For android versions before Gingerbread (2.3)
            var version = parseFloat(Ti.Platform.version);
            if (version < 2.4) packageStr = "com.android.calendar";
        }

        //Launch native calendar
        var intent = Ti.Android.createIntent({
            action: actionStr,
            packageName: packageStr,
            className: classStr
        });
        Ti.Android.currentActivity.startActivity(intent);
    }

你也可以打开原生日历的“创建事件”界面,通过和上面代码一样的方式为Titanium适配this

【讨论】:

  • 查看 Stef 的 iOS 答案。
【解决方案2】:

只需使用:

Titanium.Platform.openURL('CALSHOW://');

【讨论】:

  • 这仅适用于 iOS。有关答案的 android 部分,请参见 asanlo 的答案。
最近更新 更多