顾海波

【需求】鸿蒙接入获取token

  1 +/node_modules
  2 +/oh_modules
  3 +/local.properties
  4 +/.idea
  5 +**/build
  6 +/.hvigor
  7 +.cxx
  8 +/.clangd
  9 +/.clang-format
  10 +/.clang-tidy
  11 +**/.test
  12 +
  13 +/entry/libs/arm64-v8a/libflutter.so
  14 +/entry/src/main/resources/rawfile/flutter_assets
  15 +**.har
  16 +**/oh-package-lock.json5
  17 +BuildProfile.ets
  1 +/*
  2 +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
  3 +* Licensed under the Apache License, Version 2.0 (the "License");
  4 +* you may not use this file except in compliance with the License.
  5 +* You may obtain a copy of the License at
  6 +*
  7 +* http://www.apache.org/licenses/LICENSE-2.0
  8 +*
  9 +* Unless required by applicable law or agreed to in writing, software
  10 +* distributed under the License is distributed on an "AS IS" BASIS,
  11 +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12 +* See the License for the specific language governing permissions and
  13 +* limitations under the License.
  14 +*/
  15 +{
  16 + "apiType": "stageMode",
  17 + "buildOption": {
  18 + },
  19 + "targets": [
  20 + {
  21 + "name": "default"
  22 + },
  23 + {
  24 + "name": "flutter_push",
  25 + }
  26 + ]
  27 +}
  1 +/*
  2 +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
  3 +* Licensed under the Apache License, Version 2.0 (the "License");
  4 +* you may not use this file except in compliance with the License.
  5 +* You may obtain a copy of the License at
  6 +*
  7 +* http://www.apache.org/licenses/LICENSE-2.0
  8 +*
  9 +* Unless required by applicable law or agreed to in writing, software
  10 +* distributed under the License is distributed on an "AS IS" BASIS,
  11 +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12 +* See the License for the specific language governing permissions and
  13 +* limitations under the License.
  14 +*/
  15 +export { harTasks } from '@ohos/hvigor-ohos-plugin';
  1 +/*
  2 +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
  3 +* Licensed under the Apache License, Version 2.0 (the "License");
  4 +* you may not use this file except in compliance with the License.
  5 +* You may obtain a copy of the License at
  6 +*
  7 +* http://www.apache.org/licenses/LICENSE-2.0
  8 +*
  9 +* Unless required by applicable law or agreed to in writing, software
  10 +* distributed under the License is distributed on an "AS IS" BASIS,
  11 +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12 +* See the License for the specific language governing permissions and
  13 +* limitations under the License.
  14 +*/
  15 +import PushPlugin from './src/main/ets/com/ewin/flutter_push/FlutterPushPlugin';
  16 +export default PushPlugin;
  1 +/*
  2 +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
  3 +* Licensed under the Apache License, Version 2.0 (the "License");
  4 +* you may not use this file except in compliance with the License.
  5 +* You may obtain a copy of the License at
  6 +*
  7 +* http://www.apache.org/licenses/LICENSE-2.0
  8 +*
  9 +* Unless required by applicable law or agreed to in writing, software
  10 +* distributed under the License is distributed on an "AS IS" BASIS,
  11 +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12 +* See the License for the specific language governing permissions and
  13 +* limitations under the License.
  14 +*/
  15 +{
  16 + "name": "flutter_push",
  17 + "version": "1.0.0",
  18 + "description": "Please describe the basic information.",
  19 + "main": "index.ets",
  20 + "author": "",
  21 + "license": "Apache-2.0",
  22 + "dependencies": {
  23 + "@ohos/flutter_ohos": "file:./libs/flutter_embedding.har"
  24 + }
  25 +}
  1 +/*
  2 +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
  3 +* Licensed under the Apache License, Version 2.0 (the "License");
  4 +* you may not use this file except in compliance with the License.
  5 +* You may obtain a copy of the License at
  6 +*
  7 +* http://www.apache.org/licenses/LICENSE-2.0
  8 +*
  9 +* Unless required by applicable law or agreed to in writing, software
  10 +* distributed under the License is distributed on an "AS IS" BASIS,
  11 +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12 +* See the License for the specific language governing permissions and
  13 +* limitations under the License.
  14 +*/
  15 +import {
  16 + FlutterPlugin,
  17 + FlutterPluginBinding
  18 +} from '@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/FlutterPlugin';
  19 +import MethodChannel from '@ohos/flutter_ohos/src/main/ets/plugin/common/MethodChannel';
  20 +import PushPluginMethodChannelHandler from './PushPluginMethodChannelHandler';
  21 +import Log from '@ohos/flutter_ohos/src/main/ets/util/Log';
  22 +import StandardMethodCodec from '@ohos/flutter_ohos/src/main/ets/plugin/common/StandardMethodCodec';
  23 +
  24 +const TAG: string = "PushPlugin";
  25 +
  26 +export default class PushPlugin implements FlutterPlugin {
  27 + private methodChannel: MethodChannel | null = null;
  28 + private methodChannelHandler: PushPluginMethodChannelHandler | null = null;
  29 +
  30 + private pluginBing: FlutterPluginBinding | null = null;
  31 +
  32 + getUniqueClassName(): string {
  33 + return "PushPlugin";
  34 + }
  35 +
  36 + onAttachedToEngine(binding: FlutterPluginBinding): void {
  37 + Log.d(TAG, 'onAttachedToEngine connectivity plugin')
  38 +
  39 + this.methodChannel = new MethodChannel(binding.getBinaryMessenger(), "ewin:flutter_push", StandardMethodCodec.INSTANCE);
  40 + let methodChannelHandler = new PushPluginMethodChannelHandler(this.methodChannel);
  41 + this.methodChannel.setMethodCallHandler(methodChannelHandler);
  42 + this.pluginBing = binding;
  43 + }
  44 +
  45 + onDetachedFromEngine(binding: FlutterPluginBinding): void {
  46 + Log.d(TAG, 'onDetachedFromEngine connectivity plugin')
  47 + this.methodChannel?.setMethodCallHandler(null);
  48 + this.methodChannel = null;
  49 + this.pluginBing = null;
  50 + }
  51 +}
  1 +/*
  2 +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
  3 +* Licensed under the Apache License, Version 2.0 (the "License");
  4 +* you may not use this file except in compliance with the License.
  5 +* You may obtain a copy of the License at
  6 +*
  7 +* http://www.apache.org/licenses/LICENSE-2.0
  8 +*
  9 +* Unless required by applicable law or agreed to in writing, software
  10 +* distributed under the License is distributed on an "AS IS" BASIS,
  11 +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12 +* See the License for the specific language governing permissions and
  13 +* limitations under the License.
  14 +*/
  15 +import MethodCall from '@ohos/flutter_ohos/src/main/ets/plugin/common/MethodCall';
  16 +import { MethodCallHandler, MethodResult } from '@ohos/flutter_ohos/src/main/ets/plugin/common/MethodChannel';
  17 +import Log from '@ohos/flutter_ohos/src/main/ets/util/Log';
  18 +import { pushService } from '@kit.PushKit';
  19 +import { hilog } from '@kit.PerformanceAnalysisKit';
  20 +import { BusinessError } from '@kit.BasicServicesKit';
  21 +import { UIAbility, AbilityConstant, Want } from '@kit.AbilityKit';
  22 +import { MethodChannel } from '@ohos/flutter_ohos';
  23 +
  24 +const TAG: string = "PushPluginMethodChannelHandler";
  25 +
  26 +export default class PushPluginMethodChannelHandler implements MethodCallHandler {
  27 + private methodChannel: MethodChannel | null = null;
  28 +
  29 + constructor(methodChannel:MethodChannel) {
  30 + this.methodChannel = methodChannel
  31 + }
  32 +
  33 + onMethodCall(call: MethodCall, result: MethodResult): void {
  34 + Log.d(TAG, 'onMethodCall step in')
  35 + switch (call.method) {
  36 + case "init":
  37 + this.init(result);
  38 + break;
  39 + case "getRegId":
  40 + break;
  41 + default:
  42 + result.notImplemented();
  43 + break;
  44 + }
  45 + }
  46 +
  47 + async init(result: MethodResult): Promise<void> {
  48 + try {
  49 + const pushToken: string = await pushService.getToken();
  50 + const map:Map<string,string> =new Map<string,string>()
  51 + const params:Map<string,string> =new Map<string,string>()
  52 + params.set("platformName","huawei_ohos")
  53 + params.set("regId",pushToken)
  54 + map.set("type","ReceiveRegisterResult")
  55 + map.set("params", JSON.stringify(params))
  56 + this.methodChannel?.invokeMethod("onListener",map)
  57 + } catch (err) {
  58 + let e: BusinessError = err as BusinessError;
  59 + hilog.error(0x0000, 'testTag', 'Failed to get push token: %{public}d %{public}s', e.code, e.message);
  60 + }
  61 + result.success(true)
  62 + }
  63 +}
  64 +
  1 +/*
  2 +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
  3 +* Licensed under the Apache License, Version 2.0 (the "License");
  4 +* you may not use this file except in compliance with the License.
  5 +* You may obtain a copy of the License at
  6 +*
  7 +* http://www.apache.org/licenses/LICENSE-2.0
  8 +*
  9 +* Unless required by applicable law or agreed to in writing, software
  10 +* distributed under the License is distributed on an "AS IS" BASIS,
  11 +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12 +* See the License for the specific language governing permissions and
  13 +* limitations under the License.
  14 +*/
  15 +
  16 +{
  17 + "module": {
  18 + "name": "flutter_push",
  19 + "type": "har",
  20 + "deviceTypes": [
  21 + "default",
  22 + ],
  23 + "requestPermissions": [
  24 + {
  25 + "name": "ohos.permission.INTERNET"
  26 + },
  27 + {
  28 + "name": "ohos.permission.GET_NETWORK_INFO"
  29 + }
  30 + ]
  31 + }
  32 +}
  1 +{
  2 + "string": [
  3 + {
  4 + "name": "page_show",
  5 + "value": "page from npm package"
  6 + }
  7 + ]
  8 +}
  1 +{
  2 + "string": [
  3 + {
  4 + "name": "page_show",
  5 + "value": "page from npm package"
  6 + }
  7 + ]
  8 +}
  1 +{
  2 + "string": [
  3 + {
  4 + "name": "page_show",
  5 + "value": "page from npm package"
  6 + }
  7 + ]
  8 +}
@@ -51,6 +51,9 @@ flutter: @@ -51,6 +51,9 @@ flutter:
51 web: 51 web:
52 pluginClass: FlutterPushWeb 52 pluginClass: FlutterPushWeb
53 fileName: flutter_push_web.dart 53 fileName: flutter_push_web.dart
  54 + ohos:
  55 + package: com.ewin.flutter_push
  56 + pluginClass: FlutterPushPlugin
54 57
55 # To add assets to your plugin package, add an assets section, like this: 58 # To add assets to your plugin package, add an assets section, like this:
56 # assets: 59 # assets: