Updated on 2024-07-30 GMT+08:00

Displaying a Toast Message

ShowToast

API Description

This API is used to display a toast.

Precautions

  1. This API is an asynchronous API. The return value only indicates whether the API is successfully called. The actual service processing result is returned in the corresponding callback function.

Method Definition

1
HWM_SDK_AGENT_API hwmsdk::HwmErrCode ShowToast(const HwmToastInfo* toastInfo);

Callback Function

1
virtual void OnShowToastResult(hwmsdk::HwmErrCode ret, const char* reason) {};

Parameter Description

Table 1 Parameter description

Parameter

Mandatory

Type

Description

toastInfo

Yes

HwmToastInfo

Toast message.

Table 2 HwmToastInfo description

Parameter

Type

Description

content

char[]

Toast message.

duration

int

Display duration, in seconds.

Table 3 Return value

Type

Description

HwmErrCode

If 0 is returned, the operation is successful. If other values are returned, the operation fails. For details about values returned upon failures, see Common Error Codes.

Sample Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
/**
* Display a toast message.
*/
void demoShowToastDlg::OnBnClickedOk()
{
    hwmsdkagent::HwmToastInfo toastInfo{ 0 };
    std::string toastContent = "toastContent";
    strcpy_s(toastInfo.content, HWM_MAX_TOAST_CONTENT_LEN, toastContent.c_str());
    toastInfo.duration = 5;
 
    int ret = hwmsdkagent::ShowToast(&toastInfo);
    if (hwmsdk::HWM_COMMON_SUCCESS != ret)
    {
        AfxMessageBox(_T("show toast error"));
        return;
    }
}