mirror of
https://gitee.com/openharmony/applications_app_samples
synced 2024-11-26 18:20:47 +00:00
Description: 事件通知新增ndk sample示例 Sig: sig-systemapplications Feature or Bugfix: Feature Binary Source: No Signed-off-by: wangsen1994 <wangsen51@huawei.com>
This commit is contained in:
parent
e5146d435d
commit
57c44aefa7
5
OAT.xml
5
OAT.xml
@ -339,6 +339,11 @@ Note:If the text contains special characters, please escape them according to th
|
||||
<filteritem type="filepath" name="code/BasicFeature/Native/NdkQoS/screenshots/device/main.jpeg" desc="Provided by code/BasicFeature/Native/NdkNativeQoS"/>
|
||||
<filteritem type="filepath" name="code/BasicFeature/Native/NdkQoS/screenshots/device/showhighQoScomputingTime.jpeg" desc="Provided by code/BasicFeature/Native/NdkNativeQoS"/>
|
||||
<filteritem type="filepath" name="code/BasicFeature/Native/NdkQoS/entry/src/main/resources/base/media/icon.png" desc="Provided by code/BasicFeature/Native/NdkNativeQoS"/>
|
||||
<filteritem type="filepath" name="code/BasicFeature/Native/NdkNotification/entry/src/main/resources/base/media/startIcon.png" desc="Provided by code/BasicFeature/Native/NdkNotification/"/>
|
||||
<filteritem type="filepath" name="code/BasicFeature/Native/NdkNotification/screenshots/device/turnOnNotification.jpeg" desc="Provided by code/BasicFeature/Native/NdkNotification/"/>
|
||||
<filteritem type="filepath" name="code/BasicFeature/Native/NdkNotification/AppScope/resources/base/media/app_icon.png" desc="Provided by code/BasicFeature/Native/NdkNotification/"/>
|
||||
<filteritem type="filepath" name="code/BasicFeature/Native/NdkNotification/screenshots/device/main.jpeg" desc="Provided by code/BasicFeature/Native/NdkNotification/"/>
|
||||
<filteritem type="filepath" name="code/BasicFeature/Native/NdkNotification/screenshots/device/turnOffNotification.jpeg" desc="Provided by code/BasicFeature/Native/NdkNotification/"/>
|
||||
<filteritem type="filepath" name="code/BasicFeature/Extension/Contexttest/entry/src/main/resources/base/media/icon.png" desc="Provided by code/BasicFeature/Extension/Contexttest"/>
|
||||
<filteritem type="filepath" name="code/BasicFeature/Extension/Contexttest/entry/src/main/resources/base/media/startIcon.png" desc="Provided by code/BasicFeature/Extension/Contexttest"/>
|
||||
<filteritem type="filepath" name="code/BasicFeature/Extension/Contexttest/screenshots/extension1.jpeg" desc="Provided by code/BasicFeature/Extension/Contexttest"/>
|
||||
|
10
README_zh.md
10
README_zh.md
@ -42,7 +42,7 @@
|
||||
<td width="170" x:str><a href="code/UI/ArkTsComponentCollection/StateManagement">状态管理</a></td>
|
||||
</tr>
|
||||
<tr height="18" style='height:13.50pt;'>
|
||||
<td height="270" align="center" rowspan="29" style='height:202.50pt' x:str><strong>基础特性</strong></td>
|
||||
<td height="270" align="center" rowspan="30" style='height:202.50pt' x:str><strong>基础特性</strong></td>
|
||||
<td x:str><strong>能力增强</strong></td>
|
||||
<td x:str><a href="code/BasicFeature/Ability/AbilityFeature">基础能力增强</a></td>
|
||||
<td x:str><a href="code/BasicFeature/Ability/AppStartup">应用启动框架startup</a></td>
|
||||
@ -216,7 +216,7 @@
|
||||
<td ></td>
|
||||
</tr>
|
||||
<tr height="18" style='height:13.50pt;'>
|
||||
<td rowspan="3" x:str><strong>Native</strong></td>
|
||||
<td rowspan="4" x:str><strong>Native</strong></td>
|
||||
<td x:str><a href="code/BasicFeature/Native/NdkRawfile">获取Rawfile资源</a></td>
|
||||
<td x:str><a href="code/BasicFeature/Native/NdkXComponent">Native XComponent(API 10)</a></td>
|
||||
<td x:str><a href="code/BasicFeature/Native/NdkOpenGL">OpenGL三棱椎(API 10)</a></td>
|
||||
@ -233,6 +233,12 @@
|
||||
<td x:str><a href="code/BasicFeature/Native/NdkQoS">Native QoS</a></td>
|
||||
<td x:str><a href="code/BasicFeature/Native/NdkVulkan">XComponent组件对接Vulkan</a></td>
|
||||
<td x:str><a href="code/BasicFeature/Native/XComponent">XComponent</a></td>
|
||||
</tr>
|
||||
<tr height="18" style='height:13.50pt;'>
|
||||
<td x:str><a href="code/BasicFeature/Native/NdkNotification">Native Notification</a></td>
|
||||
<td ></td>
|
||||
<td ></td>
|
||||
<td ></td>
|
||||
</tr>
|
||||
<tr height="18" style='height:13.50pt;'>
|
||||
<td height="90" align="center" rowspan="26" style='height:67.50pt;' x:str><strong>系统特性(仅对系统应用开放)</strong></td>
|
||||
|
12
code/BasicFeature/Native/NdkNotification/.gitignore
vendored
Normal file
12
code/BasicFeature/Native/NdkNotification/.gitignore
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
/node_modules
|
||||
/oh_modules
|
||||
/local.properties
|
||||
/.idea
|
||||
**/build
|
||||
/.hvigor
|
||||
.cxx
|
||||
/.clangd
|
||||
/.clang-format
|
||||
/.clang-tidy
|
||||
**/.test
|
||||
/.appanalyzer
|
25
code/BasicFeature/Native/NdkNotification/AppScope/app.json5
Normal file
25
code/BasicFeature/Native/NdkNotification/AppScope/app.json5
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
{
|
||||
"app": {
|
||||
"bundleName": "com.examples.ndknotification",
|
||||
"vendor": "example",
|
||||
"versionCode": 1000000,
|
||||
"versionName": "1.0.0",
|
||||
"icon": "$media:app_icon",
|
||||
"label": "$string:app_name"
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "app_name",
|
||||
"value": "NdkNotification"
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
76
code/BasicFeature/Native/NdkNotification/README_zh.md
Normal file
76
code/BasicFeature/Native/NdkNotification/README_zh.md
Normal file
@ -0,0 +1,76 @@
|
||||
# 通知服务
|
||||
|
||||
### 介绍
|
||||
|
||||
本示例主要介绍开发者如何使用Native Notification接口使用通知服务。当前功能包含查询当前应用通知使能状态。
|
||||
|
||||
### 效果预览
|
||||
|
||||
| 主页 | 弹窗显示开启通知使能状态 | 弹窗显示未开启通知使能状态 |
|
||||
| ------------------------------------ | --------------------------------------------- | --------------------------------------------------- |
|
||||
| ![main](screenshots/device/main.jpeg) | ![draw star](screenshots/device/turnOffNotification.jpeg) | ![change color](screenshots/device/turnOnNotification.jpeg) |
|
||||
|
||||
使用说明
|
||||
|
||||
1. 安装编译生成的Hap包,并打开应用。
|
||||
2. 点击页面中的"Check Notification Enable"按钮,页面将弹窗显示该应用的通知使能状态。
|
||||
3. 点击弹窗中的"OK"按钮则返回主页面。
|
||||
4. 通过下拉通知中心页面,点击设置按钮进入通知管理页面,修改当前应用的通知使能状态后,可以再次点击按钮查询。
|
||||
|
||||
### 工程目录
|
||||
|
||||
```
|
||||
entry/src/main/
|
||||
|---main
|
||||
| |---cpp
|
||||
| | |---types
|
||||
| | | |---libentry
|
||||
| | | | |---index.d.ts // 接口导出
|
||||
| | | | |---oh-package.json5
|
||||
| | |---NativeNotificationAdaptor.cpp // 调用native接口
|
||||
| | |---CMakeLists.txt // 编译脚本
|
||||
| |---ets
|
||||
| | |---entryability
|
||||
| | | |---EntryAbility.ets
|
||||
| | |---pages
|
||||
| | | |---Index.ets // 首页
|
||||
| |---resources // 静态资源
|
||||
|---ohosTest
|
||||
| |---ets
|
||||
| | |---tests
|
||||
| | | |---Ability.test.ets // 自动化测试用例
|
||||
```
|
||||
|
||||
### 具体实现
|
||||
|
||||
通过在IDE中创建Native C++工程,在C++代码中定义对外接口为isNotificationEnabled,映射C++接口IsNotificationEnabled。通过获取JS的资源对象,并转化为Native的资源对象,即可调用对外开放的Native接口。在JS侧导入"libentry.so",调用src/main/cpp/type/libentry/index.d.ts中声明的接口。源代码参考:[NativeNotificationAdaptor.cpp](entry/src/main/cpp/NativeNotificationAdaptor.cpp)。其中涉及的相关接口:
|
||||
|
||||
| 接口名 | 描述 |
|
||||
|:-------------------------------|:-------------------------------------------------------------------------------------------------------|
|
||||
| bool OH_Notification_IsNotificationEnabled(void); | 查询当前应用通知使能状态。 |
|
||||
|
||||
### 相关权限
|
||||
|
||||
不涉及
|
||||
|
||||
### 依赖
|
||||
|
||||
不涉及。
|
||||
|
||||
### 约束与限制
|
||||
|
||||
1. 本示例仅支持标准系统上运行,支持设备:RK3568;
|
||||
2. 本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.43;
|
||||
3. 本示例需要使用DevEco Studio NEXT Release(5.0.3.900)才可编译运行;
|
||||
|
||||
### 下载
|
||||
|
||||
如需单独下载本工程,执行如下命令:
|
||||
|
||||
```
|
||||
git init
|
||||
git config core.sparsecheckout true
|
||||
echo code/BasicFeature/Native/NdkNotification/ > .git/info/sparse-checkout
|
||||
git remote add origin https://gitee.com/openharmony/applications_app_samples.git
|
||||
git pull origin ***(分支名)
|
||||
```
|
56
code/BasicFeature/Native/NdkNotification/build-profile.json5
Normal file
56
code/BasicFeature/Native/NdkNotification/build-profile.json5
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
{
|
||||
"app": {
|
||||
"products": [
|
||||
{
|
||||
"name": "default",
|
||||
"signingConfig": "default",
|
||||
"compileSdkVersion": 14,
|
||||
"compatibleSdkVersion": 14,
|
||||
"runtimeOS": "OpenHarmony",
|
||||
"buildOption": {
|
||||
"strictMode": {
|
||||
"caseSensitiveCheck": true,
|
||||
"useNormalizedOHMUrl": true
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"buildModeSet": [
|
||||
{
|
||||
"name": "debug"
|
||||
},
|
||||
{
|
||||
"name": "release"
|
||||
}
|
||||
]
|
||||
},
|
||||
"modules": [
|
||||
{
|
||||
"name": "entry",
|
||||
"srcPath": "./entry",
|
||||
"targets": [
|
||||
{
|
||||
"name": "default",
|
||||
"applyToProducts": [
|
||||
"default"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
6
code/BasicFeature/Native/NdkNotification/entry/.gitignore
vendored
Normal file
6
code/BasicFeature/Native/NdkNotification/entry/.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
/node_modules
|
||||
/oh_modules
|
||||
/.preview
|
||||
/build
|
||||
/.cxx
|
||||
/.test
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
{
|
||||
"apiType": "stageMode",
|
||||
"buildOption": {
|
||||
"externalNativeOptions": {
|
||||
"path": "./src/main/cpp/CMakeLists.txt",
|
||||
"arguments": "",
|
||||
"cppFlags": "",
|
||||
"abiFilters": ["arm64-v8a", "armeabi-v7a", "x86_64"]
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"name": "default",
|
||||
"runtimeOS": "OpenHarmony"
|
||||
},
|
||||
{
|
||||
"name": "ohosTest",
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
import { hapTasks } from '@ohos/hvigor-ohos-plugin';
|
||||
|
||||
export default {
|
||||
system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
|
||||
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "entry",
|
||||
"version": "1.0.0",
|
||||
"description": "Please describe the basic information.",
|
||||
"main": "",
|
||||
"author": "",
|
||||
"license": "",
|
||||
"dependencies": {
|
||||
"libentry.so": "file:./src/main/cpp/types/libentry"
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
# the minimum version of CMake.
|
||||
cmake_minimum_required(VERSION 3.5.0)
|
||||
project(NdkNotification)
|
||||
|
||||
set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
if(DEFINED PACKAGE_FIND_FILE)
|
||||
include(${PACKAGE_FIND_FILE})
|
||||
endif()
|
||||
|
||||
include_directories(${NATIVERENDER_ROOT_PATH}
|
||||
${NATIVERENDER_ROOT_PATH}/include)
|
||||
|
||||
add_library(entry SHARED NativeNotificationAdaptor.cpp)
|
||||
target_link_libraries(entry PUBLIC libace_napi.z.so libohnotification.so)
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "napi/native_api.h"
|
||||
#include <NotificationKit/notification.h>
|
||||
|
||||
static napi_value IsNotificationEnabled(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value result;
|
||||
bool enable = OH_Notification_IsNotificationEnabled();
|
||||
napi_get_boolean(env, enable, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
EXTERN_C_START
|
||||
static napi_value Init(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_property_descriptor desc[] = {
|
||||
{ "isNotificationEnabled", nullptr, IsNotificationEnabled, nullptr, nullptr, nullptr, napi_default, nullptr }
|
||||
};
|
||||
napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
|
||||
return exports;
|
||||
}
|
||||
EXTERN_C_END
|
||||
|
||||
static napi_module demoModule = {
|
||||
.nm_version = 1,
|
||||
.nm_flags = 0,
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = Init,
|
||||
.nm_modname = "entry",
|
||||
.nm_priv = ((void*)0),
|
||||
.reserved = { 0 },
|
||||
};
|
||||
|
||||
extern "C" __attribute__((constructor)) void RegisterEntryModule(void)
|
||||
{
|
||||
napi_module_register(&demoModule);
|
||||
}
|
16
code/BasicFeature/Native/NdkNotification/entry/src/main/cpp/types/libentry/Index.d.ts
vendored
Normal file
16
code/BasicFeature/Native/NdkNotification/entry/src/main/cpp/types/libentry/Index.d.ts
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export const isNotificationEnabled: () => boolean;
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "libentry.so",
|
||||
"types": "./Index.d.ts",
|
||||
"version": "1.0.0",
|
||||
"description": "Please describe the basic information."
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
|
||||
import { hilog } from '@kit.PerformanceAnalysisKit';
|
||||
import { window } from '@kit.ArkUI';
|
||||
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
|
||||
}
|
||||
|
||||
onDestroy(): void {
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage: window.WindowStage): void {
|
||||
// Main window is created, set main page for this ability
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
|
||||
|
||||
windowStage.loadContent('pages/Index', (err) => {
|
||||
if (err.code) {
|
||||
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
|
||||
return;
|
||||
}
|
||||
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.');
|
||||
});
|
||||
}
|
||||
|
||||
onWindowStageDestroy(): void {
|
||||
// Main window is destroyed, release UI related resources
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
|
||||
}
|
||||
|
||||
onForeground(): void {
|
||||
// Ability has brought to foreground
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
|
||||
}
|
||||
|
||||
onBackground(): void {
|
||||
// Ability has back to background
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
|
||||
}
|
||||
};
|
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import testNapi from 'libentry.so';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
@State message: string = 'Native Notification Sample';
|
||||
@Provide('pageInfo') pageInfo: NavPathStack = new NavPathStack();
|
||||
@State result:Boolean = false;
|
||||
|
||||
privacyDialogController: CustomDialogController = new CustomDialogController({
|
||||
builder: CustomDialogExample({ result: $result }),
|
||||
autoCancel: false,
|
||||
alignment: DialogAlignment.Center,
|
||||
customStyle: false,
|
||||
backgroundColor: Color.White,
|
||||
});
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
Column() {
|
||||
Text(this.message)
|
||||
.fontSize(30)
|
||||
.fontWeight(700)
|
||||
.textAlign(TextAlign.Start)
|
||||
.margin({ top: 56, left:16, right: 16 })
|
||||
}
|
||||
.width('100%')
|
||||
.height(px2vp(280))
|
||||
.alignItems(HorizontalAlign.Start)
|
||||
|
||||
Column() {
|
||||
Row() {
|
||||
Button('Check notification enabled')
|
||||
.layoutWeight(1)
|
||||
.fontSize(18)
|
||||
.onClick(() => {
|
||||
this.result = testNapi.isNotificationEnabled();
|
||||
this.privacyDialogController.open();
|
||||
})
|
||||
.margin({ left: 16, right: 16 })
|
||||
}
|
||||
.width('100%')
|
||||
.margin({bottom: 16})
|
||||
}
|
||||
.justifyContent(FlexAlign.End)
|
||||
.width('100%')
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.justifyContent(FlexAlign.SpaceBetween)
|
||||
}
|
||||
}
|
||||
|
||||
@CustomDialog
|
||||
struct CustomDialogExample {
|
||||
@Link result: Boolean;
|
||||
|
||||
controller?: CustomDialogController;
|
||||
cancel: () => void = () => {
|
||||
}
|
||||
confirm: () => void = () => {
|
||||
}
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
Text('Native Notification Sample')
|
||||
.fontSize(24)
|
||||
.fontWeight(700)
|
||||
.height(px2vp(100))
|
||||
Text('Current application notification enabled: ' + this.result)
|
||||
.fontSize(18)
|
||||
.fontWeight(400)
|
||||
.textAlign(TextAlign.Start)
|
||||
.margin({ left: px2vp(84), right: px2vp(84) })
|
||||
.width('90%')
|
||||
Button('OK', { buttonStyle: ButtonStyleMode.TEXTUAL, role: ButtonRole.NORMAL })
|
||||
.onClick(() => {
|
||||
if (this.controller != undefined) {
|
||||
this.controller.close();
|
||||
}
|
||||
})
|
||||
.stateEffect(false)
|
||||
.fontSize(18)
|
||||
.fontWeight(500)
|
||||
.margin(5)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
{
|
||||
"module": {
|
||||
"name": "entry",
|
||||
"type": "entry",
|
||||
"description": "$string:module_desc",
|
||||
"mainElement": "EntryAbility",
|
||||
"deviceTypes": [
|
||||
"default",
|
||||
"tablet"
|
||||
],
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false,
|
||||
"pages": "$profile:main_pages",
|
||||
"abilities": [
|
||||
{
|
||||
"name": "EntryAbility",
|
||||
"srcEntry": "./ets/entryability/EntryAbility.ets",
|
||||
"description": "$string:EntryAbility_desc",
|
||||
"icon": "$media:startIcon",
|
||||
"label": "$string:EntryAbility_label",
|
||||
"startWindowIcon": "$media:startIcon",
|
||||
"startWindowBackground": "$color:start_window_background",
|
||||
"exported": true,
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "start_window_background",
|
||||
"value": "#FFFFFF"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "module description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "NotificationSample"
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
@ -0,0 +1,3 @@
|
||||
{
|
||||
"allowToBackupRestore": true
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
{
|
||||
"src": [
|
||||
"pages/Index"
|
||||
]
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "module description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "NotificationSample"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "模块描述"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "NotificationSample"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
|
||||
import { describe, it, expect } from '@ohos/hypium';
|
||||
import { Driver, ON } from '@ohos.UiTest';
|
||||
|
||||
const TAG = '[Sample_NativeNotificationAPI]';
|
||||
|
||||
|
||||
export default function abilityTest() {
|
||||
describe('ActsAbilityTest', () => {
|
||||
/**
|
||||
* @tc.number: StartAbility_001
|
||||
* @tc.name: StartAbility_001
|
||||
* @tc.desc: open the hap
|
||||
*/
|
||||
it('StartAbility_001', 0, async (done: Function) => {
|
||||
console.info(TAG, 'StartAbility_001 begin');
|
||||
let driver = Driver.create();
|
||||
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
|
||||
try {
|
||||
await abilityDelegator.startAbility({
|
||||
bundleName: 'com.examples.ndknotification',
|
||||
abilityName: 'EntryAbility'
|
||||
});
|
||||
} catch (exception) {
|
||||
console.info(TAG, `StartAbility_001 exception = ${JSON.stringify(exception)}`);
|
||||
expect().assertFail();
|
||||
}
|
||||
await driver.delayMs(1000);
|
||||
await driver.assertComponentExist(ON.text('Check notification enabled'));
|
||||
await driver.delayMs(2000);
|
||||
done();
|
||||
console.info(TAG, 'StartAbility_001 end');
|
||||
})
|
||||
|
||||
/**
|
||||
* @tc.number: NativeNotification_001
|
||||
* @tc.name: NativeNotification_001
|
||||
* @tc.desc: detect and click the button to check application notification enabled
|
||||
*/
|
||||
it('NativeNotification_001', 0, async (done: Function) => {
|
||||
console.info(TAG, 'NativeNotification_001 begin');
|
||||
let driver = Driver.create();
|
||||
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
|
||||
try {
|
||||
await abilityDelegator.startAbility({
|
||||
bundleName: 'com.examples.ndknotification',
|
||||
abilityName: 'EntryAbility'
|
||||
});
|
||||
} catch (exception) {
|
||||
console.info(TAG, `StartAbility_001 exception = ${JSON.stringify(exception)}`);
|
||||
expect().assertFail();
|
||||
}
|
||||
await driver.delayMs(1000);
|
||||
await driver.assertComponentExist(ON.text('Check notification enabled'));
|
||||
let btn = await driver.findComponent(ON.text('Check notification enabled'));
|
||||
// 点击'Check notification enabled'按钮
|
||||
await btn.click();
|
||||
await driver.delayMs(1000);
|
||||
await driver.assertComponentExist(ON.text('OK'));
|
||||
await driver.delayMs(2000);
|
||||
await driver.findComponent(ON.text('OK'));
|
||||
await btn.click();
|
||||
await driver.delayMs(1000);
|
||||
done();
|
||||
console.info(TAG, 'NativeNotification_001 end');
|
||||
})
|
||||
})
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import abilityTest from './Ability.test';
|
||||
|
||||
export default function testsuite() {
|
||||
abilityTest();
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
{
|
||||
"module": {
|
||||
"name": "entry_test",
|
||||
"type": "feature",
|
||||
"deviceTypes": [
|
||||
"default",
|
||||
"tablet"
|
||||
],
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
{
|
||||
"modelVersion": "5.0.0",
|
||||
"dependencies": {
|
||||
}
|
||||
}
|
21
code/BasicFeature/Native/NdkNotification/hvigorfile.ts
Normal file
21
code/BasicFeature/Native/NdkNotification/hvigorfile.ts
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { appTasks } from '@ohos/hvigor-ohos-plugin';
|
||||
|
||||
export default {
|
||||
system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
|
||||
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
|
||||
}
|
10
code/BasicFeature/Native/NdkNotification/oh-package.json5
Normal file
10
code/BasicFeature/Native/NdkNotification/oh-package.json5
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"modelVersion": "5.0.0",
|
||||
"description": "Please describe the basic information.",
|
||||
"dependencies": {
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ohos/hypium": "1.0.19",
|
||||
"@ohos/hamock": "1.0.0"
|
||||
}
|
||||
}
|
11
code/BasicFeature/Native/NdkNotification/ohosTest.md
Normal file
11
code/BasicFeature/Native/NdkNotification/ohosTest.md
Normal file
@ -0,0 +1,11 @@
|
||||
# Native Notification 测试用例归档
|
||||
|
||||
## 用例表
|
||||
|
||||
| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 |
|
||||
|---------|---------------|-------------|-------------|------|------|
|
||||
| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass |
|
||||
| 查询当前应用通知使能状态 | 设备正常运行,拉起位于首页 | 点击查询按钮 | 查询成功,显示查询结果 | 是 | Pass |
|
||||
|
||||
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
Binary file not shown.
After Width: | Height: | Size: 42 KiB |
Binary file not shown.
After Width: | Height: | Size: 42 KiB |
Loading…
Reference in New Issue
Block a user