Skip to content

Commit bd040a0

Browse files
author
Ahmed Elsayed
committed
Add android request notification permission handling
1 parent fce59a1 commit bd040a0

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

packages/jsActions/mobile-resources-native/src/notifications/RequestNotificationPermission.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// - the code between BEGIN USER CODE and END USER CODE
66
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
77
// Other code you write will be lost the next time you deploy the project.
8-
import { NativeModules, Platform } from "react-native";
8+
import { NativeModules, PermissionsAndroid, Platform } from "react-native";
99
import messaging from "@react-native-firebase/messaging";
1010

1111
// BEGIN EXTRA CODE
@@ -24,6 +24,16 @@ export async function RequestNotificationPermission(): Promise<boolean> {
2424
return Promise.reject(new Error("Firebase module is not available in your app"));
2525
}
2626

27+
if (Platform.OS === "android") {
28+
return PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS)
29+
.then(() => {
30+
return true;
31+
})
32+
.catch(() => {
33+
return false;
34+
});
35+
}
36+
2737
return messaging()
2838
.requestPermission()
2939
.then(() =>

0 commit comments

Comments
 (0)