Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 94f93d2

Browse files
authoredNov 9, 2022
fix(messaging): Activity registerForActivityResult is not a function (#155)
1 parent e1b09f5 commit 94f93d2

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed
 

‎packages/firebase-messaging-core/index.android.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,23 @@ let _permissionQueue: { resolve: Function; reject: Function }[] = [];
5858

5959
function register(args: any) {
6060
if (!lastActivity) {
61-
lastActivity = new WeakRef(args.activity);
62-
requestPermissionLauncher = args.activity.registerForActivityResult(
63-
new androidx.activity.result.contract.ActivityResultContracts.RequestPermission(),
64-
new androidx.activity.result.ActivityResultCallback({
65-
onActivityResult(isGranted: boolean) {
66-
_permissionQueue.forEach((callback) => {
67-
callback.resolve(isGranted ? 0 : 1);
68-
});
69-
_permissionQueue.splice(0);
70-
},
71-
})
72-
);
61+
// Some activities do not implement activity result API
62+
if (args.activity.registerForActivityResult) {
63+
lastActivity = new WeakRef(args.activity);
64+
requestPermissionLauncher = args.activity.registerForActivityResult(
65+
new androidx.activity.result.contract.ActivityResultContracts.RequestPermission(),
66+
new androidx.activity.result.ActivityResultCallback({
67+
onActivityResult(isGranted: boolean) {
68+
_permissionQueue.forEach((callback) => {
69+
callback.resolve(isGranted ? 0 : 1);
70+
});
71+
_permissionQueue.splice(0);
72+
},
73+
})
74+
);
75+
} else {
76+
Application.android.once('activityCreated', register);
77+
}
7378
}
7479
}
7580

0 commit comments

Comments
 (0)
Please sign in to comment.