zoontek / react-native-permissions

An unified permissions API for React Native on iOS, Android and Windows.
MIT License
4.11k stars 837 forks source link

Notification Permission In Android #858

Closed wolfxpertlab closed 8 months ago

wolfxpertlab commented 8 months ago

Before submitting a new issue

Bug summary

When I ask notification permission in android that show unavailable I want to get ask notification for all android devices and iOS devices

Library version

4.1.4

Environment info

System:
  OS: macOS 14.0
  CPU: (8) arm64 Apple M1
  Memory: 114.78 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.8.0
    path: /opt/homebrew/bin/node
  Yarn: Not Found
  npm:
    version: 10.1.0
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2023.10.09.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /Users/Ahmed/.rvm/gems/ruby-2.7.5/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.0
      - iOS 17.0
      - macOS 14.0
      - tvOS 17.0
      - watchOS 10.0
  Android SDK: Not Found
IDEs:
  Android Studio: 2021.3 AI-213.7172.25.2113.9123335
  Xcode:
    version: 15.0/15A240d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.10
    path: /usr/bin/javac
  Ruby:
    version: 2.7.5
    path: /Users/Ahmed/.rvm/rubies/ruby-2.7.5/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.2
    wanted: 0.73.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Steps to reproduce

1) I am check notification function 2) requestNotificationPermission function trigger

when I check notification permission that show unavailable

I want to ask permission for all android devices

Reproducible sample code

const checkNotification = async () => {

        const status = await requestNotificationPermission()

        console.log('cehckkkk checkj notification statusss ===========================', status);

    }

 // Request Notification Permission
    const requestNotificationPermission = async () => {
        try {

            if (Platform.OS === 'android') {
                // Request notification permission for Android
                const permissionStatus = await request(PERMISSIONS.ANDROID.POST_NOTIFICATIONS);

                console.log('cehckk  permisssionsrtatuss __________', permissionStatus);

                if (permissionStatus === 'granted') {
                    return permissionStatus === RESULTS.GRANTED;
                }
                else {
                    return false
                }
            }
            else {
                const status = await requestNotifications(['alert', 'badge', 'sound'])

                if (status.settings.alert && status.settings.badge && status.settings.sound) {
                    console.log('Notification permissions granted');
                    return true;
                } else {
                    console.log('Notification permissions denied');
                    return false;
                }

            }
        } catch (error) {
            console.error('Error requesting notification permission:', error);
            return false;
        }
    };
zoontek commented 8 months ago

Use requestNotifications.

wolfxpertlab commented 8 months ago

any add permission in andoridmanifest file android?

and also describe how can I use request notification for both android and iOS

zoontek commented 8 months ago

POST_NOTIFICATIONS in your Manifest, requestNotifications for both android and iOS.