diff --git a/doric-android/doric/src/main/java/pub/doric/plugin/NotificationPlugin.java b/doric-android/doric/src/main/java/pub/doric/plugin/NotificationPlugin.java index 2b8f6b0c..28edbc5d 100644 --- a/doric-android/doric/src/main/java/pub/doric/plugin/NotificationPlugin.java +++ b/doric-android/doric/src/main/java/pub/doric/plugin/NotificationPlugin.java @@ -46,8 +46,8 @@ import pub.doric.extension.bridge.DoricPromise; @DoricPlugin(name = "notification") public class NotificationPlugin extends DoricJavaPlugin { - private HashMap systemReceivers = new HashMap<>(); - private HashMap localReceivers = new HashMap<>(); + private final HashMap systemReceivers = new HashMap<>(); + private final HashMap localReceivers = new HashMap<>(); public NotificationPlugin(DoricContext doricContext) { super(doricContext); @@ -74,7 +74,12 @@ public class NotificationPlugin extends DoricJavaPlugin { Intent intent = new Intent(name); intent.putExtra("__doric_data__", data); if (androidSystem) { - getDoricContext().getContext().sendBroadcast(intent); + String permission = null; + JSValue jsValue = args.getProperty("permission"); + if (jsValue.isString()) { + permission = jsValue.asString().value(); + } + getDoricContext().getContext().sendBroadcast(intent, permission); } else { LocalBroadcastManager.getInstance(getDoricContext().getContext()).sendBroadcast(intent); } @@ -125,7 +130,12 @@ public class NotificationPlugin extends DoricJavaPlugin { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(name); if (androidSystem) { - getDoricContext().getContext().registerReceiver(receiver, intentFilter); + String permission = null; + JSValue jsValue = args.getProperty("permission"); + if (jsValue.isString()) { + permission = jsValue.asString().value(); + } + getDoricContext().getContext().registerReceiver(receiver, intentFilter, permission, null); systemReceivers.put(callbackId, receiver); } else { LocalBroadcastManager.getInstance(getDoricContext().getContext()) diff --git a/doric-js/index.d.ts b/doric-js/index.d.ts index f336bc63..a4a1164a 100644 --- a/doric-js/index.d.ts +++ b/doric-js/index.d.ts @@ -926,12 +926,14 @@ declare module 'doric/lib/src/native/notification' { name: string; data?: object; androidSystem?: boolean; + permission?: string; }) => Promise; subscribe: (args: { biz?: string | undefined; name: string; callback: (data?: any) => void; androidSystem?: boolean | undefined; + permission?: string | undefined; }) => Promise; unsubscribe: (subscribeId: string) => Promise; }; diff --git a/doric-js/lib/src/native/notification.d.ts b/doric-js/lib/src/native/notification.d.ts index 98a2f410..62a6ee1c 100644 --- a/doric-js/lib/src/native/notification.d.ts +++ b/doric-js/lib/src/native/notification.d.ts @@ -5,12 +5,14 @@ export declare function notification(context: BridgeContext): { name: string; data?: object; androidSystem?: boolean; + permission?: string; }) => Promise; subscribe: (args: { biz?: string | undefined; name: string; callback: (data?: any) => void; androidSystem?: boolean | undefined; + permission?: string | undefined; }) => Promise; unsubscribe: (subscribeId: string) => Promise; }; diff --git a/doric-js/src/native/notification.ts b/doric-js/src/native/notification.ts index f908cece..f5004ddf 100644 --- a/doric-js/src/native/notification.ts +++ b/doric-js/src/native/notification.ts @@ -16,13 +16,13 @@ import { BridgeContext } from "../runtime/global" export function notification(context: BridgeContext) { return { - publish: (args: { biz?: string, name: string, data?: object, androidSystem?: boolean }) => { + publish: (args: { biz?: string, name: string, data?: object, androidSystem?: boolean, permission?: string }) => { if (args.data !== undefined) { (args as any).data = JSON.stringify(args.data) } return context.callNative('notification', 'publish', args) }, - subscribe: (args: { biz?: string, name: string, callback: (data?: any) => void, androidSystem?: boolean }) => { + subscribe: (args: { biz?: string, name: string, callback: (data?: any) => void, androidSystem?: boolean, permission?: string }) => { (args as any).callback = context.function2Id(args.callback) return context.callNative('notification', 'subscribe', args) as Promise },