Android Notification add permission
This commit is contained in:
parent
a355361f33
commit
ac2a4121c2
@ -46,8 +46,8 @@ import pub.doric.extension.bridge.DoricPromise;
|
||||
@DoricPlugin(name = "notification")
|
||||
public class NotificationPlugin extends DoricJavaPlugin {
|
||||
|
||||
private HashMap<String, BroadcastReceiver> systemReceivers = new HashMap<>();
|
||||
private HashMap<String, BroadcastReceiver> localReceivers = new HashMap<>();
|
||||
private final HashMap<String, BroadcastReceiver> systemReceivers = new HashMap<>();
|
||||
private final HashMap<String, BroadcastReceiver> 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())
|
||||
|
2
doric-js/index.d.ts
vendored
2
doric-js/index.d.ts
vendored
@ -926,12 +926,14 @@ declare module 'doric/lib/src/native/notification' {
|
||||
name: string;
|
||||
data?: object;
|
||||
androidSystem?: boolean;
|
||||
permission?: string;
|
||||
}) => Promise<any>;
|
||||
subscribe: (args: {
|
||||
biz?: string | undefined;
|
||||
name: string;
|
||||
callback: (data?: any) => void;
|
||||
androidSystem?: boolean | undefined;
|
||||
permission?: string | undefined;
|
||||
}) => Promise<string>;
|
||||
unsubscribe: (subscribeId: string) => Promise<any>;
|
||||
};
|
||||
|
2
doric-js/lib/src/native/notification.d.ts
vendored
2
doric-js/lib/src/native/notification.d.ts
vendored
@ -5,12 +5,14 @@ export declare function notification(context: BridgeContext): {
|
||||
name: string;
|
||||
data?: object;
|
||||
androidSystem?: boolean;
|
||||
permission?: string;
|
||||
}) => Promise<any>;
|
||||
subscribe: (args: {
|
||||
biz?: string | undefined;
|
||||
name: string;
|
||||
callback: (data?: any) => void;
|
||||
androidSystem?: boolean | undefined;
|
||||
permission?: string | undefined;
|
||||
}) => Promise<string>;
|
||||
unsubscribe: (subscribeId: string) => Promise<any>;
|
||||
};
|
||||
|
@ -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<string>
|
||||
},
|
||||
|
Reference in New Issue
Block a user