HarmonyOS鸿蒙Next中如何跳转到系统日历App并显示指定日期的提醒事件?

HarmonyOS鸿蒙Next中如何跳转到系统日历App并显示指定日期的提醒事件? 向日历插入新股上市提醒后,用户可以跳转到系统日历App中查看提醒事件

3 回复
import common from '@ohos.app.ability.common';
const context = getContext(this)

@Entry
@Component
struct Index{
  build(){
    Button("跳转到日历").onClick(()=>{
      let context = getContext(this) as common.UIAbilityContext;
      context.startAbility({
        bundleName: 'com.huawei.hmos.calendar',
        abilityName: 'MainAbility',
      });
    })
  }
}

当前只支持跳转,不能传参数到日历中指定具体日期

更多关于HarmonyOS鸿蒙Next中如何跳转到系统日历App并显示指定日期的提醒事件?的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS鸿蒙Next中,可以通过Intent跳转到系统日历App并显示指定日期的提醒事件。使用ohos.aafwk.ability.Intent类来构建跳转逻辑。首先,创建一个Intent实例,设置其Action"ohos.intent.action.VIEW",并指定Uri为日历的Uri,格式为content://com.android.calendar/time/加上时间戳。然后,使用startAbility(intent)方法启动跳转。具体代码如下:

import featureAbility from '@ohos.ability.featureAbility';
import ohos_data_uri from '@ohos.data.uri';

let date = new Date(2023, 10, 1).getTime(); // 指定日期的时间戳
let uri = ohos_data_uri.URI.parse(`content://com.android.calendar/time/${date}`);
let intent = {
    action: "ohos.intent.action.VIEW",
    uri: uri
};

featureAbility.startAbility(intent).then(() => {
    console.log("跳转成功");
}).catch((err) => {
    console.error("跳转失败", err);
});

这段代码会跳转到系统日历App,并显示指定日期的提醒事件。

在HarmonyOS鸿蒙Next中,你可以使用Intent来跳转到系统日历App并显示指定日期的提醒事件。具体代码如下:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, eventId));
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, dateInMillis);
startActivity(intent);

其中,eventId是事件的唯一标识,dateInMillis是指定日期的毫秒时间戳。通过这种方式,你可以直接跳转到系统日历并显示指定日期的提醒事件。

回到顶部