Error code 401 indicates that the provided context type is incorrect. You need to use the context of the UIAbility. To obtain UIAbilityContext, use the code snippet below:
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
export default class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
let uiAbilityContext = this.context;
// ...
}
} Reference