An ASCF atomic service is developed based on ASCF. Unlike atomic services built with ArkTS, it cannot accept custom Want parameters directly. ASCF defines a standard: The caller must pass parameters in a fixed format (Want.parameters.ascfPara). Only in this way can ASCF receive Want parameters and deliver them to the page.
The structure of the ascfPara object is as follows:
interface ascfPara {
path: string; // Target page route path. Custom parameters can be appended via a question mark (?).
extraData: object; // Object carrying additional parameters.
} The following describes how to launch the ASCF atomic service with parameters across different channels, along with the sample code.
Pass parameters through the Want object. Set ascfPara under Want.parameters. The ascfPara value can be passed either as an object or a JSON-formatted string, and it accepts the path and extraData fields.
Example:
import { common, Want } from '@kit.AbilityKit';
@Entry
@Component
struct Index {
build() {
Column() {
Button('Open')
.onClick(() => {
const context = this.getUIContext().getHostContext() as common.UIAbilityContext;
const wantInfo: Want = {
deviceId: '', // An empty deviceId indicates the local device.
bundleName: 'com.atomicservice.xxx', // Bundle name of the target atomic service.
abilityName: 'xxx', // Ability name of the target atomic service.
parameters: {
// If a parameter contains Chinese characters, you are advised to perform transcoding.
// ascfPara: encodeURIComponent(JSON.stringify({
// path: 'pages/index/index?data=Chinese',
// extraData: {}
// }))
ascfPara: {
path: 'pages/index/index?data=testData',
extraData: {}
}
},
};
context.startAbility(wantInfo);
})
}
}
} For details, please refer to Redirecting to an Application Page (router Event) Use the postCardAction API to implement the interaction between a widget and an atomic service. Refer to the Want parameter passing rules. The params parameter of postCardAction corresponds to Want.parameters. Different from the method of launching an ASCF atomic service via an API, this method requires ascfPara to be passed exclusively as a JSON-formatted string.
Example:
@Entry
@Component
struct Index {
build() {
Column() {
Button('Open')
.onClick(() => {
postCardAction(this, {
action: 'router',
abilityName: 'xxx', // Ability name of the target atomic service.
params: {
ascfPara: encodeURIComponent(JSON.stringify({
path: 'pages/index/index?data=testData',
extraData: Object({})
}))
}
});
})
}
}
} For details, please refer to Pushing Account-based Subscription Notifications. The server launches the atomic service by setting the clickAction parameter. Refer to the Want parameter passing rules. The data field corresponds to Want.parameters. ascfPara can be passed as an object or a JSON-formatted string.
Example:
// Request URL
POST 'https://push-api.cloud.huawei.com/v1/[projectId]/service_notification/send'
// Request Header
Authorization: Bearer eyJr*****OiIx---****.eyJh*****iJodHR--***.QRod*****4Gp---****
// Request Body
{
"msgId": "2**********80",
"appId": "6**********972",
"toOpenId": "A**********O",
"templateId": "1**********2",
"templateParams": {
"thing_0": "N0001",
"time_1": "April 17, 2026 22:22",
"thing_2": "xxx"
},
"clickAction": {
"actionType": 0,
"data": {
"ascfPara": {
"path": "pages/index/index?data=testData",
"extraData": {}
}
}
}
} For details, please refer to Using an Atomic Service Link for Atomic Service Redirection. When creating an atomic service link supported by App Linking in AppGallery Connect, you can pass parameters in two modes: static parameter passing and dynamic parameter passing.
For details about static parameter passing, please refer to Obtaining the Atomic Service Link.
Currently, ASCF does not support dynamic parameter passing. You need to handle it by yourself.
Append dynamic parameters to the end of the App Linking URL. For example, https://hoas.drcn.agconnect.link/xxx?ascfPara=value. The part following the question mark (?) represents dynamic parameters, which you can customize as needed. No additional configuration is required in AppGallery Connect. Refer to the following for value passing:
encodeURIComponent(JSON.stringify({
path: 'page/index/index?data=testData',
extraData: {}
})) Process dynamic parameters in the EntryAbility of the target atomic service and then pass the parameters to ASCF for processing.
Example:
import { AscfUIAbility } from '@atomicservice/ascfapi';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import { Want } from '@kit.AbilityKit';
import { url } from '@kit.ArkTS';
export default class EntryAbility extends AscfUIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
this.handleUri(want);
super.onCreate(want, launchParam);
}
onNewWant(want: Want): void {
this.handleUri(want);
super.onNewWant(want);
}
handleUri(want: Want): void {
// If you want to retain the static parameters of App Linking, obtain the value of Want.parameters['ascfPara'] and then merge the parameters.
let uri = want?.uri;
if (uri) {
try {
let urlObject = url.URL.parseURL(uri);
let ascfPara = urlObject.params.get('ascfPara');
if(ascfPara) {
want.parameters = {
'ascfPara': ascfPara
}
}
} catch (error) {
console.error('Failed to parse url');
}
}
}
}
When Intents Kit is used to launch the ASCF atomic service, parameters cannot be carried:
For details, please refer to Intents Kit - Location-based Recommendation Solution - Integration Solution. Currently, only the home page of the ASCF atomic service can be launched, and ascfPara cannot be received for page redirection.
Currently, ASCF receives and processes ascfPara parameters only in the onCreate and onNewWant callbacks. Parameter passing for Intents Kit requires POI parameters to be configured in AppGallery Connect. The corresponding parameters are obtained via the onExecuteInUIAbilityForegroundMode callback in the intent implementation class InsightIntentExecutorImpl. According to the lifecycle execution sequence of the base class for intent execution, onCreate and onNewWant are called earlier than onExecuteInUIAbilityForegroundMode. Therefore, after using the onExecuteInUIAbilityForegroundMode callback to construct ascfPara, you cannot pass the parameters to onCreate or onNewWant.
After the ASCF atomic service is launched using the preceding methods, the following situations may occur:
If the caller passes path in ascfPara and the page corresponding to path exists, the atomic service launches and navigates to the corresponding page.
If path is not passed or the page corresponding to path does not exist, the home page of the atomic service is displayed.
Obtaining launch parameters:
Obtain the parameters in the onLaunch or onShow callback of the App() method in the ascf/ascf_src/app.js file of the target atomic service.
Obtain the parameters in the onLoad callback of the Page() method in the JS file of the target atomic service page specified by path.
The extraData parameter can be obtained only in the onLaunch and onShow callbacks of the App() method.
Example:
// app.js
App({
onLaunch(options) {
let path = options.path; // page/index/index
let data = options.query; // {'data': 'testData'}
let extraData = options.referrerInfo.extraData;
console.info('data = ', data);
console.info('path = ', path);
console.info('extraData = ', extraData);
},
onShow(options) {
let path = options.path; // page/index/index
let data = options.query; // {'data': 'testData'}
let extraData = options.referrerInfo.extraData;
console.info('data = ', data);
console.info('path = ', path);
console.info('extraData = ', extraData);
}
});
// page/index/index.js
Page({
onLoad(query){
console.info('query = ', query); // {'data': 'testData'}
}
});